Fix the way the output of table is printed in print() (#12895)

# Description

Forgot that I fixed this already on my branch, but when printing without
a display output hook, the implicit call to `table` gets its output
mangled with newlines (since #12774). This happens when running `nu -c`
or a script file.

Here's that fix in one PR so it can be merged easily.

# Tests + Formatting
- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`
This commit is contained in:
Devyn Cairns 2024-05-17 07:18:18 -07:00 committed by GitHub
parent 8adf3406e5
commit 59f7c523fa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -543,16 +543,15 @@ impl PipelineData {
if let Some(decl_id) = engine_state.table_decl_id {
let command = engine_state.get_decl(decl_id);
if command.get_block_id().is_some() {
self.write_all_and_flush(engine_state, no_newline, to_stderr)?;
self.write_all_and_flush(engine_state, no_newline, to_stderr)
} else {
let call = Call::new(Span::new(0, 0));
let table = command.run(engine_state, stack, &call, self)?;
table.write_all_and_flush(engine_state, no_newline, to_stderr)?;
table.write_all_and_flush(engine_state, no_newline, to_stderr)
}
} else {
self.write_all_and_flush(engine_state, no_newline, to_stderr)?;
self.write_all_and_flush(engine_state, no_newline, to_stderr)
}
Ok(None)
}
}
@ -561,7 +560,11 @@ impl PipelineData {
engine_state: &EngineState,
no_newline: bool,
to_stderr: bool,
) -> Result<(), ShellError> {
) -> Result<Option<ExitStatus>, ShellError> {
if let PipelineData::ByteStream(stream, ..) = self {
// Copy ByteStreams directly
stream.print(to_stderr)
} else {
let config = engine_state.get_config();
for item in self {
let mut out = if let Value::Error { error, .. } = item {
@ -581,7 +584,8 @@ impl PipelineData {
}
}
Ok(())
Ok(None)
}
}
}