minhhungit / ConsoleTableExt

A fluent library to print out a nicely formatted table in a console application C#
MIT License
323 stars 36 forks source link

[debug]#30 not fixed #32

Closed haptear closed 2 years ago

haptear commented 2 years ago

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

haptear commented 2 years ago

test code


         var tableData =new List<object>() { 
                new { Id="其123中x213", Name="tab其它语言test", Host="127.0.0.1", Port=80, status ="success" } ,
                new { Id="中中123午", Name="中123午tes好demo", Host="127.0.0.1", Port=80, status ="success" } ,
            };

            ConsoleTableExt.ConsoleTableBuilder
                .From<dynamic>(tableData)
                //.WithTitle("ALL CENTERS", ConsoleColor.Yellow, ConsoleColor.DarkGray)
                .WithFormat(ConsoleTableBuilderFormat.Alternative)
                .ExportAndWriteLine(TableAligntment.Left);

            Console.ReadLine();
haptear commented 2 years ago

@minhhungit please review RP

minhhungit commented 2 years ago

thanks @haptear for the PR, merged and released in version 3.1.9