forked from extern/nushell
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:
@ -362,7 +362,8 @@ fn handle_record(
|
||||
let result = if cols.is_empty() {
|
||||
create_empty_placeholder("record", term_width, engine_state, stack)
|
||||
} else {
|
||||
let opts = TableOpts::new(config, style_computer, ctrlc, span, 0, term_width);
|
||||
let indent = (config.table_indent.left, config.table_indent.right);
|
||||
let opts = TableOpts::new(config, style_computer, ctrlc, span, 0, term_width, indent);
|
||||
let result = build_table_kv(cols, vals, table_view, opts, span)?;
|
||||
match result {
|
||||
Some(output) => maybe_strip_color(output, config),
|
||||
@ -691,6 +692,7 @@ impl PagingTableCreator {
|
||||
self.head,
|
||||
self.row_offset,
|
||||
get_width_param(self.width_param),
|
||||
(cfg.table_indent.left, cfg.table_indent.right),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -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│\
|
||||
╰─┴─┴─╯"
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user