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).
Sourcepub fn style_rules(self, rules: StyleRules) -> Self
pub fn style_rules(self, rules: StyleRules) -> Self
Conditional styles (table::rules) for the
table view of records, by header. The tree ignores them.
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. Port of
__rich_measure__. The default is what upstream’s Measurement.get
returns for a renderable without one: anything from nothing to the
whole width, (0, max_width).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.Source§fn vertical(&self) -> Option<VerticalAlign>
fn vertical(&self) -> Option<VerticalAlign>
Table cell holding this renderable uses in
place of its column’s. Upstream reads getattr(renderable, "vertical", None); Align sets it.Source§fn print_end_line(&self, _options: &ConsoleOptions) -> bool
fn print_end_line(&self, _options: &ConsoleOptions) -> bool
"\n", so a print adds the final line break. A renderable
whose upstream output stops without one (Screen, LiveRender, a
Rule whose end has no newline) returns false, and the next
output continues its last line. options are the print’s options.