diff --git a/crates/nu-command/tests/commands/table.rs b/crates/nu-command/tests/commands/table.rs index 2433d34bee..f7b1cd1a97 100644 --- a/crates/nu-command/tests/commands/table.rs +++ b/crates/nu-command/tests/commands/table.rs @@ -1,6 +1,6 @@ use nu_test_support::fs::Stub::FileWithContent; use nu_test_support::playground::Playground; -use nu_test_support::{nu, pipeline}; +use nu_test_support::{nu, nu_repl_code, pipeline}; #[test] fn table_0() { @@ -21,7 +21,213 @@ fn table_collapse_0() { let actual = nu!(r#"[[a b, c]; [1 2 3] [4 5 [1 2 3]]] | table --collapse"#); assert_eq!( actual.out, - "╭───┬───┬───╮│ a │ b │ c │ ─── ─── ─── │ 1 │ 2 │ 3 │ ─── ─── ─── │ 4 │ 5 │ 1 ││ │ ─── │ │ │ 2 ││ │ ─── │ │ │ 3 │╰───┴───┴───╯" + "╭───┬───┬───╮\ + │ a │ b │ c │\ + ├───┼───┼───┤\ + │ 1 │ 2 │ 3 │\ + ├───┼───┼───┤\ + │ 4 │ 5 │ 1 │\ + │ │ ├───┤\ + │ │ │ 2 │\ + │ │ ├───┤\ + │ │ │ 3 │\ + ╰───┴───┴───╯" + ); +} + +#[test] +fn table_collapse_basic() { + let actual = nu!(nu_repl_code(&[ + "let-env config = { table_mode: basic };", + "[[a b, c]; [1 2 3] [4 5 [1 2 3]]] | table --collapse" + ])); + assert_eq!( + actual.out, + "+---+---+---+\ + | a | b | c |\ + +---+---+---+\ + | 1 | 2 | 3 |\ + +---+---+---+\ + | 4 | 5 | 1 |\ + | | +---+\ + | | | 2 |\ + | | +---+\ + | | | 3 |\ + +---+---+---+" + ); +} + +#[test] +fn table_collapse_heavy() { + let actual = nu!(nu_repl_code(&[ + "let-env config = { table_mode: heavy };", + "[[a b, c]; [1 2 3] [4 5 [1 2 3]]] | table --collapse" + ])); + assert_eq!( + actual.out, + "┏━━━┳━━━┳━━━┓\ + ┃ a ┃ b ┃ c ┃\ + ┣━━━╋━━━╋━━━┫\ + ┃ 1 ┃ 2 ┃ 3 ┃\ + ┣━━━╋━━━╋━━━┫\ + ┃ 4 ┃ 5 ┃ 1 ┃\ + ┃ ┃ ┣━━━┫\ + ┃ ┃ ┃ 2 ┃\ + ┃ ┃ ┣━━━┫\ + ┃ ┃ ┃ 3 ┃\ + ┗━━━┻━━━┻━━━┛" + ); +} + +#[test] +fn table_collapse_compact() { + let actual = nu!(nu_repl_code(&[ + "let-env config = { table_mode: compact };", + "[[a b, c]; [1 2 3] [4 5 [1 2 3]]] | table --collapse" + ])); + assert_eq!( + actual.out, + "┌───┬───┬───┐\ + │ a │ b │ c │\ + ├───┼───┼───┤\ + │ 1 │ 2 │ 3 │\ + ├───┼───┼───┤\ + │ 4 │ 5 │ 1 │\ + │ │ ├───┤\ + │ │ │ 2 │\ + │ │ ├───┤\ + │ │ │ 3 │\ + └───┴───┴───┘" + ); +} + +#[test] +fn table_collapse_compact_double() { + let actual = nu!(nu_repl_code(&[ + "let-env config = { table_mode: compact_double };", + "[[a b, c]; [1 2 3] [4 5 [1 2 3]]] | table --collapse" + ])); + assert_eq!( + actual.out, + "╔═══╦═══╦═══╗\ + ║ a ║ b ║ c ║\ + ╠═══╬═══╬═══╣\ + ║ 1 ║ 2 ║ 3 ║\ + ╠═══╬═══╬═══╣\ + ║ 4 ║ 5 ║ 1 ║\ + ║ ║ ╠═══╣\ + ║ ║ ║ 2 ║\ + ║ ║ ╠═══╣\ + ║ ║ ║ 3 ║\ + ╚═══╩═══╩═══╝" + ); +} + +#[test] +fn table_collapse_compact_light() { + let actual = nu!(nu_repl_code(&[ + "let-env config = { table_mode: light };", + "[[a b, c]; [1 2 3] [4 5 [1 2 3]]] | table --collapse" + ])); + assert_eq!( + actual.out, + "┌───┬───┬───┐\ + │ a │ b │ c │\ + ├───┼───┼───┤\ + │ 1 │ 2 │ 3 │\ + ├───┼───┼───┤\ + │ 4 │ 5 │ 1 │\ + │ │ ├───┤\ + │ │ │ 2 │\ + │ │ ├───┤\ + │ │ │ 3 │\ + └───┴───┴───┘" + ); +} + +#[test] +fn table_collapse_none() { + let actual = nu!(nu_repl_code(&[ + "let-env config = { table_mode: none };", + "[[a b, c]; [1 2 3] [4 5 [1 2 3]]] | table --collapse" + ])); + assert_eq!( + actual.out, + concat!( + " a b c ", + " 1 2 3 ", + " 4 5 1 ", + " 2 ", + " 3 ", + ) + ); +} + +#[test] +fn table_collapse_compact_reinforced() { + let actual = nu!(nu_repl_code(&[ + "let-env config = { table_mode: reinforced };", + "[[a b, c]; [1 2 3] [4 5 [1 2 3]]] | table --collapse" + ])); + assert_eq!( + actual.out, + "┏───┬───┬───┓\ + │ a │ b │ c │\ + ├───┼───┼───┤\ + │ 1 │ 2 │ 3 │\ + ├───┼───┼───┤\ + │ 4 │ 5 │ 1 │\ + │ │ ├───┤\ + │ │ │ 2 │\ + │ │ ├───┤\ + │ │ │ 3 │\ + ┗───┴───┴───┛" + ); +} + +#[test] +fn table_collapse_compact_thin() { + let actual = nu!(nu_repl_code(&[ + "let-env config = { table_mode: thin };", + "[[a b, c]; [1 2 3] [4 5 [1 2 3]]] | table --collapse" + ])); + assert_eq!( + actual.out, + "┌───┬───┬───┐\ + │ a │ b │ c │\ + ├───┼───┼───┤\ + │ 1 │ 2 │ 3 │\ + ├───┼───┼───┤\ + │ 4 │ 5 │ 1 │\ + │ │ ├───┤\ + │ │ │ 2 │\ + │ │ ├───┤\ + │ │ │ 3 │\ + └───┴───┴───┘" + ); +} + +#[test] +fn table_collapse_hearts() { + let actual = nu!(nu_repl_code(&[ + "let-env config = { table_mode: with_love };", + "[[a b, c]; [1 2 3] [4 5 [1 2 3]]] | table --collapse" + ])); + assert_eq!( + actual.out, + concat!( + "❤❤❤❤❤❤❤❤❤❤❤❤❤", + "❤ a ❤ b ❤ c ❤", + "❤❤❤❤❤❤❤❤❤❤❤❤❤", + "❤ 1 ❤ 2 ❤ 3 ❤", + "❤❤❤❤❤❤❤❤❤❤❤❤❤", + "❤ 4 ❤ 5 ❤ 1 ❤", + "❤ ❤ ❤❤❤❤❤", + "❤ ❤ ❤ 2 ❤", + "❤ ❤ ❤❤❤❤❤", + "❤ ❤ ❤ 3 ❤", + "❤❤❤❤❤❤❤❤❤❤❤❤❤", + ) ); } diff --git a/crates/nu-table/src/nu_protocol_table.rs b/crates/nu-table/src/nu_protocol_table.rs index 8ec6b67d3c..9e3af76fdf 100644 --- a/crates/nu-table/src/nu_protocol_table.rs +++ b/crates/nu-table/src/nu_protocol_table.rs @@ -201,7 +201,7 @@ fn load_theme(table: &mut tabled::Table, style_computer: &StyleComputer, t where R: Records, { - let mut theme = theme.theme.clone(); + let mut theme = theme.into_full().unwrap_or_else(|| theme.theme.clone()); theme.set_horizontals(HashMap::default()); table.with(theme); diff --git a/crates/nu-table/src/table_theme.rs b/crates/nu-table/src/table_theme.rs index c027c32abd..a4719dfe10 100644 --- a/crates/nu-table/src/table_theme.rs +++ b/crates/nu-table/src/table_theme.rs @@ -7,12 +7,14 @@ use tabled::{ pub struct TableTheme { pub(crate) theme: RawStyle, has_inner: bool, + full_theme: Option, } impl TableTheme { pub fn basic() -> TableTheme { Self { theme: Style::ascii().into(), + full_theme: None, has_inner: true, } } @@ -20,6 +22,7 @@ impl TableTheme { pub fn thin() -> TableTheme { Self { theme: Style::modern().into(), + full_theme: None, has_inner: true, } } @@ -32,7 +35,7 @@ impl TableTheme { Line::new(Some('─'), Some('─'), None, None), )]) .into(), - + full_theme: Some(Style::modern().into()), has_inner: true, } } @@ -47,6 +50,7 @@ impl TableTheme { .left(None) .right(None)]) .into(), + full_theme: Some(Style::modern().into()), has_inner: true, } } @@ -62,6 +66,25 @@ impl TableTheme { Line::new(Some('❤'), Some('❤'), None, None), )]) .into(), + full_theme: Some( + Style::empty() + .top('❤') + .bottom('❤') + .vertical('❤') + .horizontal('❤') + .left('❤') + .right('❤') + .top_intersection('❤') + .top_left_corner('❤') + .top_right_corner('❤') + .bottom_intersection('❤') + .bottom_left_corner('❤') + .bottom_right_corner('❤') + .right_intersection('❤') + .left_intersection('❤') + .inner_intersection('❤') + .into(), + ), has_inner: true, } } @@ -76,6 +99,7 @@ impl TableTheme { .left(None) .right(None)]) .into(), + full_theme: Some(Style::extended().into()), has_inner: true, } } @@ -83,6 +107,14 @@ impl TableTheme { pub fn rounded() -> TableTheme { Self { theme: Style::rounded().into(), + full_theme: Some( + Style::modern() + .top_left_corner('╭') + .top_right_corner('╮') + .bottom_left_corner('╰') + .bottom_right_corner('╯') + .into(), + ), has_inner: true, } } @@ -96,6 +128,14 @@ impl TableTheme { .bottom_right_corner('┛') .off_horizontal() .into(), + full_theme: Some( + Style::modern() + .top_left_corner('┏') + .top_right_corner('┓') + .bottom_left_corner('┗') + .bottom_right_corner('┛') + .into(), + ), has_inner: true, } } @@ -116,6 +156,25 @@ impl TableTheme { .bottom_right_corner('┛') .horizontals([HorizontalLine::new(1, Line::full('━', '╋', '┣', '┫'))]) .into(), + full_theme: Some( + Style::modern() + .top('━') + .bottom('━') + .vertical('┃') + .left('┃') + .right('┃') + .top_intersection('┳') + .bottom_intersection('┻') + .top_left_corner('┏') + .top_right_corner('┓') + .bottom_left_corner('┗') + .bottom_right_corner('┛') + .horizontal('━') + .left_intersection('┣') + .right_intersection('┫') + .inner_intersection('╋') + .into(), + ), has_inner: true, } } @@ -123,6 +182,7 @@ impl TableTheme { pub fn none() -> TableTheme { Self { theme: Style::blank().into(), + full_theme: None, has_inner: true, } } @@ -151,4 +211,8 @@ impl TableTheme { pub fn has_inner(&self) -> bool { self.has_inner } + + pub fn into_full(&self) -> Option { + self.full_theme.clone() + } }