Git Product home page Git Product logo

consoletableext's Issues

[Question] Сolumns visibility | Select the row that I want to display

Can you help me display only those rows that I want to

For example: there is the following code:

public class TestClass1
{
    public string A { get; set; }
    public string B { get; set; }
    public string C { get; set; }
}
  List<TestClass1> testClass = new List<TestClass1>();
  testClass.Add(new TestClass1 { A = "a0", B = "b0", C = "c0" });
  testClass.Add(new TestClass1 { A = "a1", B = "b1", C = "c1" });
  ConsoleTableBuilder
  .From(testClass)
  .WithColumn("A", "B")
  .ExportAndWriteLine();

I would like to display only the "A" and "B" columns

How can I do this ?

So the question is: how to display specific columns ?

Is this supposed to work with List<T> ?

I've tried a few permutations, but I cant get it to accept a list of the same type objects.

like

public class MyClass 
{
  public string StringValue1 {get;set;}
  public string StringValue2 {get;set;}
  public string StringValue3 {get;set;}
}

var t1 = new MyClass {StringValue1 = "1", StringValue2 = "2", StringValue3 = "3"};
var t2 = new MyClass {StringValue1 = "4", StringValue2 = "5", StringValue3 = "6"};

var tList = new List<MyClass>{t1, t2}

ConsoleTableBuilder.From(tList) //<-- wont compile.

List<T> Not Renderining

The following code returns nothing. Seems similar to the Sample code you have but not sure yet what the problem is with this code.

public class Dog
{
	public string Name = "Fido";
	public string Breed = "Doberman";
	public int Age = 4;
}
List<Dog> dogList = new List<Dog>();
	dogList.Add(new Dog()
		{ Name = "spike", Breed = "Poodle", Age = 3 });

	dogList.Add(new Dog()
		{ Name = "george", Breed = "Spaniel", Age = 8 });

	dogList.Add(new Dog()
		{ Name = "sammy", Breed = "Weimaraner", Age = 13 });

ConsoleTableBuilder
	.From(dogList)
	.WithFormat(ConsoleTableBuilderFormat.Minimal).ExportAndWriteLine();

Minimal format but with spaces between the columns

I like the minimal format, except I find the solid bar for the headers to be difficult to parse the columns.

DefaultString DefaultInt32 HiddenString 
----------------------------------------
Row 1                    1 Hidden 1     
Row 2                   10 Hidden 2     
Row 3                  100 Hidden 3     

So, I thought I would try to make a version that had spaces in it:

.WithHeaderCharMapDefinition(
    new Dictionary<HeaderCharMapPositions, char>
    {
        { HeaderCharMapPositions.BottomCenter, ' ' },
        { HeaderCharMapPositions.Divider, ' ' },
        { HeaderCharMapPositions.BorderBottom, '-' },
    })

But what I found was if both BottomCenter and Divider are spaces (' '), then the space is collapsed between the two of them which squishes the columns together. I ended up needing to put something between the two to make it work:

.WithCharMapDefinition(
    new Dictionary<CharMapPositions, char>
    {
        { CharMapPositions.DividerY, ' ' },
    })
.WithHeaderCharMapDefinition(
    new Dictionary<HeaderCharMapPositions, char>
    {
        { HeaderCharMapPositions.BottomCenter, '+' },
        { HeaderCharMapPositions.Divider, ' ' },
        { HeaderCharMapPositions.BorderBottom, '-' },
    });

This produces a table like this:

 DefaultString   DefaultInt32   HiddenString 
---------------+--------------+--------------
 Row 1                      1   Hidden 1     
 Row 2                     10   Hidden 2     
 Row 3                    100   Hidden 3     

Adding that adds extra columns to the right and left of the headers, which isn't ideal but workable. But, being able to have spaces between the columns would be greatly appreciated. Is there a way of doing that?

Colour Support

Can we implement Colour Support in the tables?

Making use of something like:

Console.ForegroundColor = ConsoleColor.Green

Is there a way to center the tables inside the console?

Maybe I missed it inside your code, but is there a way to center the tables inside the console?

Just have a use case for it at the moment...

THX for any comment on this.
Great job with the package BTW, luv it!

Greetings from Belgium,
Guy

Title & Footer Bars

I like the MarkDown format but can you add a title bar and a footer option? You can do it as an extension method to your Builder pattern .WithTitle(...), .WithFooter(...).

ConsoleTableBuilder.From(GenerateResults(results))
   .WithFormat(ConsoleTableBuilderFormat.MarkDown)
   .ExportAndWriteLine();

Example

========== CONTACTS ==========
| Id | First Name | Surname  |
|----------------------------|
| 1  | Isaac      | Asimov   |
| 2  | Robert     | Heinlein |
| 3  | Frank      | Herbert  |
| 4  | Aldous     | Huxley   |
==============================

Automatic format of number types

The ConsoleTables has a nice feature, where .Configure(o => o.NumberAlignment = Alignment.Right) sets up automatic right alignment of numbers in the table.

Would you consider adding similar mechanism to your project?

Multiple lines in cell

Sorry, I can't figure out, do ConsoleTableExt have any support of multiple lines in cell? Just now as I see, when I try to use the "first" + Environment.NewLine + "second" text in cell, the line wraps not inside the cell, but on the new line of whole formatted table output. Is it possible to format table like in https://github.com/seleznevae/libfort? The libfort unfortunately is in C (

Maybe there is a way to do it in ConsoleTableExt?

This code:

public static string GetAsciiTable()
{
    var tableData = new List<List<object>>
    {
        new List<object>{ "Sakura Yamamoto", "Support Engineer", "London", 46},
        new List<object>{ "Serge Baldwin", "Data Coordinator", "San Francisco", 28, "something else" },
        new List<object>{ "Shad Decker", "Regional Director", "Edinburgh"},
    };

    return ConsoleTableBuilder.From(tableData)
        .WithColumn("AAA BBB", "CCC" + Environment.NewLine + "DDD", "EEE FFF")
       .Export().ToString();
}

Results in this output:

ss

And the C libfort library multiline output for example:

color_table

List crashed when using with string type

There was a bug when int is replaced by string

//Worked
ConsoleTableBuilder.From(new List<int> { 1, 2, 3, 4, 5, 6 })
.WithFormat(ConsoleTableBuilderFormat.Alternative).WithColumn("I'm a custom name").ExportAndWrite();

//Crashed
ConsoleTableBuilder.From(new List<string> { "1", "2", "3", "4", "5", "6" }).WithFormat(ConsoleTableBuilderFormat.Alternative).WithColumn("I'm a custom name").ExportAndWrite();

Unhandled exception. System.Reflection.TargetParameterCountException: Parameter count mismatch.
at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object[] index)
at ConsoleTableExt.ConsoleTableBuilder.From[T](List`1 list)

[debug]#30 not fixed

If multiple rows of data contain UTF8 characters, the output is still misformatted.
I think the final solution should be to override the 'string.format' method to calculate the final number of spaces that should be added in real time.

var results = builder.FormattedRows.Select(row => string.Format(tableRowContentFormatNoUtf8Charas, row.ToArray())).ToList();

change to 

 string.FormatEx(tableRowContentFormatNoUtf8Charas, row.ToArray()))

image

Suggestion: Ignore special control characters / virtual terminal sequences in row length calculation

Description

Special control characters such as ANSI escape codes are included in calculation of row length (which is determined by string length). This results in table rows appearing larger than they should be.

Example:

This is used for the row (outlined); the ANSI escape sequence is red
yWxj5WcF8h_2022-05-06_(03h47m50s)

This results in the following output:

c1hBYeWyNq_2022-05-06_(03h49m30s)
(The affected row is red)

This is because the length of the ANSI escape characters in the example is 7, which results in 7 additional characters in the row cell:

VsDebugConsole_2LEKSjhfj0

Possible Solution

A possible solution would be using regex to filter such characters and escape sequences from the row content string, and using the resulting string length to determine the row length.

See Console virtual terminal sequences

winfrom richTextBox1 Format

winfrom richTextBox1:

| Sakura Yamamoto | Support Engineer | London | 46 | |

| Serge Baldwin | Data Coordinator | San Francisco | 28 | something else |

| Shad Decker | Regional Director | Edinburgh | | |

Can you solve it?

Could not install ConsoleTableExt from the NuGet tool

Hi, thanks for your job.

On VSC, I tried to install this extension from the NuGet tool console

Install-Package ConsoleTableExt

And I got this:

Error Package restore failed. Rolling back package changes for 'ConsoleTableExt'.
Severity Code Description Project File Line Suppression State
Error NU1108 Cycle detected.
ConsoleTableExt -> ConsoleTableExt (>= 3.2.0). ConsoleTableExt D:.NET FOLDER\C# ACADEMY\Projects\ConsoleTableExt\ConsoleTableExt.csproj 1

Thanks :D!

Box-drawing characters

It could print the table using box-drawing characters.

┌───────┬─────┐
│ Name  │ Age │  
├───────┼─────┤
│ Alice │  10 │
│ Bob   │  20 │    
│ Clare │  30 │    
└───────┴─────┘

Centered Header Column with Left Aligned Column Rows

Thx for your amazing library 😍

It is possible to align the header in center but align the content rows to the left?

Actual behavior:
img

Ideal behavior:
img

P.S. The images are demo images created fast in VSCode 🤣

regards REJack

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.