mirror of
https://github.com/nushell/nushell
synced 2025-01-14 14:14:13 +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,55 +467,47 @@ impl PipelineData {
|
|||
self,
|
||||
)?;
|
||||
|
||||
for item in table {
|
||||
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)?
|
||||
}
|
||||
}
|
||||
table.write_all_and_flush(engine_state, config, no_newline, to_stderr)?;
|
||||
}
|
||||
None => {
|
||||
for item in self {
|
||||
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)?
|
||||
}
|
||||
}
|
||||
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 {
|
||||
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)?
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub struct PipelineIterator(PipelineData);
|
||||
|
|
Loading…
Reference in a new issue