mirror of
https://github.com/nushell/nushell
synced 2024-12-26 21:13:19 +00:00
Use 'table' during internal->external (#898)
* Use 'table' during internal->external * Preserve more of config
This commit is contained in:
parent
def5869c1c
commit
d62716c83e
3 changed files with 52 additions and 29 deletions
|
@ -8,7 +8,7 @@ use std::sync::mpsc;
|
||||||
use nu_engine::env_to_strings;
|
use nu_engine::env_to_strings;
|
||||||
use nu_protocol::engine::{EngineState, Stack};
|
use nu_protocol::engine::{EngineState, Stack};
|
||||||
use nu_protocol::{ast::Call, engine::Command, ShellError, Signature, SyntaxShape, Value};
|
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;
|
use itertools::Itertools;
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ impl Command for External {
|
||||||
last_expression,
|
last_expression,
|
||||||
env_vars: env_vars_str,
|
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(
|
pub fn run_with_input(
|
||||||
&self,
|
&self,
|
||||||
engine_state: &EngineState,
|
engine_state: &EngineState,
|
||||||
|
stack: &mut Stack,
|
||||||
input: PipelineData,
|
input: PipelineData,
|
||||||
config: Config,
|
|
||||||
) -> Result<PipelineData, ShellError> {
|
) -> Result<PipelineData, ShellError> {
|
||||||
let head = self.name.span;
|
let head = self.name.span;
|
||||||
|
|
||||||
|
@ -155,33 +155,42 @@ impl ExternalCommand {
|
||||||
self.name.span,
|
self.name.span,
|
||||||
)),
|
)),
|
||||||
Ok(mut child) => {
|
Ok(mut child) => {
|
||||||
// if there is a string or a stream, that is sent to the pipe std
|
if !input.is_nothing() {
|
||||||
if let Some(mut stdin_write) = child.stdin.take() {
|
let engine_state = engine_state.clone();
|
||||||
std::thread::spawn(move || {
|
let mut stack = stack.clone();
|
||||||
for value in input.into_iter() {
|
stack.update_config(
|
||||||
match value {
|
"use_ansi_coloring",
|
||||||
Value::String { val, span: _ } => {
|
Value::Bool {
|
||||||
if stdin_write.write(val.as_bytes()).is_err() {
|
val: false,
|
||||||
return Ok(());
|
span: Span::new(0, 0),
|
||||||
}
|
},
|
||||||
}
|
);
|
||||||
Value::Binary { val, span: _ } => {
|
// if there is a string or a stream, that is sent to the pipe std
|
||||||
if stdin_write.write(&val).is_err() {
|
if let Some(mut stdin_write) = child.stdin.take() {
|
||||||
return Ok(());
|
std::thread::spawn(move || {
|
||||||
}
|
let input = crate::Table::run(
|
||||||
}
|
&crate::Table,
|
||||||
x => {
|
&engine_state,
|
||||||
if stdin_write
|
&mut stack,
|
||||||
.write(x.into_string(", ", &config).as_bytes())
|
&Call::new(),
|
||||||
.is_err()
|
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(());
|
return Err(());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Ok(())
|
Ok(())
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let last_expression = self.last_expression;
|
let last_expression = self.last_expression;
|
||||||
|
|
|
@ -178,10 +178,20 @@ impl Stack {
|
||||||
|
|
||||||
match config {
|
match config {
|
||||||
Ok(config) => config.into_config(),
|
Ok(config) => config.into_config(),
|
||||||
Err(e) => {
|
Err(e) => Err(e),
|
||||||
println!("Can't find {} in {:?}", CONFIG_VARIABLE_ID, self);
|
}
|
||||||
Err(e)
|
}
|
||||||
|
|
||||||
|
pub fn update_config(&mut self, name: &str, value: Value) {
|
||||||
|
if let Some(Value::Record { cols, vals, .. }) = self.vars.get_mut(&CONFIG_VARIABLE_ID) {
|
||||||
|
for col_val in cols.iter().zip(vals.iter_mut()) {
|
||||||
|
if col_val.0 == name {
|
||||||
|
*col_val.1 = value;
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
cols.push(name.to_string());
|
||||||
|
vals.push(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -75,6 +75,10 @@ impl PipelineData {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_nothing(&self) -> bool {
|
||||||
|
matches!(self, PipelineData::Value(Value::Nothing { .. }, ..))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn into_value(self, span: Span) -> Value {
|
pub fn into_value(self, span: Span) -> Value {
|
||||||
match self {
|
match self {
|
||||||
PipelineData::Value(Value::Nothing { .. }, ..) => Value::nothing(span),
|
PipelineData::Value(Value::Nothing { .. }, ..) => Value::nothing(span),
|
||||||
|
|
Loading…
Reference in a new issue