khalidabuhakmeh / ConsoleTables

Print out a nicely formatted table in a console application C#
MIT License
948 stars 158 forks source link

Display issue with non-English languages #48

Closed Yuan-Quan closed 1 year ago

Yuan-Quan commented 4 years ago

If any Chinese, Japanese, emoji character appeared in the table, it won't display properly.

Steps to reproduce the problem:

add some non-English letters in the table

var table = new ConsoleTable("1", "2", "3");
table.AddRow("张三", "test", "李四");
table.AddRow("チルノ", "日本語", "😑😑😭");
table.Write();

Excepted behavior:

 -----------------------------
 | 1      | 2      | 3       |
 -----------------------------
 | 张三   | test   | 李四     |
 -----------------------------
 | チルノ | 日本語  | 😑😭😭 |
 -----------------------------

Actual behavior:

 -----------------------
 | 1   | 2    | 3      |
 -----------------------
 | 张三  | test | 李四     |
 -----------------------
 | チルノ | 日本語  | ���😑😭😭 |
 -----------------------

image

Yuan-Quan commented 4 years ago

I wrote 😑😑😭 in code, but the output is ���😑😭😭. This is not an issue of ConsoleTables. WriteLine("😑😑😭"); output this, too.

khalidabuhakmeh commented 4 years ago

This is a known issue with emoji rendering. I've run into it myself. Some emojis have an additional space, while others don't. It's almost impossible to determine how much space they will take up. :(

SlimeNull commented 3 years ago

好耶! 原来已经有人在我之前提出这个问题了. 不过我给出解决方案哦~ (暴力获取每个字符的宽度, 然后保存到字节数组, 作为项目的嵌入资源. 每一个字符仅占1bit. 或者用其他的判断). 完整文章: CSDN: 计算字符串在控制台中的宽度

WOW! I just noticed that you have submit the same issues as mine. but I have a method which can solve this issues. (enumerate every char, get it's width, then save the result to a byte array, write to a file, and specify this file as project resource. one char will only take one bit in this file. the other solution which not require a resource file, is to use a lot of "if".) an article about this solution: CSDN: To calculate the width of string in console

Yuan-Quan commented 3 years ago

Now it's simple. Make a separate package and add reference to it. Or simply copy and paste them here.

khalidabuhakmeh commented 1 year ago

I believe this issue has been solved with the latest release of 2.5.1. Cheers.