Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Table Alignment Issue with Chinese Characters #499

Open
MikuSugar opened this issue Feb 10, 2025 · 2 comments
Open

Table Alignment Issue with Chinese Characters #499

MikuSugar opened this issue Feb 10, 2025 · 2 comments
Labels
question Further information is requested

Comments

@MikuSugar
Copy link

I encountered an issue where the table borders are misaligned when Chinese characters are included in the content. The presence of Chinese characters seems to disrupt the table’s layout, causing the borders to appear uneven, which affects the overall table formatting and presentation.
code:

fn main() {
    use tabled::{Table, settings::Width};
  
    let data = vec![
        ("Some\ndata", "here", "and here"),
        ("Some\ndata on a next", "line", "right here"),
    ];

    let table = Table::new(data)
        .with(Width::list([20, 10, 12]))
        .to_string();
    println!("{}", table);

    //Chinese and English
    let data = vec![
        ("一些\n数据", "这里", "和这里"),
        ("Some\ndata on a next", "line", "right here"),
    ];

    let table = Table::new(data)
        .with(Width::list([20, 10, 12]))
        .to_string();
    println!("{}", table);

    // All Chinese
    let data = vec![
        ("一些\n数据", "这里", "和这里"),
        ("一些\n数据在下一", "行", "就在那里"),
    ];

    let table = Table::new(data)
        .with(Width::list([20, 10, 12]))
        .to_string();
    println!("{}", table);
}

out:

Image
@zhiburt
Copy link
Owner

zhiburt commented Feb 10, 2025

Hi @MikuSugar

So you're right sometimes some characters play tricks with the layout....
But in most cases it's a terminal differences.
If you run it in a different terminal it may work or may not 😅

See for me it works.

Image


This is actually an issue with how terminals treat UTF-8.
I do still think we probably need to have a way to address it....

For example having a different strategies for some terminals.
Likely most of them are using same approaches.

But it's something I was not thinking a lot about....
But we likely ought to.

We just need to do a bit of research, maybe you want to 😄 ?

@zhiburt zhiburt added the question Further information is requested label Feb 10, 2025
@MikuSugar
Copy link
Author

Hi   嗨@MikuSugar

So you're right sometimes some characters play tricks with the layout....所以,你有时候是对的,有些字符会对布局玩点小花招…… But in most cases it's a terminal differences.但大多数情况下,这是终端差异。 If you run it in a different terminal it may work or may not 😅如果您在不同的终端中运行它,它可能工作也可能不工作 😅

See for me it works.为我看看它是否工作。

Image

This is actually an issue with how terminals treat UTF-8.这是一个终端处理 UTF-8 的问题。 I do still think we probably need to have a way to address it....我仍然认为我们可能需要有一种方法来解决这个问题……

For example having a different strategies for some terminals.例如,为某些终端制定不同的策略。 Likely most of them are using same approaches.很可能他们大多数都在使用相同的方法。

But it's something I was not thinking a lot about....但是这并不是我思考很多的事情.... But we likely ought to.但我们可能应该。

We just need to do a bit of research, maybe you want to 😄 ?我们只需要做一点研究,也许你想😄?

Thank you for your reply 😊. My previous output was from the run output of RustRover. I changed the output in the run configuration to simulate the terminal, and it worked fine. I tested several common terminals, and they all displayed correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants