zhiburt / tabled

An easy to use library for pretty print tables of Rust structs and enums.
MIT License
2.01k stars 84 forks source link

Unicode width not being accounted for #349

Open nithinmuthukumar opened 1 year ago

nithinmuthukumar commented 1 year ago

Characters with variable width break the table borders. Example: Screen Shot 2023-06-28 at 12 18 23 PM

nithinmuthukumar commented 1 year ago

I'm willing to help, if you could point me in the right direction

zhiburt commented 1 year ago

Hi @nithinmuthukumar

Could you provide your example?

I just wonder if you used color feature? (it's often nessary in such context)

daywalker90 commented 5 months ago

I'm encountering the same problem. What does the color feature have to do with this? Is there something i can do, besides filtering unicode characters?

daywalker90 commented 5 months ago

It's not all characters but these 2 i found causing issues: ☀️🏛️ EDIT: I can see that tabled only prints the left side of these characters

zhiburt commented 5 months ago

Hi @daywalker90

Could you provide a code example?

What does the color feature have to do with this?

It was renamed to ansi in recent releases. But it changes the calculations a little bit. But to be honest in this specific case, it mustn't be different.

It's not all characters but these 2 i found causing issues: ☀️🏛️

Generally speaking it all depends on a terminal. If you render the same table, which includes some obscure utf8, in different terminals it may (likely) be different.

zhiburt commented 5 months ago

Generally speaking it all depends on a terminal. If you render the same table, which includes some obscure utf8, in different terminals it may (likely) be different.

Now I am thinking maybe it's worth to add a configuration for it. I mean we can't fetch information from a terminal, But we could be given it.

Either a complete UTF-8 map or some specifics like this particular char will take not 1 but 3 terminal columns. Yee It could could be usefullllllllllllllllllll rarely, but would slow down rendering a fair bit. So maybe would need to be hidden by a feature.

Just thoughts here.

daywalker90 commented 5 months ago

You are right, it's highly terminal related. With putty i have these 2 above misbehaving and with powershell it's a complete mess. (i know, windows... yikes)

pub async fn qwert(
    plugin: Plugin<()>,
    _args: serde_json::Value,
) -> Result<serde_json::Value, Error> {
    let row1 = TableTest {
        name: "test1".to_string(),
    };
    let row2 = TableTest {
        name: "test☀️".to_string(),
    };
    let mut rows = Vec::new();
    rows.push(row1);
    rows.push(row2);
    let table = Table::new(rows);
    Ok(json!({ "format-hint":"simple",
        "result": table.to_string() }))
}

image

zhiburt commented 5 months ago

See xterm

image