pub struct Explorer<'a> { /* private fields */ }Expand description
A renderable view of a document tree.
Scalars reuse core’s JSON styles, keys json.key, XML attributes
data.attribute; YAML anchors and aliases show as dim &name / *name
badges and INI/dotenv comments as a dim # comment. Every line is cut to
the available width: long strings shrink first (keeping their quotes),
then the line ends in …, so nothing wraps.
use rich::Console;
use rich_ext::data::{parse, Explorer, Format};
let node = parse(Format::Json, r#"{"a": {"b": 1, "c": 2}, "d": [1, 2, 3]}"#).unwrap();
let explorer = Explorer::new(&node).max_depth(1).root_label("doc");
let out = Console::builder().width(40).build().render_export(&explorer);
assert_eq!(out, "doc\n├── a: {…} 2 keys\n└── d: […] 3 items\n");Implementations§
Source§impl<'a> Explorer<'a>
impl<'a> Explorer<'a>
Sourcepub fn max_depth(self, depth: usize) -> Self
pub fn max_depth(self, depth: usize) -> Self
Fold containers this deep (the root is depth 0) to a summary like
{…} 3 keys.
Sourcepub fn max_length(self, length: usize) -> Self
pub fn max_length(self, length: usize) -> Self
Show at most this many children per container, then … N more.
Sourcepub fn max_string(self, length: usize) -> Self
pub fn max_string(self, length: usize) -> Self
Cut strings to this many characters (with …). Strings are also cut
to the available width regardless.
Sourcepub fn show_paths(self, show: bool) -> Self
pub fn show_paths(self, show: bool) -> Self
Append each leaf’s path, dim.
Sourcepub fn show_types(self, show: bool) -> Self
pub fn show_types(self, show: bool) -> Self
Append each node’s type (str, int, map, …), dim.
Sourcepub fn highlight(self, path: Path, style: Style) -> Self
pub fn highlight(self, path: Path, style: Style) -> Self
Style the tree line of the node at path, such as the selection of a
data::transform::Highlight. The table view ignores it.
Sourcepub fn root_label(self, label: impl Into<String>) -> Self
pub fn root_label(self, label: impl Into<String>) -> Self
The root line’s label (default: the root’s summary).
Trait Implementations§
Source§impl Renderable for Explorer<'_>
impl Renderable for Explorer<'_>
fn rich_render( &self, console: &Console, options: &ConsoleOptions, ) -> Vec<Segment>
Source§fn measure(&self, console: &Console, options: &ConsoleOptions) -> Measurement
fn measure(&self, console: &Console, options: &ConsoleOptions) -> Measurement
(minimum, maximum) cell width this renderable wants. The default
assumes the renderable fills the available width (e.g. Panel, Table);
Text overrides it with its content width so the top-level print path can
shrink to fit. Port of __rich_measure__ / Measurement.get.Source§fn fit_to_measurement(&self) -> bool
fn fit_to_measurement(&self) -> bool
Console::print shrinks this renderable to its
measured width. Upstream renders every top-level renderable at the full
console width, so the default is false; an extension may opt in.