Files
heartwood/radicle-cli/src/terminal/json.rs
T
cloudhead ad7a3addb6 cli: Add rad config command
Displays the current configuration.

Also move to our tree-sitter highlighter for pretty-printing JSON and
remove the `json-color` dependency.
2023-11-30 10:46:32 +01:00

16 lines
512 B
Rust

use std::path::Path;
use crate::terminal as term;
/// Pretty-print a JSON value with syntax highlighting.
pub fn to_pretty(value: &impl serde::Serialize, path: &Path) -> anyhow::Result<Vec<term::Line>> {
let json = serde_json::to_string_pretty(&value)?;
let mut highlighter = term::highlight::Highlighter::default();
if let Some(highlighted) = highlighter.highlight(path, json.as_bytes())? {
Ok(highlighted)
} else {
Ok(json.split('\n').map(term::Line::new).collect())
}
}