RyanBluth/term-table-rs

How to add colour

RRethy opened this issue · 4 comments

I'm having issues adding color to cells and am wondering what you would recommend.

    use colored::*;
    let mut table = term_table::Table::new();
    table.style = term_table::TableStyle::thin();
    table.add_row(Row::new(vec![
        TableCell::new("one".red().bold()),
        TableCell::new("two".red().bold()),
    ]));
    table.add_row(Row::new(vec![
        TableCell::new("three".red()),
        TableCell::new("four".red()),
    ]));
    println!("{}", table.render());

Prints:

image

I'm assuming it has to do with the len of the string is not the display width because of the escape codes added for the coloured output. I don't see anything in term-table-rs that can handle colour, so I'm wondering how you would recommend adding colour to cells (or if it can reliably be done with term-table-rs)?

Hmm, I've done this in the past. Can you try with version version 0.1.6?

With 0.1.6:

    Updating crates.io index
error: no matching package named `wcwidth` found
location searched: registry `https://github.com/rust-lang/crates.io-index`
required by package `term-table v0.1.6`

wcwidth seemed to have been yanked from crates.io so I can't use 0.1.6 :/

I've tested it out with the most recent version and it's not working for me either. My intention is to support this so that people can chose whichever method they want for using colour in their tables. I won't be able to debug this for a few days, but will try to get to it as soon as I can. If you're willing to dig into things and open a PR that would be appreciated, but if not then no worries.

Sounds good, I'll try take a look tmrw and let you know any progress.