termimad
termimad copied to clipboard
Support for `Colored`/terminal escape codes
Thanks for the nifty package, it's very cool! I'd love to be able to use it with Colored, but using coloured text in a table breaks the layout:
use colored::Colorize;
use termimad::{MadSkin};
fn main() {
let header = "|:-|:-\n|**Example**|**Table**|\n|-|-";
let col1 = "Colourful text".bright_red();
let col2 = "breaks the table :(".bold();
let rest = format!("| {col1} | {col2} |");
let table = format!("{header}\n{rest}\n|-");
MadSkin::default().print_text(&table);
}
$ cargo run
┌───────────────────────┬───────────────────────────┐
│Example │Table │
├───────────────────────┼───────────────────────────┤
│Colourful text│breaks the table :(│
└───────────────────────┴───────────────────────────┘
My guess is it's counting escape codes when it shouldn't.
My guess is it's counting escape codes when it shouldn't.
Termimad relies on unicode_width, which has no concept of TTY escape codes (just like Markdown).
Now, assuming we would want a special mode in which text would be assumed to contain TTY escape codes (and also assuming all TTY spans are INSIDE markdown spans), then we could, when computing visible sizes, first remove TTY escape sequences.
If I find some time, maybe I'll try it.