forked from extern/nushell
Use 'table' during internal->external (#898)
* Use 'table' during internal->external * Preserve more of config
This commit is contained in:
@ -8,7 +8,7 @@ use std::sync::mpsc;
|
||||
use nu_engine::env_to_strings;
|
||||
use nu_protocol::engine::{EngineState, Stack};
|
||||
use nu_protocol::{ast::Call, engine::Command, ShellError, Signature, SyntaxShape, Value};
|
||||
use nu_protocol::{Category, Config, PipelineData, RawStream, Span, Spanned};
|
||||
use nu_protocol::{Category, PipelineData, RawStream, Span, Spanned};
|
||||
|
||||
use itertools::Itertools;
|
||||
|
||||
@ -96,7 +96,7 @@ impl Command for External {
|
||||
last_expression,
|
||||
env_vars: env_vars_str,
|
||||
};
|
||||
command.run_with_input(engine_state, input, config)
|
||||
command.run_with_input(engine_state, stack, input)
|
||||
}
|
||||
}
|
||||
|
||||
@ -111,8 +111,8 @@ impl ExternalCommand {
|
||||
pub fn run_with_input(
|
||||
&self,
|
||||
engine_state: &EngineState,
|
||||
stack: &mut Stack,
|
||||
input: PipelineData,
|
||||
config: Config,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
let head = self.name.span;
|
||||
|
||||
@ -155,33 +155,42 @@ impl ExternalCommand {
|
||||
self.name.span,
|
||||
)),
|
||||
Ok(mut child) => {
|
||||
// if there is a string or a stream, that is sent to the pipe std
|
||||
if let Some(mut stdin_write) = child.stdin.take() {
|
||||
std::thread::spawn(move || {
|
||||
for value in input.into_iter() {
|
||||
match value {
|
||||
Value::String { val, span: _ } => {
|
||||
if stdin_write.write(val.as_bytes()).is_err() {
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
Value::Binary { val, span: _ } => {
|
||||
if stdin_write.write(&val).is_err() {
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
x => {
|
||||
if stdin_write
|
||||
.write(x.into_string(", ", &config).as_bytes())
|
||||
.is_err()
|
||||
{
|
||||
if !input.is_nothing() {
|
||||
let engine_state = engine_state.clone();
|
||||
let mut stack = stack.clone();
|
||||
stack.update_config(
|
||||
"use_ansi_coloring",
|
||||
Value::Bool {
|
||||
val: false,
|
||||
span: Span::new(0, 0),
|
||||
},
|
||||
);
|
||||
// if there is a string or a stream, that is sent to the pipe std
|
||||
if let Some(mut stdin_write) = child.stdin.take() {
|
||||
std::thread::spawn(move || {
|
||||
let input = crate::Table::run(
|
||||
&crate::Table,
|
||||
&engine_state,
|
||||
&mut stack,
|
||||
&Call::new(),
|
||||
input,
|
||||
);
|
||||
|
||||
if let Ok(input) = input {
|
||||
for value in input.into_iter() {
|
||||
if let Value::String { val, span: _ } = value {
|
||||
if stdin_write.write(val.as_bytes()).is_err() {
|
||||
return Ok(());
|
||||
}
|
||||
} else {
|
||||
return Err(());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
});
|
||||
|
||||
Ok(())
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
let last_expression = self.last_expression;
|
||||
|
Reference in New Issue
Block a user