mirror of
https://github.com/nushell/nushell
synced 2025-01-15 06:34:15 +00:00
Simplify PipelineData::print (#6119)
* Simplify PipelineData::print Signed-off-by: nibon7 <nibon7@163.com> * make write_all_and_flush to be associated function Signed-off-by: nibon7 <nibon7@163.com>
This commit is contained in:
parent
8b35239bce
commit
5a5c65ee4b
1 changed files with 34 additions and 42 deletions
|
@ -467,29 +467,23 @@ impl PipelineData {
|
||||||
self,
|
self,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
for item in table {
|
table.write_all_and_flush(engine_state, config, no_newline, to_stderr)?;
|
||||||
let mut out = if let Value::Error { error } = item {
|
|
||||||
let working_set = StateWorkingSet::new(engine_state);
|
|
||||||
|
|
||||||
format_error(&working_set, &error)
|
|
||||||
} else if no_newline {
|
|
||||||
item.into_string("", config)
|
|
||||||
} else {
|
|
||||||
item.into_string("\n", config)
|
|
||||||
};
|
|
||||||
|
|
||||||
if !no_newline {
|
|
||||||
out.push('\n');
|
|
||||||
}
|
|
||||||
|
|
||||||
if !to_stderr {
|
|
||||||
stdout_write_all_and_flush(out)?
|
|
||||||
} else {
|
|
||||||
stderr_write_all_and_flush(out)?
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
|
self.write_all_and_flush(engine_state, config, no_newline, to_stderr)?;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_all_and_flush(
|
||||||
|
self,
|
||||||
|
engine_state: &EngineState,
|
||||||
|
config: &Config,
|
||||||
|
no_newline: bool,
|
||||||
|
to_stderr: bool,
|
||||||
|
) -> Result<(), ShellError> {
|
||||||
for item in self {
|
for item in self {
|
||||||
let mut out = if let Value::Error { error } = item {
|
let mut out = if let Value::Error { error } = item {
|
||||||
let working_set = StateWorkingSet::new(engine_state);
|
let working_set = StateWorkingSet::new(engine_state);
|
||||||
|
@ -511,8 +505,6 @@ impl PipelineData {
|
||||||
stderr_write_all_and_flush(out)?
|
stderr_write_all_and_flush(out)?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue