add back debug --raw switch (#401)

* add back debug --raw switch

* tweak some debug and other settings
This commit is contained in:
Darren Schroeder 2021-12-02 08:32:12 -06:00 committed by GitHub
parent 071066b6d9
commit f2aa952e86
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 48 additions and 20 deletions

View file

@ -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<PipelineData, ShellError> {
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(),
)

View file

@ -163,6 +163,9 @@ pub fn get_color_config(config: &Config) -> HashMap<String, Style> {
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<String, Style>) -> 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<String, Style>) -> 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<String, Style>) -> 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(),
}
}

View file

@ -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 {

View file

@ -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 {