This commit is contained in:
JT
2021-10-25 17:24:10 +13:00
parent b6d269e90a
commit 397a31e69c
8 changed files with 241 additions and 195 deletions

View File

@ -3,7 +3,7 @@ use nu_engine::CallExt;
use nu_protocol::{
ast::{Call, PathMember},
engine::{Command, EvaluationContext},
Signature, Span, SyntaxShape, Value,
IntoPipelineData, PipelineData, Signature, Span, SyntaxShape, Value,
};
use nu_term_grid::grid::{Alignment, Cell, Direction, Filling, Grid, GridOptions};
use terminal_size::{Height, Width};
@ -50,14 +50,14 @@ prints out the list properly."#
&self,
context: &EvaluationContext,
call: &Call,
input: Value,
) -> Result<nu_protocol::Value, nu_protocol::ShellError> {
input: PipelineData,
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
let width_param: Option<String> = call.get_flag(context, "width")?;
let color_param: bool = call.has_flag("color");
let separator_param: Option<String> = call.get_flag(context, "separator")?;
match input {
Value::List { vals, .. } => {
PipelineData::Value(Value::List { vals, .. }) => {
// dbg!("value::list");
let data = convert_to_list2(vals);
if let Some(items) = data {
@ -69,10 +69,10 @@ prints out the list properly."#
separator_param,
))
} else {
Ok(Value::Nothing { span: call.head })
Ok(PipelineData::new())
}
}
Value::Stream { stream, .. } => {
PipelineData::Stream(stream) => {
// dbg!("value::stream");
let data = convert_to_list2(stream);
if let Some(items) = data {
@ -85,10 +85,10 @@ prints out the list properly."#
))
} else {
// dbg!(data);
Ok(Value::Nothing { span: call.head })
Ok(PipelineData::new())
}
}
Value::Record { cols, vals, .. } => {
PipelineData::Value(Value::Record { cols, vals, .. }) => {
// dbg!("value::record");
let mut items = vec![];
@ -119,7 +119,7 @@ fn create_grid_output2(
width_param: Option<String>,
color_param: bool,
separator_param: Option<String>,
) -> Value {
) -> PipelineData {
let ls_colors = LsColors::from_env().unwrap_or_default();
let cols = if let Some(col) = width_param {
col.parse::<u16>().unwrap_or(80)
@ -167,6 +167,7 @@ fn create_grid_output2(
span: call.head,
}
}
.into_pipeline_data()
}
fn convert_to_list2(iter: impl IntoIterator<Item = Value>) -> Option<Vec<(usize, String, String)>> {

View File

@ -1,6 +1,6 @@
use nu_protocol::ast::{Call, PathMember};
use nu_protocol::engine::{Command, EvaluationContext};
use nu_protocol::{ShellError, Signature, Span, Value};
use nu_protocol::{IntoPipelineData, PipelineData, ShellError, Signature, Span, Value};
use nu_table::StyledString;
use std::collections::HashMap;
use terminal_size::{Height, Width};
@ -26,8 +26,8 @@ impl Command for Table {
&self,
_context: &EvaluationContext,
call: &Call,
input: Value,
) -> Result<nu_protocol::Value, nu_protocol::ShellError> {
input: PipelineData,
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
let term_width = if let Some((Width(w), Height(_h))) = terminal_size::terminal_size() {
w as usize
} else {
@ -35,7 +35,7 @@ impl Command for Table {
};
match input {
Value::List { vals, .. } => {
PipelineData::Value(Value::List { vals, .. }) => {
let table = convert_to_table(vals)?;
if let Some(table) = table {
@ -44,12 +44,13 @@ impl Command for Table {
Ok(Value::String {
val: result,
span: call.head,
})
}
.into_pipeline_data())
} else {
Ok(Value::Nothing { span: call.head })
Ok(PipelineData::new())
}
}
Value::Stream { stream, .. } => {
PipelineData::Stream(stream) => {
let table = convert_to_table(stream)?;
if let Some(table) = table {
@ -58,12 +59,13 @@ impl Command for Table {
Ok(Value::String {
val: result,
span: call.head,
})
}
.into_pipeline_data())
} else {
Ok(Value::Nothing { span: call.head })
Ok(PipelineData::new())
}
}
Value::Record { cols, vals, .. } => {
PipelineData::Value(Value::Record { cols, vals, .. }) => {
let mut output = vec![];
for (c, v) in cols.into_iter().zip(vals.into_iter()) {
@ -90,9 +92,10 @@ impl Command for Table {
Ok(Value::String {
val: result,
span: call.head,
})
}
.into_pipeline_data())
}
Value::Error { error } => Err(error),
PipelineData::Value(Value::Error { error }) => Err(error),
x => Ok(x),
}
}