douglasg14b / BetterConsoleTables

Faster, colorable, more configurable, and more robust console colors & tables for C# console applications
GNU Lesser General Public License v3.0
92 stars 16 forks source link

Column align to right #9

Closed franklupo closed 5 years ago

franklupo commented 5 years ago

Hi, wonderful job. Is it possible to specify in ToString if the column is aligned to the right?

Best regards

douglasg14b commented 5 years ago

That can probably be done!

I'm super busy for the next few days, if I forget about this please feel free to ping me again.

davidnmbond commented 5 years ago

We'd also like to right align numbers. Please do add this feature!

douglasg14b commented 5 years ago

Oh hey, I completely forgot about this!

For now alignment will be on a per-column basis, and will pad based on the max column width. Meaning if the column width is the same as number of characters in that row, they won't appear right-aligned. I might as well throw in center-align while I'm at it as well.

Thoughts?

davidnmbond commented 5 years ago

Yes, that sounds perfect. The right align requirement is purely for number presentation, so a column that entirely consisted of 4-digit numbers would be tightly packed, and that's as it should be. However, throw a single 5-digit number into the same column and the alignment would still make sense.

As for center alignment, you're right(-aligned) - might as well throw it in!

douglasg14b commented 5 years ago

@davidnmbond @franklupo I have added support for aligning both the headers and the rows to Left, Right, or Center. This is available under the 1.1.0 nuget package that still indexing.

Please refer to the Readme for code examples.

franklupo commented 5 years ago

Hi, the table.AddColumn(...) not working with align but in constructor yes.

Best regards

douglasg14b commented 5 years ago

@franklupo Can you paste a brief repro?

This is working for me:

    Table table = new Table("Left");
    table.AddColumn("Left Header", Alignment.Right)
        .AddColumn("Right Header", Alignment.Center, Alignment.Right)
        .AddRow("1", "2", "3")
        .AddRow("Short", "item", "Here")
        .AddRow("Longer items go here", "Right Contents", "Centered Contents")
        .Config = TableConfiguration.MySqlSimple();

    Console.Write(table.ToString());