Only abbreviate to "[table x rows]" if every value is a record (#7922)

# Description

Closes #6768.

BEFORE:
```
〉{ foo: [{a:1, b:2},2,3,4,5] }
╭─────┬────────────────╮
│ foo │ [table 5 rows] │
╰─────┴────────────────╯
```
AFTER:
```
〉{ foo: [{a:1, b:2},2,3,4,5] }
╭─────┬────────────────╮
│ foo │ [list 5 items] │
╰─────┴────────────────╯
```

# User-Facing Changes

See above.

# Tests + Formatting

Don't forget to add tests that cover your changes.

Make sure you've run and fixed any issues with these commands:

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect` to check that you're using the standard code
style
- `cargo test --workspace` to check that all tests pass

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
This commit is contained in:
Leon 2023-02-03 09:03:36 +10:00 committed by GitHub
parent 9945241b77
commit e89e734ca2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -565,18 +565,21 @@ impl Value {
)
}
Value::String { val, .. } => val.to_string(),
Value::List { ref vals, .. } => match &vals[..] {
[Value::Record { .. }, _end @ ..] => format!(
Value::List { ref vals, .. } => {
if !vals.is_empty() && vals.iter().all(|x| matches!(x, Value::Record { .. })) {
format!(
"[table {} row{}]",
vals.len(),
if vals.len() == 1 { "" } else { "s" }
),
_ => format!(
)
} else {
format!(
"[list {} item{}]",
vals.len(),
if vals.len() == 1 { "" } else { "s" }
),
},
)
}
}
Value::Record { cols, .. } => format!(
"{{record {} field{}}}",
cols.len(),