Skip to content

Commit

Permalink
Display keys and values inline
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementNerma committed Dec 9, 2024
1 parent 728b64b commit 7acf1c3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 28 deletions.
42 changes: 15 additions & 27 deletions crates/runtime/src/pretty_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,12 @@ impl PrettyPrintable for RuntimeValue {

keys.iter()
.map(|key| {
let mut styled_key = pretty_printable_string_parts(key);
styled_key.push(Styled::colored(":", Color::Cyan));
styled_key.push(Styled::colorless(" "));

// Yes, that part is a hack :p
PrettyPrintablePiece::List {
begin: styled_key,
items: vec![map.get(*key).unwrap().generate_pretty_data(ctx)],
sep: vec![],
end: vec![],
suffix: None,
}
PrettyPrintablePiece::Join(vec![
pretty_printable_string(key),
PrettyPrintablePiece::colored_atomic(":", Color::Blue),
PrettyPrintablePiece::Atomic(Styled::colorless(" ")),
map.get(*key).unwrap().generate_pretty_data(ctx),
])
})
.collect()
},
Expand All @@ -116,16 +110,13 @@ impl PrettyPrintable for RuntimeValue {
let keys = obj.keys().collect::<BTreeSet<_>>();

keys.iter()
.map(|field|
// Yes, that part is a hack :p
PrettyPrintablePiece::List {
begin: vec![Styled::colored(field, Color::Red),Styled::colored(":", Color::Blue), Styled::colorless(" ")],
items: vec![
obj.get(*field).unwrap().generate_pretty_data(ctx)
],
sep: vec![],
end: vec![],
suffix: None
.map(|field| {
PrettyPrintablePiece::Join(vec![
PrettyPrintablePiece::colored_atomic(field, Color::Red),
PrettyPrintablePiece::colored_atomic(":", Color::Blue),
PrettyPrintablePiece::Atomic(Styled::colorless(" ")),
obj.get(*field).unwrap().generate_pretty_data(ctx),
])
})
.collect()
},
Expand Down Expand Up @@ -228,11 +219,8 @@ impl PrettyPrintable for SingleCmdArgResult {
}
}
}
pub fn pretty_printable_string(string: &str) -> PrettyPrintablePiece {
PrettyPrintablePiece::Suite(pretty_printable_string_parts(string))
}

pub fn pretty_printable_string_parts(string: &str) -> Vec<Styled> {
pub fn pretty_printable_string(string: &str) -> PrettyPrintablePiece {
let mut pieces = vec![Styled::colored("'", Color::BrightGreen)];

let mut shift = 0;
Expand Down Expand Up @@ -261,5 +249,5 @@ pub fn pretty_printable_string_parts(string: &str) -> Vec<Styled> {

pieces.push(Styled::colored("'", Color::BrightGreen));

pieces
PrettyPrintablePiece::Suite(pieces)
}
2 changes: 1 addition & 1 deletion crates/shared/src/pretty/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub enum PrettyPrintablePiece {
}

impl PrettyPrintablePiece {
/// Create an atom
/// Create a colored atom
pub fn colored_atomic(content: impl AsRef<str>, color: Color) -> Self {
Self::Atomic(Styled::colored(content, color))
}
Expand Down

0 comments on commit 7acf1c3

Please sign in to comment.