Closed haptear closed 3 years ago
@haptear can you give me your test code please
@minhhungit the test code
using ConsoleTableExt;
using System;
using System.Collections.Generic;
namespace ConsoleApp6
{
class Program
{
static void Main(string[] args)
{
var tableData =new List<object>() { new { Id="xxx", Name="tab其它语言test", 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();
}
}
}
this is first look, still checking more
After adding Console.OutputEncoding = Encoding.Unicode;
I see the problem
it looks it has extra space
Thank you for your quick reply
I have no idea, my lack of knowledge about this case
It counts length of text correctly, the text "tab其它语言test" has length 11, but after console print out, console need more space
The actual length of the string "tab其它语言test" is 15,UTF-8 characters should be *2
@minhhungit You can get the actual length with "GetStringLen" GetStringLen("tab其它语言test")==15
public static int GetStringLen(string str)
{
int i = 0;//count
foreach (char newChar in str)
{
if ((int)newChar > 127)
{
//utf-8 characters
i += 2;
}
else
{
i++;
}
}
return i;
}
@haptear thank you about the suggestion but that is not only length issue but also windows console problem
Problem here for a text for example "tab其它语言test", we can get the length is 15, but windows app don't print the length exactly
I tried but no lucky, I am quite sure this is problem of windows console
@minhhungit
hi can you merge request?
@haptear thanks, I will review the PR soon
released in 3.1.8
If there are UTF-8 characters in the data, it will cause the output to be misformatted