This commit is contained in:
Reilly Wood 2024-08-04 17:10:59 +02:00 committed by GitHub
commit 06dde79dff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 73 additions and 111 deletions

View File

@ -96,22 +96,18 @@ Commands are separated by the pipe symbol (`|`) to denote a pipeline flowing lef
```shell
> ls | where type == "dir" | table
╭────┬──────────┬──────┬─────────┬───────────────╮
│ # │ name │ type │ size │ modified │
├────┼──────────┼──────┼─────────┼───────────────┤
│ 0 │ .cargo │ dir │ 0 B │ 9 minutes ago │
│ 1 │ assets │ dir │ 0 B │ 2 weeks ago │
│ 2 │ crates │ dir │ 4.0 KiB │ 2 weeks ago │
│ 3 │ docker │ dir │ 0 B │ 2 weeks ago │
│ 4 │ docs │ dir │ 0 B │ 2 weeks ago │
│ 5 │ images │ dir │ 0 B │ 2 weeks ago │
│ 6 │ pkg_mgrs │ dir │ 0 B │ 2 weeks ago │
│ 7 │ samples │ dir │ 0 B │ 2 weeks ago │
│ 8 │ src │ dir │ 4.0 KiB │ 2 weeks ago │
│ 9 │ target │ dir │ 0 B │ a day ago │
│ 10 │ tests │ dir │ 4.0 KiB │ 2 weeks ago │
│ 11 │ wix │ dir │ 0 B │ 2 weeks ago │
╰────┴──────────┴──────┴─────────┴───────────────╯
╭─#─┬──name───┬type─┬──size───┬───modified───╮
│ 0 │ assets │ dir │ 4.0 KiB │ 3 months ago │
│ 1 │ benches │ dir │ 4.0 KiB │ 3 weeks ago │
│ 2 │ crates │ dir │ 4.0 KiB │ 3 weeks ago │
│ 3 │ devdocs │ dir │ 4.0 KiB │ 3 weeks ago │
│ 4 │ docker │ dir │ 4.0 KiB │ 3 months ago │
│ 5 │ scripts │ dir │ 4.0 KiB │ 3 weeks ago │
│ 6 │ src │ dir │ 4.0 KiB │ 2 days ago │
│ 7 │ target │ dir │ 4.0 KiB │ 2 weeks ago │
│ 8 │ tests │ dir │ 4.0 KiB │ 3 weeks ago │
│ 9 │ wix │ dir │ 4.0 KiB │ a month ago │
╰───┴─────────┴─────┴─────────┴──────────────╯
```
Because most of the time you'll want to see the output of a pipeline, `table` is assumed.
@ -126,9 +122,7 @@ For example, we could use the built-in `ps` command to get a list of the running
```shell
> ps | where cpu > 0
╭───┬───────┬───────────┬───────┬───────────┬───────────╮
│ # │ pid │ name │ cpu │ mem │ virtual │
├───┼───────┼───────────┼───────┼───────────┼───────────┤
╭─#─┬──pid──┬───name────┬──cpu──┬────mem────┬──virtual──╮
│ 0 │ 2240 │ Slack.exe │ 16.40 │ 178.3 MiB │ 232.6 MiB │
│ 1 │ 16948 │ Slack.exe │ 16.32 │ 205.0 MiB │ 197.9 MiB │
│ 2 │ 17700 │ nu.exe │ 3.77 │ 26.1 MiB │ 8.8 MiB │

View File

@ -7,9 +7,7 @@ fn table_0() {
let actual = nu!("[[a b, c]; [1 2 3] [4 5 [1 2 3]]] | table --width=80");
assert_eq!(
actual.out,
"╭───┬───┬───┬────────────────╮\
# a b c \
\
"╭─#─┬─a─┬─b─┬───────c────────╮\
0 1 2 3 \
1 4 5 [list 3 items] \
"
@ -253,9 +251,7 @@ fn table_expand_0() {
let actual = nu!("[[a b, c]; [1 2 3] [4 5 [1 2 3]]] | table --width=80 --expand");
assert_eq!(
actual.out,
"╭───┬───┬───┬───────────╮\
# a b c \
\
"╭─#─┬─a─┬─b─┬─────c─────╮\
0 1 2 3 \
1 4 5 \
0 1 \
@ -276,9 +272,7 @@ fn table_expand_exceed_overlap_0() {
assert_eq!(
actual.out,
"╭───┬────────────────────────┬───┬───────────╮\
# a b c \
\
"╭─#─┬───────────a────────────┬─b─┬─────c─────╮\
0 xxxxxxxxxxxxxxxxxxxxxx 2 3 \
1 4 5 \
0 1 \
@ -296,9 +290,7 @@ fn table_expand_exceed_overlap_0() {
assert_eq!(
actual.out,
"╭──────┬───────────────────────────────────────────────────┬─────┬─────────────╮\
# a b c \
\
"╭──#───┬─────────────────────────a─────────────────────────┬──b──┬──────c──────╮\
0 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 2 3 \
1 4 5 \
0 1 \
@ -315,9 +307,7 @@ fn table_expand_deep_0() {
nu!("[[a b, c]; [1 2 3] [4 5 [1 2 [1 2 3]]]] | table --width=80 --expand --expand-deep=1");
assert_eq!(
actual.out,
"╭───┬───┬───┬────────────────────────╮\
# a b c \
\
"╭─#─┬─a─┬─b─┬───────────c────────────╮\
0 1 2 3 \
1 4 5 \
0 1 \
@ -334,9 +324,7 @@ fn table_expand_deep_1() {
nu!("[[a b, c]; [1 2 3] [4 5 [1 2 [1 2 3]]]] | table --width=80 --expand --expand-deep=0");
assert_eq!(
actual.out,
"╭───┬───┬───┬────────────────╮\
# a b c \
\
"╭─#─┬─a─┬─b─┬───────c────────╮\
0 1 2 3 \
1 4 5 [list 3 items] \
"
@ -349,9 +337,7 @@ fn table_expand_flatten_0() {
nu!("[[a b, c]; [1 2 3] [4 5 [1 2 [1 1 1]]]] | table --width=80 --expand --flatten ");
assert_eq!(
actual.out,
"╭───┬───┬───┬───────────────╮\
# a b c \
\
"╭─#─┬─a─┬─b─┬───────c───────╮\
0 1 2 3 \
1 4 5 \
0 1 \
@ -369,9 +355,7 @@ fn table_expand_flatten_1() {
);
assert_eq!(
actual.out,
"╭───┬───┬───┬───────────────╮\
# a b c \
\
"╭─#─┬─a─┬─b─┬───────c───────╮\
0 1 2 3 \
1 4 5 \
0 1 \
@ -390,9 +374,7 @@ fn table_expand_flatten_and_deep_1() {
assert_eq!(
actual.out,
"╭───┬───┬───┬────────────────────────────────╮\
# a b c \
\
"╭─#─┬─a─┬─b─┬───────────────c────────────────╮\
0 1 2 3 \
1 4 5 \
0 1 \
@ -413,9 +395,7 @@ fn table_expand_record_0() {
assert_eq!(
actual.out,
"╭───┬───────────╮\
# c \
\
"╭─#─┬─────c─────╮\
0 \
d 1 \
\
@ -430,9 +410,7 @@ fn table_expand_record_1() {
assert_eq!(
actual.out,
"╭───┬───┬───┬─────────────────────╮\
# a b c \
\
"╭─#─┬─a─┬─b─┬──────────c──────────╮\
0 1 2 3 \
1 4 5 \
0 1 \
@ -459,37 +437,35 @@ fn table_expand_record_2() {
assert_eq!(
actual.out,
"╭────────┬───────────────────────────────────────────╮\
\
field1 0 a \
1 b \
2 c \
\
\
field2 0 123 \
1 234 \
2 345 \
\
\
field3 # head1 head2 head3 \
\
0 1 2 3 \
1 79 79 79 \
2 1 2 \
f1 a string \
f2 1000 \
\
\
\
field4 f1 1 \
f2 3 \
\
f3 f1 f1 \
f2 f2 \
f3 f3 \
\
\
"
"╭────────┬───────────────────────────────────────╮\
\
field1 0 a \
1 b \
2 c \
\
\
field2 0 123 \
1 234 \
2 345 \
\
#head1head2head3 \
field3 0 1 2 3 \
1 79 79 79 \
2 1 2 \
f1 a string \
f2 1000 \
\
\
\
field4 f1 1 \
f2 3 \
\
f3 f1 f1 \
f2 f2 \
f3 f3 \
\
\
"
);
}
@ -2576,9 +2552,7 @@ fn table_padding_not_default() {
nu!("$env.config.table.padding = 5; [[a b, c]; [1 2 3] [4 5 [1 2 3]]] | table --width=80");
assert_eq!(
actual.out,
"╭───────────┬───────────┬───────────┬────────────────────────╮\
# a b c \
\
"╭─────#─────┬─────a─────┬─────b─────┬───────────c────────────╮\
0 1 2 3 \
1 4 5 [list 3 items] \
"
@ -2592,9 +2566,7 @@ fn table_padding_zero() {
);
assert_eq!(
actual.out,
"╭─┬─┬─┬──────────────╮\
#ab c \
\
"╭#┬a┬b┬──────c───────╮\
012 3\
145[list 3 items]\
"
@ -2608,9 +2580,7 @@ fn table_expand_padding_not_default() {
);
assert_eq!(
actual.out,
"╭─────────────┬─────────────┬─────────────┬────────────────────────────────────╮\
# a b c \
\
"╭──────#──────┬──────a──────┬──────b──────┬─────────────────c──────────────────╮\
0 1 2 3 \
1 4 5 \
0 1 \
@ -2626,9 +2596,7 @@ 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 --width=80 -e");
assert_eq!(
actual.out,
"╭─┬─┬─┬─────╮\
#ab c \
\
"╭#┬a┬b┬──c──╮\
012 3\
145\
01\
@ -2686,7 +2654,7 @@ fn table_leading_trailing_space_bg() {
);
assert_eq!(
actual.out,
"╭───┬───────┬───────┬────────────────╮│ # │ a │ b │ c │├───┼───────┼───────┼────────────────┤│ 0 │ 1 │ 2 │ 3 ││ 1 │ 4 │ hello │ [list 3 items] ││ │ │ world │ │╰───┴───────┴───────┴────────────────╯"
"╭─#─┬───a───┬───b───┬──────c ──────╮│ 0 │ 1 │ 2 │ 3 ││ 1 │ 4 │ hello │ [list 3 items] ││ │ │ world │ │╰───┴───────┴───────┴────────────────╯"
);
}
@ -2697,7 +2665,7 @@ fn table_leading_trailing_space_bg_expand() {
);
assert_eq!(
actual.out,
"╭───┬───────┬───────┬───────────────────────╮│ # │ a │ b │ c │├───┼───────┼───────┼───────────────────────┤│ 0 │ 1 │ 2 │ 3 ││ 1 │ 4 │ hello │ ╭───┬───────────────╮ ││ │ │ world │ │ 0 │ 1 │ ││ │ │ │ │ 1 │ 2 │ ││ │ │ │ │ 2 │ ╭───┬───────╮ │ ││ │ │ │ │ │ │ 0 │ 1 │ │ ││ │ │ │ │ │ │ 1 │ 2 │ │ ││ │ │ │ │ │ │ 2 │ 3 │ │ ││ │ │ │ │ │ ╰───┴───────╯ │ ││ │ │ │ ╰───┴───────────────╯ │╰───┴───────┴───────┴───────────────────────╯"
"╭─#─┬───a───┬───b───┬─────────c ──────────╮│ 0 │ 1 │ 2 │ 3 ││ 1 │ 4 │ hello │ ╭───┬───────────────╮ ││ │ │ world │ │ 0 │ 1 │ ││ │ │ │ │ 1 │ 2 │ ││ │ │ │ │ 2 │ ╭───┬───────╮ │ ││ │ │ │ │ │ │ 0 │ 1 │ │ ││ │ │ │ │ │ │ 1 │ 2 │ │ ││ │ │ │ │ │ │ 2 │ 3 │ │ ││ │ │ │ │ │ ╰───┴───────╯ │ ││ │ │ │ ╰───┴───────────────╯ │╰───┴───────┴───────┴───────────────────────╯"
);
}
@ -2706,17 +2674,17 @@ fn table_abbreviation() {
let actual = nu!(
r#"[[a b, c]; [1 2 3] [4 5 [1 2 3]] [1 2 3] [1 2 3] [1 2 3] [1 2 3] [1 2 3]] | table --width=80 -a 100"#
);
assert_eq!(actual.out, "╭───┬───┬───┬────────────────╮│ # │ a │ b │ c │├───┼───┼───┼────────────────┤│ 0 │ 1 │ 2 │ 3 ││ 1 │ 4 │ 5 │ [list 3 items] ││ 2 │ 1 │ 2 │ 3 ││ 3 │ 1 │ 2 │ 3 ││ 4 │ 1 │ 2 │ 3 ││ 5 │ 1 │ 2 │ 3 ││ 6 │ 1 │ 2 │ 3 │╰───┴───┴───┴────────────────╯");
assert_eq!(actual.out, "╭─#─┬─a─┬─b─┬───────c────────╮│ 0 │ 1 │ 2 │ 3 ││ 1 │ 4 │ 5 │ [list 3 items] ││ 2 │ 1 │ 2 │ 3 ││ 3 │ 1 │ 2 │ 3 ││ 4 │ 1 │ 2 │ 3 ││ 5 │ 1 │ 2 │ 3 ││ 6 │ 1 │ 2 │ 3 │╰───┴───┴───┴────────────────╯");
let actual = nu!(
r#"[[a b, c]; [1 2 3] [4 5 [1 2 3]] [1 2 3] [1 2 3] [1 2 3] [1 2 3] [1 2 3]] | table --width=80 -a 2"#
);
assert_eq!(actual.out, "╭───┬─────┬─────┬────────────────╮│ # │ a │ b │ c │├───┼─────┼─────┼────────────────┤│ 0 │ 1 │ 2 │ 3 ││ 1 │ 4 │ 5 │ [list 3 items] ││ 2 │ ... │ ... │ ... ││ 3 │ 1 │ 2 │ 3 ││ 4 │ 1 │ 2 │ 3 │╰───┴─────┴─────┴────────────────╯");
assert_eq!(actual.out, "╭─#─┬──a──┬──b──┬───────c────────╮│ 0 │ 1 │ 2 │ 3 ││ 1 │ 4 │ 5 │ [list 3 items] ││ 2 │ ... │ ... │ ... ││ 3 │ 1 │ 2 │ 3 ││ 4 │ 1 │ 2 │ 3 │╰───┴─────┴─────┴────────────────╯");
let actual = nu!(
r#"[[a b, c]; [1 2 3] [4 5 [1 2 3]] [1 2 3] [1 2 3] [1 2 3] [1 2 3] [1 2 3]] | table --width=80 -a 1"#
);
assert_eq!(actual.out, "╭───┬─────┬─────┬─────╮│ # │ a │ b │ c │├───┼─────┼─────┼─────┤│ 0 │ 1 │ 2 │ 3 ││ 1 │ ... │ ... │ ... ││ 2 │ 1 │ 2 │ 3 │╰───┴─────┴─────┴─────╯");
assert_eq!(actual.out, "╭─#─┬──a──┬──b──┬──c──╮│ 0 │ 1 │ 2 │ 3 ││ 1 │ ... │ ... │ ... ││ 2 │ 1 │ 2 │ 3 │╰───┴─────┴─────┴─────╯");
let actual = nu!(
r#"[[a b, c]; [1 2 3] [4 5 [1 2 3]] [1 2 3] [1 2 3] [1 2 3] [1 2 3] [1 2 3]] | table --width=80 -a 0"#
@ -2781,17 +2749,17 @@ fn table_abbreviation_by_config() {
let actual = nu!(
r#"$env.config.table.abbreviated_row_count = 100; [[a b, c]; [1 2 3] [4 5 [1 2 3]] [1 2 3] [1 2 3] [1 2 3] [1 2 3] [1 2 3]] | table --width=80"#
);
assert_eq!(actual.out, "╭───┬───┬───┬────────────────╮│ # │ a │ b │ c │├───┼───┼───┼────────────────┤│ 0 │ 1 │ 2 │ 3 ││ 1 │ 4 │ 5 │ [list 3 items] ││ 2 │ 1 │ 2 │ 3 ││ 3 │ 1 │ 2 │ 3 ││ 4 │ 1 │ 2 │ 3 ││ 5 │ 1 │ 2 │ 3 ││ 6 │ 1 │ 2 │ 3 │╰───┴───┴───┴────────────────╯");
assert_eq!(actual.out, "╭─#─┬─a─┬─b─┬───────c────────╮│ 0 │ 1 │ 2 │ 3 ││ 1 │ 4 │ 5 │ [list 3 items] ││ 2 │ 1 │ 2 │ 3 ││ 3 │ 1 │ 2 │ 3 ││ 4 │ 1 │ 2 │ 3 ││ 5 │ 1 │ 2 │ 3 ││ 6 │ 1 │ 2 │ 3 │╰───┴───┴───┴────────────────╯");
let actual = nu!(
r#"$env.config.table.abbreviated_row_count = 2; [[a b, c]; [1 2 3] [4 5 [1 2 3]] [1 2 3] [1 2 3] [1 2 3] [1 2 3] [1 2 3]] | table --width=80"#
);
assert_eq!(actual.out, "╭───┬─────┬─────┬────────────────╮│ # │ a │ b │ c │├───┼─────┼─────┼────────────────┤│ 0 │ 1 │ 2 │ 3 ││ 1 │ 4 │ 5 │ [list 3 items] ││ 2 │ ... │ ... │ ... ││ 3 │ 1 │ 2 │ 3 ││ 4 │ 1 │ 2 │ 3 │╰───┴─────┴─────┴────────────────╯");
assert_eq!(actual.out, "╭─#─┬──a──┬──b──┬───────c────────╮│ 0 │ 1 │ 2 │ 3 ││ 1 │ 4 │ 5 │ [list 3 items] ││ 2 │ ... │ ... │ ... ││ 3 │ 1 │ 2 │ 3 ││ 4 │ 1 │ 2 │ 3 │╰───┴─────┴─────┴────────────────╯");
let actual = nu!(
r#"$env.config.table.abbreviated_row_count = 1; [[a b, c]; [1 2 3] [4 5 [1 2 3]] [1 2 3] [1 2 3] [1 2 3] [1 2 3] [1 2 3]] | table --width=80"#
);
assert_eq!(actual.out, "╭───┬─────┬─────┬─────╮│ # │ a │ b │ c │├───┼─────┼─────┼─────┤│ 0 │ 1 │ 2 │ 3 ││ 1 │ ... │ ... │ ... ││ 2 │ 1 │ 2 │ 3 │╰───┴─────┴─────┴─────╯");
assert_eq!(actual.out, "╭─#─┬──a──┬──b──┬──c──╮│ 0 │ 1 │ 2 │ 3 ││ 1 │ ... │ ... │ ... ││ 2 │ 1 │ 2 │ 3 │╰───┴─────┴─────┴─────╯");
let actual = nu!(
r#"$env.config.table.abbreviated_row_count = 0; [[a b, c]; [1 2 3] [4 5 [1 2 3]] [1 2 3] [1 2 3] [1 2 3] [1 2 3] [1 2 3]] | table --width=80"#
@ -2804,12 +2772,12 @@ fn table_abbreviation_by_config_override() {
let actual = nu!(
r#"$env.config.table.abbreviated_row_count = 2; [[a b, c]; [1 2 3] [4 5 [1 2 3]] [1 2 3] [1 2 3] [1 2 3] [1 2 3] [1 2 3]] | table --width=80 -a 1"#
);
assert_eq!(actual.out, "╭───┬─────┬─────┬─────╮│ # │ a │ b │ c │├───┼─────┼─────┼─────┤│ 0 │ 1 │ 2 │ 3 ││ 1 │ ... │ ... │ ... ││ 2 │ 1 │ 2 │ 3 │╰───┴─────┴─────┴─────╯");
assert_eq!(actual.out, "╭─#─┬──a──┬──b──┬──c──╮│ 0 │ 1 │ 2 │ 3 ││ 1 │ ... │ ... │ ... ││ 2 │ 1 │ 2 │ 3 │╰───┴─────┴─────┴─────╯");
let actual = nu!(
r#"$env.config.table.abbreviated_row_count = 1; [[a b, c]; [1 2 3] [4 5 [1 2 3]] [1 2 3] [1 2 3] [1 2 3] [1 2 3] [1 2 3]] | table --width=80 -a 2"#
);
assert_eq!(actual.out, "╭───┬─────┬─────┬────────────────╮│ # │ a │ b │ c │├───┼─────┼─────┼────────────────┤│ 0 │ 1 │ 2 │ 3 ││ 1 │ 4 │ 5 │ [list 3 items] ││ 2 │ ... │ ... │ ... ││ 3 │ 1 │ 2 │ 3 ││ 4 │ 1 │ 2 │ 3 │╰───┴─────┴─────┴────────────────╯");
assert_eq!(actual.out, "╭─#─┬──a──┬──b──┬───────c────────╮│ 0 │ 1 │ 2 │ 3 ││ 1 │ 4 │ 5 │ [list 3 items] ││ 2 │ ... │ ... │ ... ││ 3 │ 1 │ 2 │ 3 ││ 4 │ 1 │ 2 │ 3 │╰───┴─────┴─────┴────────────────╯");
}
#[test]

View File

@ -53,7 +53,7 @@ pub struct Config {
pub external_completer: Option<Closure>,
pub filesize_metric: bool,
pub table_mode: TableMode,
pub table_move_header: bool,
pub table_header_on_border: bool,
pub table_show_empty: bool,
pub table_indent: TableIndent,
pub table_abbreviation_threshold: Option<usize>,
@ -126,7 +126,7 @@ impl Default for Config {
table_index_mode: TableIndexMode::Always,
table_show_empty: true,
trim_strategy: TrimStrategy::default(),
table_move_header: false,
table_header_on_border: true,
table_indent: TableIndent { left: 1, right: 1 },
table_abbreviation_threshold: None,
@ -454,7 +454,7 @@ impl Value {
&mut errors);
}
"header_on_separator" => {
process_bool_config(value, &mut errors, &mut config.table_move_header);
process_bool_config(value, &mut errors, &mut config.table_header_on_border);
}
"padding" => match value {
Value::Int { val, .. } => {

View File

@ -24,7 +24,7 @@ pub fn create_nu_table_config(
with_header: out.with_header,
split_color: Some(lookup_separator_color(comp)),
trim: config.trim_strategy.clone(),
header_on_border: config.table_move_header,
header_on_border: config.table_header_on_border,
expand,
}
}

View File

@ -168,7 +168,7 @@ $env.config = {
wrapping_try_keep_words: true # A strategy used by the 'wrapping' methodology
truncating_suffix: "..." # A suffix used by the 'truncating' methodology
}
header_on_separator: false # show header text on separator/border line
header_on_separator: true # show column headers on the top border of the table (more compact than in a separate header section)
# abbreviated_row_count: 10 # limit data rows from top and bottom after reaching a set point
}

View File

@ -87,7 +87,7 @@ fn in_used_in_range_to() -> TestResult {
#[test]
fn help_works_with_missing_requirements() -> TestResult {
run_test(r#"each --help | lines | length"#, "72")
run_test(r#"each --help | lines | length"#, "70")
}
#[test]