pub struct Json { /* private fields */ }Expand description
A parsed JSON document, rendered with syntax highlighting. Mirrors rich.json.JSON.
Implementations§
Source§impl Json
impl Json
Sourcepub fn new(text: &str) -> Result<Self>
pub fn new(text: &str) -> Result<Self>
Parse text as JSON. Returns an error if it is not valid JSON.
Sourcepub fn no_wrap(self, no_wrap: bool) -> Self
pub fn no_wrap(self, no_wrap: bool) -> Self
Keep rich.json.JSON’s self.text.no_wrap = True, which crops each
line at the available width instead of wrapping it.
Defaults to false, because that is what a top-level
Console.print(JSON(...)) produces and that is how this renderable is
normally reached. Upstream’s flag really is set, but Console.print
never renders the Text it is set on: _collect_renderables sees a
Text, buffers it, and check_text hands back
Text(sep, justify=…, end=…).join(buffered) — and Text.join starts
from self.blank_copy(), i.e. from the separator’s metadata. The
separator has no_wrap=None, so the copy that actually renders wraps
with the default fold overflow.
Turn it on whenever the document is nested inside another
renderable — a Panel, Padding, Styled, Constrain, or rich-cli’s
ForceWidth. Those are ConsoleRenderables, so _collect_renderables
appends them untouched and the inner Text reaches
Text.__rich_console__ with the flag intact; Text.wrap then skips
divide_line and only truncates to the width.
The two are not interchangeable. Wrapping keeps every character; cropping discards what does not fit, which for JSON means the printed document no longer parses — so the choice has to follow upstream’s, not taste.
Trait Implementations§
Source§impl Renderable for Json
impl Renderable for Json
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.