Hi there,

The case which was presented must be addressed.

But I did not test it properly...
I'd encourage you to do so.

Take care.

---------

Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>
This commit is contained in:
Maxim Zhiburt 2023-02-08 05:01:31 +03:00 committed by GitHub
parent a7fdca05c6
commit 6e6ef862c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 118 additions and 25 deletions

View File

@ -1333,24 +1333,31 @@ fn convert_to_table2_entry(
return value_to_styled_string(item, config, style_computer);
}
let table = match &item {
match &item {
Value::Record { span, cols, vals } => {
if cols.is_empty() && vals.is_empty() {
return value_to_styled_string(item, config, style_computer);
}
convert_to_table2(
0,
std::iter::once(item),
// we verify what is the structure of a Record cause it might represent
let table = build_expanded_table(
cols.clone(),
vals.clone(),
*span,
ctrlc.clone(),
config,
*span,
style_computer,
width,
deep.map(|i| i - 1),
flatten,
flatten_sep,
width,
)
);
match table {
Ok(Some(table)) => (table, TextStyle::default()),
_ => value_to_styled_string(item, config, style_computer),
}
}
Value::List { vals, span } => {
if flatten {
@ -1363,7 +1370,7 @@ fn convert_to_table2_entry(
}
}
convert_to_table2(
let table = convert_to_table2(
0,
vals.iter(),
ctrlc.clone(),
@ -1374,24 +1381,24 @@ fn convert_to_table2_entry(
flatten,
flatten_sep,
width,
)
);
let (table, whead, windex) = match table {
Ok(Some(out)) => out,
_ => return value_to_styled_string(item, config, style_computer),
};
let count_rows = table.count_rows();
let table_config =
create_table_config(config, style_computer, count_rows, whead, windex, false);
let table = table.draw(table_config, usize::MAX);
match table {
Some(table) => (table, TextStyle::default()),
None => value_to_styled_string(item, config, style_computer),
}
}
_ => return value_to_styled_string(item, config, style_computer), // unknown type.
};
let (table, whead, windex) = match table {
Ok(Some(out)) => out,
_ => return value_to_styled_string(item, config, style_computer),
};
let count_rows = table.count_rows();
let table_config =
create_table_config(config, style_computer, count_rows, whead, windex, false);
let table = table.draw(table_config, usize::MAX);
match table {
Some(table) => (table, TextStyle::default()),
None => value_to_styled_string(item, config, style_computer),
_ => value_to_styled_string(item, config, style_computer), // unknown type.
}
}

View File

@ -180,6 +180,92 @@ fn table_expand_flatten_and_deep_1() {
);
}
#[test]
fn table_expand_record_0() {
let actual = nu!(r#"[{c: {d: 1}}] | table --expand"#);
assert_eq!(
actual.out,
"╭───┬───────────╮\
# c \
\
0 \
d 1 \
\
"
);
}
#[test]
fn table_expand_record_1() {
let actual =
nu!(r#"[[a b, c]; [1 2 3] [4 5 [1 2 {a: 123, b: 234, c: 345}]]] | table --expand"#);
assert_eq!(
actual.out,
"╭───┬───┬───┬─────────────────────╮\
# a b c \
\
0 1 2 3 \
1 4 5 \
0 1 \
1 2 \
2 \
a 123 \
b 234 \
c 345 \
\
\
"
);
}
#[test]
fn table_expand_record_2() {
let structure = "{\
field1: [ a, b, c ],\
field2: [ 123, 234, 345 ],\
field3: [ [ head1, head2, head3 ]; [ 1 2 3 ] [ 79 79 79 ] [ { f1: 'a string', f2: 1000 }, 1, 2 ] ],\
field4: { f1: 1, f2: 3, f3: { f1: f1, f2: f2, f3: f3 } }\
}";
let actual = nu!(format!("{} | table --expand", structure));
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 \
\
\
"
);
}
#[test]
#[cfg(not(windows))]
fn external_with_too_much_stdout_should_not_hang_nu() {