diff --git a/.changeset/tabled-ansi-width.md b/.changeset/tabled-ansi-width.md new file mode 100644 index 00000000..d9b7160a --- /dev/null +++ b/.changeset/tabled-ansi-width.md @@ -0,0 +1,5 @@ +--- +'@smooai/smooth': patch +--- + +th-6e77b7: `th admin` tables no longer over-widen columns containing coloured status cells — tabled's `ansi` feature makes its width calc strip escape sequences. diff --git a/Cargo.lock b/Cargo.lock index 9b61e96d..14428235 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -26,6 +26,25 @@ dependencies = [ "libc", ] +[[package]] +name = "ansi-str" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "060de1453b69f46304b28274f382132f4e72c55637cf362920926a70d090890d" +dependencies = [ + "ansitok", +] + +[[package]] +name = "ansitok" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0a8acea8c2f1c60f0a92a8cd26bf96ca97db56f10bbcab238bbe0cceba659ee" +dependencies = [ + "nom", + "vte", +] + [[package]] name = "anstream" version = "1.0.0" @@ -82,6 +101,12 @@ version = "1.0.102" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c" +[[package]] +name = "arrayvec" +version = "0.7.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f02882884d3e1bc524fb12c79f107f6ad0e1cfd498c536ffb494301740995dfe" + [[package]] name = "ascii" version = "1.1.0" @@ -2280,6 +2305,8 @@ version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b915f831b85d984193fdc3d3611505871dc139b2534530fa01c1a6a6707b6723" dependencies = [ + "ansi-str", + "ansitok", "bytecount", "fnv", "unicode-width", @@ -4153,6 +4180,8 @@ version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "121d8171ee5687a4978d1b244f7d99c43e7385a272185a2f1e1fa4dc0979d444" dependencies = [ + "ansi-str", + "ansitok", "papergrid", "tabled_derive", ] @@ -4922,6 +4951,16 @@ version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" +[[package]] +name = "vte" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "231fdcd7ef3037e8330d8e17e61011a2c244126acc0a982f4040ac3f9f0bc077" +dependencies = [ + "arrayvec", + "memchr", +] + [[package]] name = "vtparse" version = "0.6.2" diff --git a/crates/smooth-cli/Cargo.toml b/crates/smooth-cli/Cargo.toml index 09b6e190..60243b59 100644 --- a/crates/smooth-cli/Cargo.toml +++ b/crates/smooth-cli/Cargo.toml @@ -68,7 +68,7 @@ quick-xml = { version = "0.37", features = ["serialize"] } # `tabled` is what nushell uses — best-of-class in the Rust table- # rendering space. Builder API for dynamic JSON, rich modifier chain # for theming, 10+ built-in styles. -tabled = "0.18" +tabled = { version = "0.18", features = ["ansi"] } # `ansi`: width calc strips escapes — coloured status cells were over-widening columns (th-6e77b7) # Pearl th-fcb579: browser-based `th auth login`. # - `tiny_http`: minimal blocking HTTP listener for the OAuth diff --git a/crates/smooth-cli/src/admin/render.rs b/crates/smooth-cli/src/admin/render.rs index 327b5411..787fbdb8 100644 --- a/crates/smooth-cli/src/admin/render.rs +++ b/crates/smooth-cli/src/admin/render.rs @@ -366,6 +366,21 @@ mod tests { assert_eq!(opts.label, Some("users")); } + #[test] + fn ansi_escapes_do_not_widen_columns_th_6e77b7() { + // Explicit escapes (owo-colors may no-op off-TTY): the coloured + // cell must render the same table width as the plain one. + let table_width = |cell: &str| { + let mut b = Builder::default(); + b.push_record(["status"]); + b.push_record([cell]); + let mut t = b.build(); + apply_modern_style(&mut t); + t.to_string().lines().next().map_or(0, |l| l.chars().count()) + }; + assert_eq!(table_width("\u{1b}[32;1mactive\u{1b}[0m"), table_width("active")); + } + #[test] fn colour_status_known_values_get_colour_codes_other_passthrough() { // Coloured = contains an ANSI escape. The actual code depends