ConsoleTableExt icon indicating copy to clipboard operation
ConsoleTableExt copied to clipboard

Automatic format of number types

Open michalfita opened this issue 3 years ago • 3 comments

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?

michalfita avatar Jun 08 '21 15:06 michalfita

hi @michalfita , ConsoleTableExt treat all values as string, so it does not discriminate "number" or "string"

but ConsoleTableExt also has a feature which give us define which columns we want to align using WithTextAlignment extension, for example:

.WithTextAlignment(new Dictionary<int, TextAligntment>{
    { 1, TextAligntment.Right },
    { 3, TextAligntment.Center}
})

In above example, 1 and 3 are column indexs

Same, you can align header with extension WithHeaderTextAlignment

.WithHeaderTextAlignment(new Dictionary<int, TextAligntment> {
   {1, TextAligntment.Center }
})

Check more in example project here https://github.com/minhhungit/ConsoleTableExt/tree/master/Src/ConsoleTableApp

minhhungit avatar Jun 09 '21 00:06 minhhungit

I'm aware of this feature, however this require really going extra mile in comparison to ConsoleTables if you want to stick with simple From() call but want numbers right aligned. As you keep List<List<object>> some extra meta-magic would be possible figured if the original data were actually the number.

michalfita avatar Jun 09 '21 10:06 michalfita

Support the feature is not too hard, but we will need to check every values in the table to verify if value is a "number" or not, this will cause a performance problem, it can be slower for large table. Anyway, I will consider to support it, I admit that defining text align by column index is quite bored

minhhungit avatar Jun 09 '21 11:06 minhhungit