diff --git a/crates/nu-command/src/viewers/griddle.rs b/crates/nu-command/src/viewers/griddle.rs index d7747ca288..f16ec4a743 100644 --- a/crates/nu-command/src/viewers/griddle.rs +++ b/crates/nu-command/src/viewers/griddle.rs @@ -15,7 +15,7 @@ impl Command for Griddle { } fn usage(&self) -> &str { - "Render the grid." + "Renders the output to a textual terminal grid." } fn signature(&self) -> nu_protocol::Signature { @@ -27,6 +27,15 @@ impl Command for Griddle { ) } + fn extra_usage(&self) -> &str { + r#"grid was built to give a concise gridded layout for ls. however, +it determines what to put in the grid by looking for a column named +'name'. this works great for tables and records but for lists we +need to do something different. such as with '[one two three] | grid' +it creates a fake column called 'name' for these values so that it +prints out the list properly."# + } + fn run( &self, context: &EvaluationContext, @@ -57,21 +66,11 @@ impl Command for Griddle { } Value::Record { cols, vals, .. } => { // dbg!("value::record"); - - // let mut items = vec![]; - - // for (c, v) in cols.into_iter().zip(vals.into_iter()) { - // items.push(vec![c, v.into_string()]) - // } - // dbg!(&items); - - // Ok(create_grid_output(items, call, columns_param)) let mut items = vec![]; for (i, (c, v)) in cols.into_iter().zip(vals.into_iter()).enumerate() { items.push((i, c, v.into_string())) } - // dbg!(&items); Ok(create_grid_output2(items, call, columns_param)) } @@ -213,8 +212,6 @@ fn convert_to_list2(iter: impl IntoIterator) -> Option = headers.into_iter().map(|x| x.trim().to_string()).collect(); // let d: Vec> = data.into_iter().map(|x| x.into_iter().collect()).collect(); - // dbg!(&headers); - // dbg!(&data); let mut h: Vec = headers.into_iter().collect(); // let d: Vec> = data.into_iter().collect(); @@ -224,26 +221,22 @@ fn convert_to_list2(iter: impl IntoIterator) -> Option Result { + let term_width = if let Some((Width(w), Height(_h))) = terminal_size::terminal_size() { + w as usize + } else { + 80usize + }; + match input { Value::List { vals, .. } => { let table = convert_to_table(vals); if let Some(table) = table { - let result = nu_table::draw_table(&table, 80, &HashMap::new()); + let result = nu_table::draw_table(&table, term_width, &HashMap::new()); Ok(Value::String { val: result, @@ -46,7 +52,7 @@ impl Command for Table { let table = convert_to_table(stream); if let Some(table) = table { - let result = nu_table::draw_table(&table, 80, &HashMap::new()); + let result = nu_table::draw_table(&table, term_width, &HashMap::new()); Ok(Value::String { val: result, @@ -78,7 +84,7 @@ impl Command for Table { theme: nu_table::Theme::rounded(), }; - let result = nu_table::draw_table(&table, 80, &HashMap::new()); + let result = nu_table::draw_table(&table, term_width, &HashMap::new()); Ok(Value::String { val: result,