Always pretty print binary values in table (#12294)

# Description
Binary values passed to `table` may or may not be pretty formatted based
on the output destination. This leads to weird behavior as documented in
#12287. This PR changes `table` to always pretty print binary values.
However, binary values passed to external commands will not be formatted
(this is the existing behavior).

# User-Facing Changes
This is a breaking change. E.g.:
```nushell
0x[8989] | table | cat -
```
used to print raw bytes, but it will now print the pretty formatted
bytes.

# After Submitting
Add to 0.92.0 release notes and update documentation.
This commit is contained in:
Ian Manske
2024-03-26 18:22:34 +00:00
committed by GitHub
parent b07e206b36
commit b752fdb0dc
2 changed files with 25 additions and 30 deletions

View File

@ -466,20 +466,26 @@ impl ExternalCommand {
thread::Builder::new()
.name("external stdin worker".to_string())
.spawn(move || {
let stack = &mut stack.start_capture();
// Attempt to render the input as a table before piping it to the external.
// This is important for pagers like `less`;
// they need to get Nu data rendered for display to users.
//
// TODO: should we do something different for list<string> inputs?
// Users often expect those to be piped to *nix tools as raw strings separated by newlines
let input = crate::Table::run(
&crate::Table,
&engine_state,
stack,
&Call::new(head),
input,
);
let input = match input {
input @ PipelineData::Value(Value::Binary { .. }, ..) => {
Ok(input)
}
input => {
let stack = &mut stack.start_capture();
// Attempt to render the input as a table before piping it to the external.
// This is important for pagers like `less`;
// they need to get Nu data rendered for display to users.
//
// TODO: should we do something different for list<string> inputs?
// Users often expect those to be piped to *nix tools as raw strings separated by newlines
crate::Table.run(
&engine_state,
stack,
&Call::new(head),
input,
)
}
};
if let Ok(input) = input {
for value in input.into_iter() {