mirror of
https://github.com/nushell/nushell
synced 2024-12-28 22:13:10 +00:00
add back debug --raw switch (#401)
* add back debug --raw switch * tweak some debug and other settings
This commit is contained in:
parent
071066b6d9
commit
f2aa952e86
4 changed files with 48 additions and 20 deletions
|
@ -15,7 +15,11 @@ impl Command for Debug {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn signature(&self) -> Signature {
|
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(
|
fn run(
|
||||||
|
@ -27,11 +31,21 @@ impl Command for Debug {
|
||||||
) -> Result<PipelineData, ShellError> {
|
) -> Result<PipelineData, ShellError> {
|
||||||
let head = call.head;
|
let head = call.head;
|
||||||
let config = stack.get_config()?;
|
let config = stack.get_config()?;
|
||||||
|
let raw = call.has_flag("raw");
|
||||||
|
|
||||||
input.map(
|
input.map(
|
||||||
move |x| Value::String {
|
move |x| {
|
||||||
val: x.debug_string(", ", &config),
|
if raw {
|
||||||
span: head,
|
Value::String {
|
||||||
|
val: x.debug_value(),
|
||||||
|
span: head,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Value::String {
|
||||||
|
val: x.debug_string(", ", &config),
|
||||||
|
span: head,
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
engine_state.ctrlc.clone(),
|
engine_state.ctrlc.clone(),
|
||||||
)
|
)
|
||||||
|
|
|
@ -163,6 +163,9 @@ pub fn get_color_config(config: &Config) -> HashMap<String, Style> {
|
||||||
hm.insert("binary".to_string(), Color::White.normal());
|
hm.insert("binary".to_string(), Color::White.normal());
|
||||||
hm.insert("cellpath".to_string(), Color::White.normal());
|
hm.insert("cellpath".to_string(), Color::White.normal());
|
||||||
hm.insert("row_index".to_string(), Color::Green.bold());
|
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 {
|
for (key, value) in &config.color_config {
|
||||||
update_hashmap(key, value, &mut hm);
|
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" => {}
|
let style = color_hm.get(primitive);
|
||||||
// "list" => {}
|
match style {
|
||||||
// "block" => {}
|
Some(s) => TextStyle::with_style(Alignment::Left, *s),
|
||||||
|
None => TextStyle::basic_left(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
"nothing" => {
|
"nothing" => {
|
||||||
let style = color_hm.get(primitive);
|
let style = color_hm.get(primitive);
|
||||||
match style {
|
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
|
// types in nushell but not in engine-q
|
||||||
// "Line" => {
|
// "Line" => {
|
||||||
// let style = color_hm.get("Primitive::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(),
|
// None => TextStyle::default_header(),
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// "index_color" => {
|
_ => TextStyle::basic_left(),
|
||||||
// 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(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -224,7 +224,8 @@ fn convert_to_table(
|
||||||
let mut row: Vec<(String, String)> = vec![("string".to_string(), row_num.to_string())];
|
let mut row: Vec<(String, String)> = vec![("string".to_string(), row_num.to_string())];
|
||||||
|
|
||||||
if headers.is_empty() {
|
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 {
|
} else {
|
||||||
for header in headers.iter().skip(1) {
|
for header in headers.iter().skip(1) {
|
||||||
let result = match item {
|
let result = match item {
|
||||||
|
|
|
@ -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.
|
/// Convert Value into string. Note that Streams will be consumed.
|
||||||
pub fn debug_string(self, separator: &str, config: &Config) -> String {
|
pub fn debug_string(self, separator: &str, config: &Config) -> String {
|
||||||
match self {
|
match self {
|
||||||
|
|
Loading…
Reference in a new issue