nu-table/ Add table.indent configuration (#9983)

Hi there.

Am I got it right?

ref: https://github.com/zhiburt/tabled/issues/358
cc: @fdncred

---------

Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>
This commit is contained in:
Maxim Zhiburt
2023-08-11 16:37:16 +03:00
committed by GitHub
parent a0cecf7658
commit aa37572ddc
11 changed files with 226 additions and 13 deletions

View File

@ -2560,3 +2560,107 @@ fn theme_cmd(theme: &str, footer: bool, then: &str) -> String {
format!("$env.config.table.mode = {theme}; $env.config.table.header_on_separator = true; {with_foorter}; {then}")
}
#[test]
fn table_padding_not_default() {
let actual = nu!("$env.config.table.padding = 5; [[a b, c]; [1 2 3] [4 5 [1 2 3]]] | table");
assert_eq!(
actual.out,
"╭───────────┬───────────┬───────────┬────────────────────────╮\
│ # │ a │ b │ c │\
├───────────┼───────────┼───────────┼────────────────────────┤\
│ 0 │ 1 │ 2 │ 3 │\
│ 1 │ 4 │ 5 │ [list 3 items] │\
╰───────────┴───────────┴───────────┴────────────────────────╯"
);
}
#[test]
fn table_padding_zero() {
let actual = nu!(
"$env.config.table.padding = {left: 0, right: 0}; [[a b, c]; [1 2 3] [4 5 [1 2 3]]] | table"
);
assert_eq!(
actual.out,
"╭─┬─┬─┬──────────────╮\
│#│a│b│ c │\
├─┼─┼─┼──────────────┤\
│0│1│2│ 3│\
│1│4│5│[list 3 items]│\
╰─┴─┴─┴──────────────╯"
);
}
#[test]
fn table_expand_padding_not_default() {
let actual = nu!("$env.config.table.padding = 5; [[a b, c]; [1 2 3] [4 5 [1 2 3]]] | table -e");
assert_eq!(
actual.out,
"╭───────────┬───────────┬───────────┬───────────────────────────────────╮\
│ # │ a │ b │ c │\
├───────────┼───────────┼───────────┼───────────────────────────────────┤\
│ 0 │ 1 │ 2 │ 3 │\
│ 1 │ 4 │ 5 │ ╭───────────┬───────────╮ │\
│ │ │ │ │ 0 │ 1 │ │\
│ │ │ │ │ 1 │ 2 │ │\
│ │ │ │ │ 2 │ 3 │ │\
│ │ │ │ ╰───────────┴───────────╯ │\
╰───────────┴───────────┴───────────┴───────────────────────────────────╯"
);
}
#[test]
fn table_expand_padding_zero() {
let actual = nu!("$env.config.table.padding = {left: 0, right: 0}; [[a b, c]; [1 2 3] [4 5 [1 2 3]]] | table -e");
assert_eq!(
actual.out,
"╭─┬─┬─┬─────╮\
│#│a│b│ c │\
├─┼─┼─┼─────┤\
│0│1│2│ 3│\
│1│4│5│╭─┬─╮│\
│ │ │ ││0│1││\
│ │ │ ││1│2││\
│ │ │ ││2│3││\
│ │ │ │╰─┴─╯│\
╰─┴─┴─┴─────╯"
);
}
#[test]
fn table_collapse_padding_not_default() {
let actual = nu!("$env.config.table.padding = 5; [[a b, c]; [1 2 3] [4 5 [1 2 3]]] | table -c");
assert_eq!(
actual.out,
"╭───────────┬───────────┬───────────╮\
│ a │ b │ c │\
├───────────┼───────────┼───────────┤\
│ 1 │ 2 │ 3 │\
├───────────┼───────────┼───────────┤\
│ 4 │ 5 │ 1 │\
│ │ ├───────────┤\
│ │ │ 2 │\
│ │ ├───────────┤\
│ │ │ 3 │\
╰───────────┴───────────┴───────────╯"
);
}
#[test]
fn table_collapse_padding_zero() {
let actual = nu!("$env.config.table.padding = {left: 0, right: 0}; [[a b, c]; [1 2 3] [4 5 [1 2 3]]] | table -c");
assert_eq!(
actual.out,
"╭─┬─┬─╮\
│a│b│c│\
├─┼─┼─┤\
│1│2│3│\
├─┼─┼─┤\
│4│5│1│\
│ │ ├─┤\
│ │ │2│\
│ │ ├─┤\
│ │ │3│\
╰─┴─┴─╯"
);
}