mirror of
https://seed.radicle.dev/rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5.git
synced 2026-11-22 02:50:39 +08:00
Displays the current configuration. Also move to our tree-sitter highlighter for pretty-printing JSON and remove the `json-color` dependency.
16 lines
512 B
Rust
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())
|
|
}
|
|
}
|