mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 05:34:58 +02:00
nu-table/ Do footer_inheritance by accouting for rows rather then a f… (#14380)
So it's my take on the comments in #14060
The change could be seen in this test.
Looks like it works :) but I haven't done a lot of testing.
0b1af77415/crates/nu-command/tests/commands/table.rs (L3032-L3062)
```nushell
$env.config.table.footer_inheritance = true;
$env.config.footer_mode = 7;
[[a b]; ['kv' {0: [[field]; [0] [1] [2] [3] [4] [5]]} ], ['data' 0], ['data' 0] ] | table --expand --width=80
```
```text
╭───┬──────┬───────────────────────╮
│ # │ a │ b │
├───┼──────┼───────────────────────┤
│ 0 │ kv │ ╭───┬───────────────╮ │
│ │ │ │ │ ╭───┬───────╮ │ │
│ │ │ │ 0 │ │ # │ field │ │ │
│ │ │ │ │ ├───┼───────┤ │ │
│ │ │ │ │ │ 0 │ 0 │ │ │
│ │ │ │ │ │ 1 │ 1 │ │ │
│ │ │ │ │ │ 2 │ 2 │ │ │
│ │ │ │ │ │ 3 │ 3 │ │ │
│ │ │ │ │ │ 4 │ 4 │ │ │
│ │ │ │ │ │ 5 │ 5 │ │ │
│ │ │ │ │ ╰───┴───────╯ │ │
│ │ │ ╰───┴───────────────╯ │
│ 1 │ data │ 0 │
│ 2 │ data │ 0 │
├───┼──────┼───────────────────────┤
│ # │ a │ b │
╰───┴──────┴───────────────────────╯
```
Maybe it will also solve the issue you @fdncred encountered.
close #14060
cc: @NotTheDr01ds
This commit is contained in:
@ -1088,7 +1088,7 @@ fn create_empty_placeholder(
|
||||
let data = vec![vec![cell]];
|
||||
let mut table = NuTable::from(data);
|
||||
table.set_data_style(TextStyle::default().dimmed());
|
||||
let out = TableOutput::new(table, false, false, false);
|
||||
let out = TableOutput::new(table, false, false, 1);
|
||||
|
||||
let style_computer = &StyleComputer::from_config(engine_state, stack);
|
||||
let config = create_nu_table_config(&config, style_computer, &out, false, TableMode::default());
|
||||
|
@ -2941,3 +2941,123 @@ fn table_footer_inheritance() {
|
||||
assert_eq!(actual.out.match_indices("x2").count(), 1);
|
||||
assert_eq!(actual.out.match_indices("x3").count(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn table_footer_inheritance_kv_rows() {
|
||||
let actual = nu!(
|
||||
concat!(
|
||||
"$env.config.table.footer_inheritance = true;",
|
||||
"$env.config.footer_mode = 7;",
|
||||
"[[a b]; ['kv' {0: 0, 1: 1, 2: 2, 3: 3, 4: 4} ], ['data' 0], ['data' 0] ] | table --expand --width=80",
|
||||
)
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
actual.out,
|
||||
"╭───┬──────┬───────────╮\
|
||||
│ # │ a │ b │\
|
||||
├───┼──────┼───────────┤\
|
||||
│ 0 │ kv │ ╭───┬───╮ │\
|
||||
│ │ │ │ 0 │ 0 │ │\
|
||||
│ │ │ │ 1 │ 1 │ │\
|
||||
│ │ │ │ 2 │ 2 │ │\
|
||||
│ │ │ │ 3 │ 3 │ │\
|
||||
│ │ │ │ 4 │ 4 │ │\
|
||||
│ │ │ ╰───┴───╯ │\
|
||||
│ 1 │ data │ 0 │\
|
||||
│ 2 │ data │ 0 │\
|
||||
╰───┴──────┴───────────╯"
|
||||
);
|
||||
|
||||
let actual = nu!(
|
||||
concat!(
|
||||
"$env.config.table.footer_inheritance = true;",
|
||||
"$env.config.footer_mode = 7;",
|
||||
"[[a b]; ['kv' {0: 0, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5} ], ['data' 0], ['data' 0] ] | table --expand --width=80",
|
||||
)
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
actual.out,
|
||||
"╭───┬──────┬───────────╮\
|
||||
│ # │ a │ b │\
|
||||
├───┼──────┼───────────┤\
|
||||
│ 0 │ kv │ ╭───┬───╮ │\
|
||||
│ │ │ │ 0 │ 0 │ │\
|
||||
│ │ │ │ 1 │ 1 │ │\
|
||||
│ │ │ │ 2 │ 2 │ │\
|
||||
│ │ │ │ 3 │ 3 │ │\
|
||||
│ │ │ │ 4 │ 4 │ │\
|
||||
│ │ │ │ 5 │ 5 │ │\
|
||||
│ │ │ ╰───┴───╯ │\
|
||||
│ 1 │ data │ 0 │\
|
||||
│ 2 │ data │ 0 │\
|
||||
├───┼──────┼───────────┤\
|
||||
│ # │ a │ b │\
|
||||
╰───┴──────┴───────────╯"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn table_footer_inheritance_list_rows() {
|
||||
let actual = nu!(
|
||||
concat!(
|
||||
"$env.config.table.footer_inheritance = true;",
|
||||
"$env.config.footer_mode = 7;",
|
||||
"[[a b]; ['kv' {0: [[field]; [0] [1] [2] [3] [4]]} ], ['data' 0], ['data' 0] ] | table --expand --width=80",
|
||||
)
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
actual.out,
|
||||
"╭───┬──────┬───────────────────────╮\
|
||||
│ # │ a │ b │\
|
||||
├───┼──────┼───────────────────────┤\
|
||||
│ 0 │ kv │ ╭───┬───────────────╮ │\
|
||||
│ │ │ │ │ ╭───┬───────╮ │ │\
|
||||
│ │ │ │ 0 │ │ # │ field │ │ │\
|
||||
│ │ │ │ │ ├───┼───────┤ │ │\
|
||||
│ │ │ │ │ │ 0 │ 0 │ │ │\
|
||||
│ │ │ │ │ │ 1 │ 1 │ │ │\
|
||||
│ │ │ │ │ │ 2 │ 2 │ │ │\
|
||||
│ │ │ │ │ │ 3 │ 3 │ │ │\
|
||||
│ │ │ │ │ │ 4 │ 4 │ │ │\
|
||||
│ │ │ │ │ ╰───┴───────╯ │ │\
|
||||
│ │ │ ╰───┴───────────────╯ │\
|
||||
│ 1 │ data │ 0 │\
|
||||
│ 2 │ data │ 0 │\
|
||||
╰───┴──────┴───────────────────────╯"
|
||||
);
|
||||
|
||||
let actual = nu!(
|
||||
concat!(
|
||||
"$env.config.table.footer_inheritance = true;",
|
||||
"$env.config.footer_mode = 7;",
|
||||
"[[a b]; ['kv' {0: [[field]; [0] [1] [2] [3] [4] [5]]} ], ['data' 0], ['data' 0] ] | table --expand --width=80",
|
||||
)
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
actual.out,
|
||||
"╭───┬──────┬───────────────────────╮\
|
||||
│ # │ a │ b │\
|
||||
├───┼──────┼───────────────────────┤\
|
||||
│ 0 │ kv │ ╭───┬───────────────╮ │\
|
||||
│ │ │ │ │ ╭───┬───────╮ │ │\
|
||||
│ │ │ │ 0 │ │ # │ field │ │ │\
|
||||
│ │ │ │ │ ├───┼───────┤ │ │\
|
||||
│ │ │ │ │ │ 0 │ 0 │ │ │\
|
||||
│ │ │ │ │ │ 1 │ 1 │ │ │\
|
||||
│ │ │ │ │ │ 2 │ 2 │ │ │\
|
||||
│ │ │ │ │ │ 3 │ 3 │ │ │\
|
||||
│ │ │ │ │ │ 4 │ 4 │ │ │\
|
||||
│ │ │ │ │ │ 5 │ 5 │ │ │\
|
||||
│ │ │ │ │ ╰───┴───────╯ │ │\
|
||||
│ │ │ ╰───┴───────────────╯ │\
|
||||
│ 1 │ data │ 0 │\
|
||||
│ 2 │ data │ 0 │\
|
||||
├───┼──────┼───────────────────────┤\
|
||||
│ # │ a │ b │\
|
||||
╰───┴──────┴───────────────────────╯"
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user