From f2aa952e8652abeaf5d7c6671288bab004dff29e Mon Sep 17 00:00:00 2001 From: Darren Schroeder <343840+fdncred@users.noreply.github.com> Date: Thu, 2 Dec 2021 08:32:12 -0600 Subject: [PATCH] add back debug --raw switch (#401) * add back debug --raw switch * tweak some debug and other settings --- crates/nu-command/src/core_commands/debug.rs | 22 +++++++++-- crates/nu-command/src/viewers/color_config.rs | 38 +++++++++++-------- crates/nu-command/src/viewers/table.rs | 3 +- crates/nu-protocol/src/value/mod.rs | 5 +++ 4 files changed, 48 insertions(+), 20 deletions(-) diff --git a/crates/nu-command/src/core_commands/debug.rs b/crates/nu-command/src/core_commands/debug.rs index 72023eabbb..e6df58baf6 100644 --- a/crates/nu-command/src/core_commands/debug.rs +++ b/crates/nu-command/src/core_commands/debug.rs @@ -15,7 +15,11 @@ impl Command for Debug { } fn signature(&self) -> Signature { - Signature::build("debug").category(Category::Core) + Signature::build("debug").category(Category::Core).switch( + "raw", + "Prints the raw value representation", + Some('r'), + ) } fn run( @@ -27,11 +31,21 @@ impl Command for Debug { ) -> Result { let head = call.head; let config = stack.get_config()?; + let raw = call.has_flag("raw"); input.map( - move |x| Value::String { - val: x.debug_string(", ", &config), - span: head, + move |x| { + if raw { + Value::String { + val: x.debug_value(), + span: head, + } + } else { + Value::String { + val: x.debug_string(", ", &config), + span: head, + } + } }, engine_state.ctrlc.clone(), ) diff --git a/crates/nu-command/src/viewers/color_config.rs b/crates/nu-command/src/viewers/color_config.rs index 20e00d2cee..7feedbd4fd 100644 --- a/crates/nu-command/src/viewers/color_config.rs +++ b/crates/nu-command/src/viewers/color_config.rs @@ -163,6 +163,9 @@ pub fn get_color_config(config: &Config) -> HashMap { hm.insert("binary".to_string(), Color::White.normal()); hm.insert("cellpath".to_string(), Color::White.normal()); hm.insert("row_index".to_string(), Color::Green.bold()); + hm.insert("record".to_string(), Color::White.normal()); + hm.insert("list".to_string(), Color::White.normal()); + hm.insert("block".to_string(), Color::White.normal()); for (key, value) in &config.color_config { update_hashmap(key, value, &mut hm); @@ -244,10 +247,14 @@ pub fn style_primitive(primitive: &str, color_hm: &HashMap) -> Te } } - // i think these are made up of other primitives - // "record" => {} - // "list" => {} - // "block" => {} + "record" | "list" | "block" => { + let style = color_hm.get(primitive); + match style { + Some(s) => TextStyle::with_style(Alignment::Left, *s), + None => TextStyle::basic_left(), + } + } + "nothing" => { let style = color_hm.get(primitive); match style { @@ -274,6 +281,17 @@ pub fn style_primitive(primitive: &str, color_hm: &HashMap) -> Te } } + "row_index" => { + let style = color_hm.get(primitive); + match style { + Some(s) => TextStyle::with_style(Alignment::Right, *s), + None => TextStyle::new() + .alignment(Alignment::Right) + .fg(Color::Green) + .bold(Some(true)), + } + } + // types in nushell but not in engine-q // "Line" => { // let style = color_hm.get("Primitive::Line"); @@ -338,17 +356,7 @@ pub fn style_primitive(primitive: &str, color_hm: &HashMap) -> Te // None => TextStyle::default_header(), // } // } - // "index_color" => { - // let style = color_hm.get("index_color"); - // match style { - // Some(s) => TextStyle::with_style(Alignment::Right, *s), - // None => TextStyle::new() - // .alignment(Alignment::Right) - // .fg(Color::Green) - // .bold(Some(true)), - // } - // } - _ => TextStyle::basic_center(), + _ => TextStyle::basic_left(), } } diff --git a/crates/nu-command/src/viewers/table.rs b/crates/nu-command/src/viewers/table.rs index 75b3786319..b70d71b37b 100644 --- a/crates/nu-command/src/viewers/table.rs +++ b/crates/nu-command/src/viewers/table.rs @@ -224,7 +224,8 @@ fn convert_to_table( let mut row: Vec<(String, String)> = vec![("string".to_string(), row_num.to_string())]; if headers.is_empty() { - row.push(("header".to_string(), item.into_string(", ", config))) + // if header row is empty, this is probably a list so format it that way + row.push(("list".to_string(), item.into_string(", ", config))) } else { for header in headers.iter().skip(1) { let result = match item { diff --git a/crates/nu-protocol/src/value/mod.rs b/crates/nu-protocol/src/value/mod.rs index 93fdf99f98..161b380b3c 100644 --- a/crates/nu-protocol/src/value/mod.rs +++ b/crates/nu-protocol/src/value/mod.rs @@ -317,6 +317,11 @@ impl Value { } } + /// Convert Value into a debug string + pub fn debug_value(self) -> String { + format!("{:#?}", self) + } + /// Convert Value into string. Note that Streams will be consumed. pub fn debug_string(self, separator: &str, config: &Config) -> String { match self {