pub struct Console {
pub file: Box<dyn Write + Send>,
pub color_system: ColorSystem,
pub theme: Theme,
pub options: ConsoleOptions,
pub quiet: bool,
pub soft_wrap: bool,
/* private fields */
}Expand description
The main console for rendering rich output.
Fields§
§file: Box<dyn Write + Send>The output writer.
color_system: ColorSystemDetected color system.
theme: ThemeCurrent theme.
options: ConsoleOptionsDefault options.
quiet: boolIf true, suppress all output.
soft_wrap: boolIf true, text wraps at word boundaries.
Implementations§
Source§impl Console
impl Console
Sourcepub fn set_width(&mut self, width: usize)
pub fn set_width(&mut self, width: usize)
Set the console width (overrides auto-detected terminal width).
Sourcepub fn set_height(&mut self, height: usize)
pub fn set_height(&mut self, height: usize)
Set the console height.
Sourcepub fn render_lines(
&self,
renderable: &dyn Renderable,
options: &ConsoleOptions,
style: Option<&Style>,
_pad: bool,
) -> Vec<Vec<Segment>>
pub fn render_lines( &self, renderable: &dyn Renderable, options: &ConsoleOptions, style: Option<&Style>, _pad: bool, ) -> Vec<Vec<Segment>>
Render a renderable and return the segment lines.
Sourcepub fn get_style(&self, name: &str, default: &str) -> Option<Style>
pub fn get_style(&self, name: &str, default: &str) -> Option<Style>
Look up a style by name from the theme.
Sourcepub fn render_str(&self, text: &str, style: &str) -> Text
pub fn render_str(&self, text: &str, style: &str) -> Text
Render a string (with optional style).
Sourcepub fn print(&mut self, objects: &[&dyn Renderable], sep: &str, end: &str)
pub fn print(&mut self, objects: &[&dyn Renderable], sep: &str, end: &str)
Print one or more renderable objects, separated by sep, ending with
end.
Sourcepub fn println(&mut self, renderable: &dyn Renderable)
pub fn println(&mut self, renderable: &dyn Renderable)
Print a single renderable followed by a newline.
Sourcepub fn print_str(&mut self, text: &str)
pub fn print_str(&mut self, text: &str)
Print a plain string (supports markup by default when markup is
enabled).
Sourcepub fn print_json(&mut self, data: &Value)
pub fn print_json(&mut self, data: &Value)
Print formatted JSON.
Sourcepub fn show_cursor(&mut self)
pub fn show_cursor(&mut self)
Show the cursor.
Sourcepub fn hide_cursor(&mut self)
pub fn hide_cursor(&mut self)
Hide the cursor.
Sourcepub fn set_window_title(&mut self, title: &str)
pub fn set_window_title(&mut self, title: &str)
Set the terminal window title.
Sourcepub fn color_ansi(&self, color: &Color) -> String
pub fn color_ansi(&self, color: &Color) -> String
Get the ANSI escape string for a given color as this console supports.
Sourcepub fn render(
&self,
renderable: &dyn Renderable,
options: &ConsoleOptions,
) -> Vec<Segment>
pub fn render( &self, renderable: &dyn Renderable, options: &ConsoleOptions, ) -> Vec<Segment>
Render a renderable by recursively flattening nested items into
segments. This is equivalent to Python Rich’s Console.render().
It handles Group composition and any renderable that yields other
renderables.
Sourcepub fn measure(
&self,
renderable: &dyn Renderable,
options: &ConsoleOptions,
) -> Measurement
pub fn measure( &self, renderable: &dyn Renderable, options: &ConsoleOptions, ) -> Measurement
Measure a renderable’s width constraints.
Equivalent to Python Rich’s Measurement.get(console, options, renderable).
Sourcepub fn rule(
&mut self,
title: impl Into<String>,
characters: Option<&str>,
style: Option<Style>,
align: Option<AlignMethod>,
)
pub fn rule( &mut self, title: impl Into<String>, characters: Option<&str>, style: Option<Style>, align: Option<AlignMethod>, )
Render a rule with the given title.
Equivalent to Console.rule().
Sourcepub fn log(&mut self, objects: &[&dyn Renderable])
pub fn log(&mut self, objects: &[&dyn Renderable])
Output a log entry with timestamp, caller info.
Sourcepub fn push_theme(&mut self, theme: Theme)
pub fn push_theme(&mut self, theme: Theme)
Push a theme onto the stack.
Sourcepub fn export_html(&self, renderable: &dyn Renderable) -> String
pub fn export_html(&self, renderable: &dyn Renderable) -> String
Export the current console output as an HTML document.
Renders the given renderable and wraps it in a styled HTML page.
Sourcepub fn save_html(
&self,
path: impl AsRef<Path>,
renderable: &dyn Renderable,
) -> Result<()>
pub fn save_html( &self, path: impl AsRef<Path>, renderable: &dyn Renderable, ) -> Result<()>
Save rendered output as an HTML file.
Sourcepub fn export_svg(&self, renderable: &dyn Renderable) -> String
pub fn export_svg(&self, renderable: &dyn Renderable) -> String
Export the current console output as an SVG document.
Sourcepub fn save_svg(
&self,
path: impl AsRef<Path>,
renderable: &dyn Renderable,
) -> Result<()>
pub fn save_svg( &self, path: impl AsRef<Path>, renderable: &dyn Renderable, ) -> Result<()>
Save rendered output as an SVG file.
Sourcepub fn export_text(&self, renderable: &dyn Renderable) -> String
pub fn export_text(&self, renderable: &dyn Renderable) -> String
Export the current console output as plain text (strips ANSI).
Sourcepub fn save_text(
&self,
path: impl AsRef<Path>,
renderable: &dyn Renderable,
) -> Result<()>
pub fn save_text( &self, path: impl AsRef<Path>, renderable: &dyn Renderable, ) -> Result<()>
Save rendered output as a plain text file.
Sourcepub fn begin_capture(&mut self)
pub fn begin_capture(&mut self)
Enter a capture context. Returns the Console back so it can be
used inside a block. Call end_capture() to get the captured text.
Sourcepub fn end_capture(&mut self) -> String
pub fn end_capture(&mut self) -> String
End capture and return captured text.
Sourcepub fn set_soft_wrap(&mut self, soft_wrap: bool)
pub fn set_soft_wrap(&mut self, soft_wrap: bool)
Set the soft-wrap flag (wrap text at word boundaries when true).
Sourcepub fn input(&mut self, prompt: &str, password: bool) -> String
pub fn input(&mut self, prompt: &str, password: bool) -> String
Read a line of input from the user.
Writes prompt to the console, then reads a line from stdin.
When password is true, the input is masked with * characters
(using raw terminal mode via crossterm).
Sourcepub fn screen(&mut self) -> ScreenContext
pub fn screen(&mut self) -> ScreenContext
Create a ScreenContext that enters the
alternate screen buffer. The context automatically exits the alternate
screen when dropped.
Sourcepub fn set_alt_screen(&mut self, enable: bool)
pub fn set_alt_screen(&mut self, enable: bool)
Enter or exit the alternate screen buffer by writing the corresponding
escape sequences (\x1b[?1049h / \x1b[?1049l).
Sourcepub fn is_terminal(&self) -> bool
pub fn is_terminal(&self) -> bool
Get whether the output is a terminal.
Sourcepub fn set_size(&mut self, width: usize, height: usize)
pub fn set_size(&mut self, width: usize, height: usize)
Set the terminal size (overrides auto-detected dimensions).
Sourcepub fn on_broken_pipe(&self)
pub fn on_broken_pipe(&self)
Handle broken pipe errors gracefully.
In Rust, write() returns ErrorKind::BrokenPipe instead of raising
SIGPIPE, so broken pipes are not fatal. The Console already uses
let _ = write!(...) throughout, which silently discards all write
errors including EPIPE. This method is provided for API compatibility
with Python Rich and as a documentation point.