Improved inspect

This commit is contained in:
2026-07-31 05:21:06 +02:00
parent b5ec2eed40
commit 9d0ff45bdd
2 changed files with 34 additions and 13 deletions
+27 -9
View File
@@ -10,15 +10,24 @@ impl Formatted for InspectTarget {
match self {
Self::None => vec!["\x1b[2mnothing to inspect\x1b[0m".to_string()],
Self::Some(items) => items
.iter()
.map(|item| match item {
InspectItem::F64(v) => format_f64(*v),
InspectItem::USD(v) => format!("${}", format_f64(*v)),
InspectItem::Symbol(v) => format!("\x1b[35m{v}\x1b[0m"),
InspectItem::String(v) => v.clone(),
})
.collect(),
Self::Some(items) => {
let items = items
.iter()
.map(|row| {
(
format_inspect_item(&row.0),
format_inspect_item(&row.1),
format_inspect_item(&row.2),
)
})
.collect::<Vec<_>>();
items
.iter()
.map(|(a, b, c)| Triple(a, b, c))
.collect::<Vec<_>>()
.get_formatted()
}
}
}
}
@@ -226,6 +235,15 @@ pub fn apply_padding(mut items: Vec<String>) -> Vec<String> {
items
}
pub fn format_inspect_item(item: &InspectItem) -> String {
match item {
InspectItem::F64(v) => format_f64(v.as_f64()),
InspectItem::USD(v) => format!("${}", format_f64(v.as_f64())),
InspectItem::Symbol(v) => format!("\x1b[35m{v}\x1b[0m"),
InspectItem::Name(v) => v.clone(),
}
}
pub fn format_symbol(value: &str) -> String {
format!("\x1b[35m{value}\x1b[0m")
}