pub struct ThemeContext<'a> { /* private fields */ }Expand description
A theme in use on a Console until this guard drops. Returned by
Console::use_theme; upstream’s ThemeContext.
Methods from Deref<Target = Console>§
Sourcepub fn color_system(&self) -> Option<ColorSystem>
pub fn color_system(&self) -> Option<ColorSystem>
The active color system, or None when styles are not rendered at
all. Port of Console.color_system.
Like upstream, this is independent of no_color:
no-colour mode keeps the colour system and strips only the colours at
output time, so bold, italic, underline and the like still render.
Callers asking “will colour reach the terminal?” must check both.
Sourcepub fn no_color(&self) -> bool
pub fn no_color(&self) -> bool
Whether colour output is disabled. Port of Console.no_color: set by
the builder, or by a non-empty NO_COLOR environment variable.
Sourcepub fn get_time(&self) -> f64
pub fn get_time(&self) -> f64
The current time in seconds from this console’s clock. Port of
Console.get_time (default time.monotonic); override it with
ConsoleBuilder::get_time for deterministic animation.
Sourcepub fn width(&self) -> usize
pub fn width(&self) -> usize
The width in cells. Port of the Console.width property: the
width of size.
Sourcepub fn set_height(&mut self, height: usize)
pub fn set_height(&mut self, height: usize)
Set the height. Port of the Console.height setter.
Sourcepub fn set_size(&mut self, width: usize, height: usize)
pub fn set_size(&mut self, width: usize, height: usize)
Set the width and height. Port of the Console.size setter.
Sourcepub fn set_quiet(&self, quiet: bool)
pub fn set_quiet(&self, quiet: bool)
Suppress (or restore) all output. Upstream’s Console.quiet is a
plain attribute; on_broken_pipe sets it.
Sourcepub fn set_soft_wrap(&mut self, soft_wrap: bool)
pub fn set_soft_wrap(&mut self, soft_wrap: bool)
Change the soft wrap default. Upstream’s Console.soft_wrap is a
plain attribute.
Sourcepub fn style(&self) -> Option<&StyleType>
pub fn style(&self) -> Option<&StyleType>
The style applied to all output, if any. Port of Console.style.
Sourcepub fn set_style(&mut self, style: Option<StyleType>)
pub fn set_style(&mut self, style: Option<StyleType>)
Change the style applied to all output. Upstream’s Console.style
is a plain attribute.
Sourcepub fn is_dumb_terminal(&self) -> bool
pub fn is_dumb_terminal(&self) -> bool
Whether the console writes to a terminal that cannot render styles:
TERM is dumb or unknown. Port of Console.is_dumb_terminal.
Sourcepub fn on_broken_pipe(&self)
pub fn on_broken_pipe(&self)
Called when a write fails because the reader closed the pipe. Port of
Console.on_broken_pipe: by default the console goes
quiet and the process exits with status 1 (upstream
raises SystemExit(1)). Upstream lets a subclass override it; here
ConsoleBuilder::on_broken_pipe gives the replacement.
Upstream also points standard output at os.devnull so that the
interpreter’s flush at exit does not fail again. A Rust process does
not flush at exit, so nothing is redirected.
Sourcepub fn is_terminal(&self) -> bool
pub fn is_terminal(&self) -> bool
Whether output is going to a real terminal.
Sourcepub fn legacy_windows(&self) -> bool
pub fn legacy_windows(&self) -> bool
Whether output targets a legacy Windows console (drives box substitution).
Sourcepub fn safe_box(&self) -> bool
pub fn safe_box(&self) -> bool
Whether to substitute box glyphs for terminal-safe variants (default on).
Sourcepub fn ascii_only(&self) -> bool
pub fn ascii_only(&self) -> bool
Whether the terminal can only render ASCII (forces the ASCII box).
Sourcepub fn get_style(&self, style: &StyleType) -> Result<Style>
pub fn get_style(&self, style: &StyleType) -> Result<Style>
Resolve a style name (or pass a style through) against this console’s
theme. Port of Console.get_style.
Sourcepub fn push_theme(&mut self, theme: Theme, inherit: bool)
pub fn push_theme(&mut self, theme: Theme, inherit: bool)
Push a theme on to the top of the stack. Port of Console.push_theme.
With inherit the new top is the current top’s styles overridden by
theme’s; without it, the new top is exactly theme. Prefer
use_theme, which pops again automatically.
Sourcepub fn pop_theme(&mut self) -> Result<()>
pub fn pop_theme(&mut self) -> Result<()>
Remove the top theme, restoring the previous one. Port of
Console.pop_theme; popping the base theme is an error
(upstream’s ThemeStackError("Unable to pop base theme")).
Sourcepub fn use_theme(&mut self, theme: Theme) -> ThemeContext<'_>
pub fn use_theme(&mut self, theme: Theme) -> ThemeContext<'_>
Use a theme until the returned guard is dropped. Port of
Console.use_theme, Python’s context manager as an RAII guard.
The guard dereferences to the console, so print through the guard while it is alive; dropping it pops the theme, including during a panic unwind.
let mut console = Console::builder().width(20).build();
let mut theme = Theme::new();
theme.insert("warning", Style::parse("bold red").unwrap());
{
let themed = console.use_theme(theme);
assert!(themed.theme().get("warning").is_some());
}
assert!(console.theme().get("warning").is_none());Upstream’s use_theme also takes inherit, but its ThemeContext
never passes it on to push_theme, so a used theme always inherits
(verified against rich 15.0.0). This port keeps that behaviour and
omits the ignored parameter; call push_theme to
replace the styles outright.
Sourcepub fn base_style(&self) -> &Style
pub fn base_style(&self) -> &Style
The whole-output base style.
Sourcepub fn add_highlighter(&mut self, highlighter: Box<dyn Highlighter + Send>)
pub fn add_highlighter(&mut self, highlighter: Box<dyn Highlighter + Send>)
Sourcepub fn options(&self) -> ConsoleOptions
pub fn options(&self) -> ConsoleOptions
The default render options for this console (full width, no height).
Sourcepub fn size(&self) -> ConsoleDimensions
pub fn size(&self) -> ConsoleDimensions
The size of the console. Port of the Console.size property: the
width and height given (the width one less on a legacy Windows
console, as upstream subtracts it when both are set), else 80x25 on
a dumb terminal, else the terminal’s size
for whichever was not given.
Sourcepub fn encoding(&self) -> &'static str
pub fn encoding(&self) -> &'static str
The output encoding: "ascii" for an ASCII-only
console, else "utf-8". Port of the Console.encoding property (which
reads the output file’s encoding; this port has no file to ask).
Sourcepub fn render_to_string(&self, renderable: &dyn Renderable) -> String
pub fn render_to_string(&self, renderable: &dyn Renderable) -> String
Render a value to an ANSI string (no trailing newline). Primarily for tests and inline rendering.
When no explicit justify is requested, the width is first shrunk to the renderable’s measured width (matching upstream’s measurement-fit for a bare top-level renderable).
Sourcepub fn render_segments_with(
&self,
renderable: &dyn Renderable,
options: &ConsoleOptions,
) -> Vec<Segment>
pub fn render_segments_with( &self, renderable: &dyn Renderable, options: &ConsoleOptions, ) -> Vec<Segment>
Render a renderable to segments with explicit render options, exactly
as print_with does before writing: a printed
Text goes through upstream’s Text.join, a renderable that opts in
is fitted to its measurement, and the result is cropped to the console
width (print(crop=True)). No trailing newline is added.
For upstream’s lower-level Console.render, see render.
Sourcepub fn render(
&self,
renderable: &dyn Renderable,
options: Option<&ConsoleOptions>,
) -> Vec<Segment>
pub fn render( &self, renderable: &dyn Renderable, options: Option<&ConsoleOptions>, ) -> Vec<Segment>
Render a renderable to segments. Port of Console.render: options
defaults to options, and nothing is rendered when
there is no width (max_width < 1).
Unlike the print path (render_segments_with)
the renderable is rendered as-is: no Text.join, no fitting and no
crop. Container renderables use this for their children.
As everywhere in this port, lines are separated by newline segments:
the final line has no trailing "\n" where upstream’s has one.
Sourcepub fn input(&self, prompt: &str) -> Result<Option<String>>
pub fn input(&self, prompt: &str) -> Result<Option<String>>
Display prompt and read a line of input from standard input. Port of
Console.input: the prompt is console markup, printed through the
console with end="" so it is captured and exported like any other
output. None means end of input.
Sourcepub fn input_from(
&self,
prompt: &dyn Renderable,
stream: &mut dyn InputSource,
) -> Result<Option<String>>
pub fn input_from( &self, prompt: &dyn Renderable, stream: &mut dyn InputSource, ) -> Result<Option<String>>
input with a renderable prompt (upstream accepts a
Text) and an explicit input source — upstream’s stream= argument.
Sourcepub fn render_lines(
&self,
renderable: &dyn Renderable,
options: &ConsoleOptions,
pad: bool,
) -> Vec<Vec<Segment>>
pub fn render_lines( &self, renderable: &dyn Renderable, options: &ConsoleOptions, pad: bool, ) -> Vec<Vec<Segment>>
Render a value into a list of lines, each a list of Segments.
Port of Console.render_lines. When pad is true, every line is padded
(or cropped) to options.max_width — this is what container renderables
such as Panel/Padding rely on to get uniform-width child rows.
Sourcepub fn render_lines_styled(
&self,
renderable: &dyn Renderable,
options: &ConsoleOptions,
style: Option<&Style>,
pad: bool,
) -> Vec<Vec<Segment>>
pub fn render_lines_styled( &self, renderable: &dyn Renderable, options: &ConsoleOptions, style: Option<&Style>, pad: bool, ) -> Vec<Vec<Segment>>
render_lines with upstream’s style= argument:
the style is applied under every rendered segment and to the padding
that fills each line, as Panel and Padding use it.
Sourcepub fn render_export(&self, renderable: &dyn Renderable) -> String
pub fn render_export(&self, renderable: &dyn Renderable) -> String
Render a value exactly as print would write it,
returning the string (including the single trailing newline). For tests
and export.
Sourcepub fn print(&self, renderable: &dyn Renderable)
pub fn print(&self, renderable: &dyn Renderable)
Render a value and write it to stdout, followed by a newline (unless
the renderable ends without one upstream:
Renderable::print_end_line).
Sourcepub fn print_with(&self, renderable: &dyn Renderable, options: &ConsoleOptions)
pub fn print_with(&self, renderable: &dyn Renderable, options: &ConsoleOptions)
Print with explicit render options, the equivalent of upstream’s
Console.print(renderable, justify=…, overflow=…, no_wrap=…). Start
from options and set the fields to override. A
printed Text defers to these options, because upstream’s Text.join
drops the text’s own justify, overflow and no_wrap.
Sourcepub fn render_export_with(
&self,
renderable: &dyn Renderable,
options: &ConsoleOptions,
) -> String
pub fn render_export_with( &self, renderable: &dyn Renderable, options: &ConsoleOptions, ) -> String
Like render_export, with explicit render
options as for print_with.
Sourcepub fn control(&self, control: &Control)
pub fn control(&self, control: &Control)
Write a terminal control sequence to stdout.
Port of Console.control. Control codes are only written when output is
a real terminal (they are meaningless when redirected to a file).
Sourcepub fn push_render_hook(&self, hook: Arc<dyn RenderHook>)
pub fn push_render_hook(&self, hook: Arc<dyn RenderHook>)
Add a render hook to the stack. Port of Console.push_render_hook.
Sourcepub fn pop_render_hook(&self)
pub fn pop_render_hook(&self)
Remove the last render hook pushed. Port of
Console.pop_render_hook; with none left, nothing happens (upstream
raises IndexError).
Sourcepub fn set_live(&self, live: Arc<dyn Any + Send + Sync>) -> bool
pub fn set_live(&self, live: Arc<dyn Any + Send + Sync>) -> bool
Push a live display on to this console’s stack, returning whether it
is the only one (the display that draws). Port of Console.set_live,
which upstream’s Live calls when it starts.
The stack is shared by the console’s clones. A
Live pushes itself here when it starts and
pops the stack when it stops; one started while the stack is not
empty is nested, and the first display draws it below its own
renderable. Anything else pushed here takes a place on the stack and
draws nothing.
Sourcepub fn clear_live(&self)
pub fn clear_live(&self)
Pop the last live display pushed by set_live.
Port of Console.clear_live; with none left, nothing happens
(upstream raises IndexError).
Sourcepub fn screen(
&self,
hide_cursor: bool,
style: Option<StyleType>,
) -> ScreenContext<'_>
pub fn screen( &self, hide_cursor: bool, style: Option<StyleType>, ) -> ScreenContext<'_>
Use the alternate screen until the returned guard drops. Port of
Console.screen(hide_cursor=…, style=…), Python’s context manager as
an RAII guard: the alternate screen is switched on (and the cursor
hidden, when hide_cursor), and switched back when the guard drops,
if it was switched at all (only a terminal is). Print a full-screen
renderable with ScreenContext::update.
Sourcepub fn status(&self, status: Status) -> LiveStatus<Stdout>
pub fn status(&self, status: Status) -> LiveStatus<Stdout>
Display a status and spinner until it is stopped. Port of
Console.status: status carries the message and upstream’s
keyword arguments (spinner, spinner_style, speed,
refresh_per_second), and the display starts at once on a copy of
this console, writing to standard output, as with console.status(…): does; LiveStatus::stop
ends it.
Sourcepub fn status_to<W: Write + Send + 'static>(
&self,
status: Status,
writer: W,
) -> LiveStatus<W>
pub fn status_to<W: Write + Send + 'static>( &self, status: Status, writer: W, ) -> LiveStatus<W>
status, writing to writer instead of standard
output (upstream’s console file).
Sourcepub fn is_alt_screen(&self) -> bool
pub fn is_alt_screen(&self) -> bool
Whether the alternate screen is enabled. Port of
Console.is_alt_screen.
Sourcepub fn set_alt_screen(&self, enable: bool) -> bool
pub fn set_alt_screen(&self, enable: bool) -> bool
Enable or disable the alternate screen. Port of
Console.set_alt_screen: only a terminal (not a legacy Windows
console) switches, and the result says whether it did.
Sourcepub fn update_screen(
&self,
renderable: &dyn Renderable,
region: Option<Region>,
options: Option<&ConsoleOptions>,
) -> Result<()>
pub fn update_screen( &self, renderable: &dyn Renderable, region: Option<Region>, options: Option<&ConsoleOptions>, ) -> Result<()>
Render renderable into region of the alternate screen (the whole
screen when None). Port of Console.update_screen.
Sourcepub fn update_screen_lines(
&self,
lines: &[Vec<Segment>],
x: usize,
y: usize,
) -> Result<()>
pub fn update_screen_lines( &self, lines: &[Vec<Segment>], x: usize, y: usize, ) -> Result<()>
Write rendered lines to the alternate screen at column x, row y.
Port of Console.update_screen_lines (through ScreenUpdate).
Sourcepub fn show_cursor(&self, show: bool)
pub fn show_cursor(&self, show: bool)
Show or hide the cursor. Port of Console.show_cursor.
Sourcepub fn capture(&self, f: impl FnOnce(&Console)) -> String
pub fn capture(&self, f: impl FnOnce(&Console)) -> String
Capture everything printed inside f instead of writing it to stdout,
returning it as a rendered (ANSI) string.
The Rust analogue of upstream’s with console.capture() as capture: —
the closure receives the same console, and captures nest correctly.
Equivalent to what would have been written to the terminal.
Each closure capture holds only what was printed inside it. Upstream’s
nested capture() contexts share one buffer, so the inner one takes
everything printed since the outer one began;
begin_capture and
end_capture behave that way.
Sourcepub fn begin_capture(&self)
pub fn begin_capture(&self)
Begin capturing this thread’s output: what is printed is held until
end_capture instead of written. Port of
Console.begin_capture.
Sourcepub fn end_capture(&self) -> String
pub fn end_capture(&self) -> String
End the innermost capture begun with
begin_capture on this thread, returning what
was printed as a terminal string. Port of Console.end_capture.
As upstream, which holds one buffer per thread, everything captured on the thread so far is returned, including what outer captures hold, and those are left empty. Without a capture to end, the result is empty (upstream’s console would stop writing altogether).
Sourcepub fn export_text(&self, f: impl FnOnce(&Console)) -> String
pub fn export_text(&self, f: impl FnOnce(&Console)) -> String
Like capture but with all styles stripped, returning
plain text. Port of Console.export_text(styles=False).
Sourcepub fn export_text_styled(&self, f: impl FnOnce(&Console)) -> String
pub fn export_text_styled(&self, f: impl FnOnce(&Console)) -> String
Like export_text with escape codes. Port of
Console.export_text(styles=True): each segment in the console’s
colour system (upstream’s style keeps the codes printing rendered),
or in truecolor, Style.render’s default, without one.
Sourcepub fn save_text(
&self,
path: impl AsRef<Path>,
styles: bool,
f: impl FnOnce(&Console),
) -> Result<()>
pub fn save_text( &self, path: impl AsRef<Path>, styles: bool, f: impl FnOnce(&Console), ) -> Result<()>
Write what f prints to path as text, with escape codes when
styles. Port of Console.save_text.
Sourcepub fn save_html(
&self,
path: impl AsRef<Path>,
f: impl FnOnce(&Console),
) -> Result<()>
pub fn save_html( &self, path: impl AsRef<Path>, f: impl FnOnce(&Console), ) -> Result<()>
Write what f prints to path as HTML with a stylesheet. Port of
Console.save_html (its default inline_styles=False).
Sourcepub fn save_svg(
&self,
path: impl AsRef<Path>,
title: &str,
unique_id: &str,
f: impl FnOnce(&Console),
) -> Result<()>
pub fn save_svg( &self, path: impl AsRef<Path>, title: &str, unique_id: &str, f: impl FnOnce(&Console), ) -> Result<()>
Write what f prints to path as SVG. Port of Console.save_svg;
as for export_svg, the unique_id is given.
Sourcepub fn page(&self, styles: bool, f: impl FnOnce(&Console)) -> Result<()>
pub fn page(&self, styles: bool, f: impl FnOnce(&Console)) -> Result<()>
Buffer everything printed inside f and display it through the system
pager. The Rust analogue of upstream’s with console.pager(): block.
Styles are stripped unless styles is set, matching
Console.pager(styles=False). When there’s no terminal to page in (piped
output, TERM=dumb) or no pager can be started, the content is written
straight to stdout.
Sourcepub fn page_with(
&self,
pager: &dyn Pager,
styles: bool,
f: impl FnOnce(&Console),
) -> Result<()>
pub fn page_with( &self, pager: &dyn Pager, styles: bool, f: impl FnOnce(&Console), ) -> Result<()>
Sourcepub fn page_with_links(
&self,
pager: &dyn Pager,
styles: bool,
links: bool,
f: impl FnOnce(&Console),
) -> Result<()>
pub fn page_with_links( &self, pager: &dyn Pager, styles: bool, links: bool, f: impl FnOnce(&Console), ) -> Result<()>
Like page_with, keeping hyperlinks when links
and styles are both set. Port of Console.pager(pager, styles, links): without styles everything is plain, and without links
each style loses its link (Segment.strip_links).
Sourcepub fn export_html(&self, f: impl FnOnce(&Console)) -> String
pub fn export_html(&self, f: impl FnOnce(&Console)) -> String
Capture output printed inside f and export it as a self-contained HTML
document (inline styles), using the default terminal theme. Port of
Console.export_html(inline_styles=True).
Sourcepub fn export_html_themed(
&self,
theme: &TerminalTheme,
f: impl FnOnce(&Console),
) -> String
pub fn export_html_themed( &self, theme: &TerminalTheme, f: impl FnOnce(&Console), ) -> String
Like export_html but with an explicit palette —
upstream’s export_html(theme=…). See terminal_theme for the
bundled presets.
Sourcepub fn export_html_classes(&self, f: impl FnOnce(&Console)) -> String
pub fn export_html_classes(&self, f: impl FnOnce(&Console)) -> String
Like export_html but with a generated CSS-class
stylesheet (.r1 {…}) instead of inline styles. Port of upstream’s
default Console.export_html(inline_styles=False).
Sourcepub fn export_html_classes_themed(
&self,
theme: &TerminalTheme,
f: impl FnOnce(&Console),
) -> String
pub fn export_html_classes_themed( &self, theme: &TerminalTheme, f: impl FnOnce(&Console), ) -> String
Like export_html_classes but with an
explicit palette — upstream’s export_html(theme=…, inline_styles=False).
Sourcepub fn export_svg(
&self,
title: &str,
unique_id: &str,
f: impl FnOnce(&Console),
) -> String
pub fn export_svg( &self, title: &str, unique_id: &str, f: impl FnOnce(&Console), ) -> String
Capture output printed inside f and export it as a self-contained SVG
image of a terminal window, using SVG_EXPORT_THEME. Port of
Console.export_svg.
unique_id prefixes every generated id/class. Upstream’s auto-computed
default hashes Python repr() output (not reproducible in Rust), so this
port takes an explicit id; output is byte-parity with
export_svg(title=…, unique_id=…) (see docs/DIVERGENCES.md #15).
Sourcepub fn export_svg_themed(
&self,
theme: &TerminalTheme,
title: &str,
unique_id: &str,
f: impl FnOnce(&Console),
) -> String
pub fn export_svg_themed( &self, theme: &TerminalTheme, title: &str, unique_id: &str, f: impl FnOnce(&Console), ) -> String
Like export_svg but with an explicit palette —
upstream’s export_svg(theme=…).
Sourcepub fn export_html_with(
&self,
theme: &TerminalTheme,
code_format: Option<&str>,
inline_styles: bool,
f: impl FnOnce(&Console),
) -> Result<String, ExportFormatError>
pub fn export_html_with( &self, theme: &TerminalTheme, code_format: Option<&str>, inline_styles: bool, f: impl FnOnce(&Console), ) -> Result<String, ExportFormatError>
Capture output printed inside f and export it as HTML with every
option of upstream’s Console.export_html: code_format (default
CONSOLE_HTML_FORMAT) and
inline_styles. See export::export_html_with.
Sourcepub fn export_svg_with(
&self,
theme: &TerminalTheme,
title: &str,
unique_id: &str,
code_format: Option<&str>,
font_aspect_ratio: f64,
f: impl FnOnce(&Console),
) -> Result<String, ExportFormatError>
pub fn export_svg_with( &self, theme: &TerminalTheme, title: &str, unique_id: &str, code_format: Option<&str>, font_aspect_ratio: f64, f: impl FnOnce(&Console), ) -> Result<String, ExportFormatError>
Capture output printed inside f and export it as SVG with every
option of upstream’s Console.export_svg: code_format (default
CONSOLE_SVG_FORMAT) and
font_aspect_ratio (upstream default 0.61). See
svg::export_svg_with.
Sourcepub fn record_output(&self, f: impl FnOnce(&Console)) -> Vec<Segment>
pub fn record_output(&self, f: impl FnOnce(&Console)) -> Vec<Segment>
Record everything f prints and hand back the raw segments, without
writing to the terminal.
This is the seam for producing several outputs from one render — the
terminal bytes and an HTML and an SVG file, say — which is what
rich --export-html … --export-svg … needs. Upstream reaches the same
place with Console(record=True) plus save_html(clear=False); here the
buffer is returned instead of being held on the console, so the caller
decides what to do with it and there is no hidden state to clear.
Pair with segments_to_string to get the
terminal form, export::export_html_classes
for HTML, and svg::export_svg for SVG.
Rendering twice instead would be wrong, not merely wasteful: a renderable reading standard input only yields its content once.
Sourcepub fn set_record(&self, record: bool)
pub fn set_record(&self, record: bool)
Start (or stop) recording. Upstream’s Console.record is a plain
attribute.
Sourcepub fn export_text_recorded(&self, clear: bool, styles: bool) -> Result<String>
pub fn export_text_recorded(&self, clear: bool, styles: bool) -> Result<String>
The recorded output as text, with escape codes when styles, the
record cleared when clear. Port of Console.export_text(clear=…, styles=…) for a console built with
record; upstream’s default is
clear=True, styles=False. Without plain text, control codes are
left out; with styles they stay, as upstream’s.
The styled form renders each style in the console’s colour system,
truecolor without one, as export_text_styled.
§Errors
RichError::Console when the
console is not recording (upstream asserts).
Sourcepub fn save_text_recorded(
&self,
path: impl AsRef<Path>,
clear: bool,
styles: bool,
) -> Result<()>
pub fn save_text_recorded( &self, path: impl AsRef<Path>, clear: bool, styles: bool, ) -> Result<()>
Write export_text_recorded to path.
Port of Console.save_text(path, clear=…, styles=…).
Sourcepub fn export_html_recorded(
&self,
options: &ExportHtmlOptions<'_>,
) -> Result<String>
pub fn export_html_recorded( &self, options: &ExportHtmlOptions<'_>, ) -> Result<String>
The recorded output as an HTML document. Port of
Console.export_html(theme=…, clear=…, code_format=…, inline_styles=…) for a console built with
record.
§Errors
RichError::Console when the
console is not recording, or when code_format is not a template
this port can fill (see export::export_html_with).
Sourcepub fn save_html_recorded(
&self,
path: impl AsRef<Path>,
options: &ExportHtmlOptions<'_>,
) -> Result<()>
pub fn save_html_recorded( &self, path: impl AsRef<Path>, options: &ExportHtmlOptions<'_>, ) -> Result<()>
Write export_html_recorded to path.
Port of Console.save_html.
Sourcepub fn export_svg_recorded(
&self,
options: &ExportSvgOptions<'_>,
) -> Result<String>
pub fn export_svg_recorded( &self, options: &ExportSvgOptions<'_>, ) -> Result<String>
The recorded output as an SVG image of a terminal window. Port of
Console.export_svg(title=…, theme=…, clear=…, code_format=…, font_aspect_ratio=…, unique_id=…) for a console built with
record. Control codes are left out, and
the image is as wide as the console is now.
§Errors
As for export_html_recorded.
Sourcepub fn save_svg_recorded(
&self,
path: impl AsRef<Path>,
options: &ExportSvgOptions<'_>,
) -> Result<()>
pub fn save_svg_recorded( &self, path: impl AsRef<Path>, options: &ExportSvgOptions<'_>, ) -> Result<()>
Write export_svg_recorded to path.
Port of Console.save_svg.
Sourcepub fn print_str(&self, content: &str)
pub fn print_str(&self, content: &str)
Parse content as console markup, apply registered highlighters, and
print it. This is the console.print("...") path.
Sourcepub fn render_str_to_string(&self, content: &str) -> String
pub fn render_str_to_string(&self, content: &str) -> String
Same as Console::print_str but returns the ANSI string.
Sourcepub fn build_text(&self, content: &str) -> Text
pub fn build_text(&self, content: &str) -> Text
Parse content as console markup (expanding emoji + applying the active
highlighters), returning the styled Text that print_str would print.
Exposed so callers can wrap the markup in another renderable.
Sourcepub fn try_build_text(&self, content: &str) -> Result<Text>
pub fn try_build_text(&self, content: &str) -> Result<Text>
As build_text, but returns
RichError::Markup for malformed
markup instead of falling back to the raw text — upstream’s behaviour.
Sourcepub fn render_str(&self, content: &str, highlight: Option<bool>) -> Text
pub fn render_str(&self, content: &str, highlight: Option<bool>) -> Text
Convert a plain string to Text the way a str renderable is
converted upstream: emoji codes expand (per the console), console
markup is parsed, and highlighting runs when highlight (or, when
None, the console default) enables it. Port of Console.render_str,
which Table cells, Tree labels and Columns items go through.
Malformed markup falls back to the literal text, as
build_text does (docs/DIVERGENCES.md §2).
Sourcepub fn try_print_str(&self, content: &str) -> Result<()>
pub fn try_print_str(&self, content: &str) -> Result<()>
As print_str, but reports malformed markup.
Sourcepub fn try_print_justified(&self, content: &str, justify: Justify) -> Result<()>
pub fn try_print_justified(&self, content: &str, justify: Justify) -> Result<()>
As print_justified, but reports malformed
markup.
Sourcepub fn render_str_with(
&self,
content: &str,
options: &RenderStrOptions<'_>,
) -> Result<Text>
pub fn render_str_with( &self, content: &str, options: &RenderStrOptions<'_>, ) -> Result<Text>
Convert a string to Text with every keyword upstream’s
Console.render_str takes. Port of Console.render_str, strict:
malformed markup is an error (MarkupError), not the literal text.
Emoji, markup and highlighting default to the console’s settings when
the option is None. As upstream, a highlighted result is a fresh
Text carrying only spans (the highlighter’s, then the markup’s): the
style, justify and overflow are dropped by copy_styles.
Sourcepub fn emoji(&self) -> bool
pub fn emoji(&self) -> bool
Whether :emoji: codes are replaced by default. Port of
Console(emoji=…).
Sourcepub fn highlight(&self) -> bool
pub fn highlight(&self) -> bool
Whether printed strings are highlighted by default. Port of
Console(highlight=…).
Sourcepub fn markup(&self) -> bool
pub fn markup(&self) -> bool
Whether printed strings are parsed as console markup by default. Port
of Console(markup=…).
Sourcepub fn emoji_variant(&self) -> Option<EmojiVariant>
pub fn emoji_variant(&self) -> Option<EmojiVariant>
The default emoji variant. Port of Console(emoji_variant=…).
Sourcepub fn tab_size(&self) -> usize
pub fn tab_size(&self) -> usize
The tab stop width Text expands tabs to. Port of Console.tab_size.
Sourcepub fn set_tab_size(&mut self, tab_size: usize)
pub fn set_tab_size(&mut self, tab_size: usize)
Change the tab stop width. Upstream’s Console.tab_size is a plain
attribute.
Sourcepub fn set_window_title(&self, title: &str) -> bool
pub fn set_window_title(&self, title: &str) -> bool
Set the terminal window title. Port of Console.set_window_title:
only a terminal is sent the code, and the return value says whether it
was.
Sourcepub fn print_justified(&self, content: &str, justify: Justify)
pub fn print_justified(&self, content: &str, justify: Justify)
Parse content as markup and print it justified to the console width.
This is the console.print("...", justify=...) path.
Sourcepub fn render_justified_to_string(
&self,
content: &str,
justify: Justify,
) -> String
pub fn render_justified_to_string( &self, content: &str, justify: Justify, ) -> String
Same as Console::print_justified but returns the ANSI string.
The justify is passed via options.justify, which — matching upstream —
disables the measurement-fit so the text pads to the full width.
Sourcepub fn segments_to_string(&self, segments: &[Segment]) -> String
pub fn segments_to_string(&self, segments: &[Segment]) -> String
Convert rendered segments into a terminal string, applying this console’s
colour system (and honouring no_color). Port of Console._render_buffer.
Sourcepub fn log(
&self,
objects: &[LogObject<'_>],
options: &LogOptions<'_>,
) -> Result<()>
pub fn log( &self, objects: &[LogObject<'_>], options: &LogOptions<'_>, ) -> Result<()>
Log objects with the time and the caller’s file and line. Port of
Console.log(*objects, sep=…, end=…, style=…, justify=…, emoji=…, markup=…, highlight=…): the objects are joined as for print and
laid out by upstream’s LogRender table, with the time (blank when
it repeats the last one) and file:line linked to the file.
The caller is the code calling log, found with #[track_caller]
(upstream inspects the stack). log_at names it.
Sourcepub fn log_at(
&self,
objects: &[LogObject<'_>],
options: &LogOptions<'_>,
file: &str,
line: u32,
) -> Result<()>
pub fn log_at( &self, objects: &[LogObject<'_>], options: &LogOptions<'_>, file: &str, line: u32, ) -> Result<()>
log with the caller’s file and line given:
upstream’s _caller_frame_info. The path column shows the file’s
name, linked to its absolute path unless it starts with <.
Sourcepub fn print_objects(
&self,
objects: &[PrintObject<'_>],
options: &PrintOptions<'_>,
) -> Result<()>
pub fn print_objects( &self, objects: &[PrintObject<'_>], options: &PrintOptions<'_>, ) -> Result<()>
Print objects as upstream’s Console.print(*objects, sep=…, end=…, style=…, justify=…, overflow=…, no_wrap=…, emoji=…, markup=…, highlight=…, width=…, height=…, crop=…, soft_wrap=…, new_line_start=…) does. Strings and texts in a row join into one
Text with sep and end with end; other renderables stand alone.
Malformed markup is an error, as upstream’s MarkupError.
Sourcepub fn render_objects(
&self,
objects: &[PrintObject<'_>],
options: &PrintOptions<'_>,
) -> Result<Vec<Segment>>
pub fn render_objects( &self, objects: &[PrintObject<'_>], options: &PrintOptions<'_>, ) -> Result<Vec<Segment>>
The segments print_objects writes, ending
as upstream’s do (a trailing newline included).
Sourcepub fn rule(
&self,
title: &str,
characters: &str,
style: impl Into<StyleType>,
align: HorizontalAlign,
)
pub fn rule( &self, title: &str, characters: &str, style: impl Into<StyleType>, align: HorizontalAlign, )
Draw a rule with an optional title. Port of Console.rule(title, characters=…, style=…, align=…).
Sourcepub fn out(
&self,
objects: &[&str],
sep: &str,
end: &str,
style: Option<StyleType>,
highlight: Option<bool>,
) -> Result<()>
pub fn out( &self, objects: &[&str], sep: &str, end: &str, style: Option<StyleType>, highlight: Option<bool>, ) -> Result<()>
Write objects joined by sep with no markup, emoji, wrapping or
cropping. Port of Console.out.
Sourcepub fn print_json(&self, json: &str, options: &JsonOptions) -> Result<()>
pub fn print_json(&self, json: &str, options: &JsonOptions) -> Result<()>
Pretty print a JSON string. Port of Console.print_json: a
Json printed with soft_wrap=True.
Sourcepub fn measure(
&self,
renderable: &dyn Renderable,
options: Option<&ConsoleOptions>,
) -> Measurement
pub fn measure( &self, renderable: &dyn Renderable, options: Option<&ConsoleOptions>, ) -> Measurement
The width renderable needs under options (the console’s when
None). Port of Console.measure.