Context manager to capture the result of printing to the console. See capture()
for how to use.
console (Console) – A console instance to capture output.
Get the result of the capture.
An error in the Capture context manager.
A high level console interface.
color_system (str, optional) – The color system supported by your terminal, either "standard"
, "256"
or "truecolor"
. Leave as "auto"
to autodetect.
force_terminal (Optional[bool], optional) – Enable/disable terminal control codes, or None to auto-detect terminal. Defaults to None.
force_jupyter (Optional[bool], optional) – Enable/disable Jupyter rendering, or None to auto-detect Jupyter. Defaults to None.
force_interactive (Optional[bool], optional) – Enable/disable interactive mode, or None to auto detect. Defaults to None.
soft_wrap (Optional[bool], optional) – Set soft wrap default on print method. Defaults to False.
theme (Theme, optional) – An optional style theme object, or None
for default theme.
stderr (bool, optional) – Use stderr rather than stdout if file
is not specified. Defaults to False.
file (IO, optional) – A file object where the console should write to. Defaults to stdout.
quiet (bool, Optional) – Boolean to suppress all output. Defaults to False.
width (int, optional) – The width of the terminal. Leave as default to auto-detect width.
height (int, optional) – The height of the terminal. Leave as default to auto-detect height.
style (StyleType, optional) – Style to apply to all output, or None for no style. Defaults to None.
no_color (Optional[bool], optional) – Enabled no color mode, or None to auto detect. Defaults to None.
tab_size (int, optional) – Number of spaces used to replace a tab character. Defaults to 8.
record (bool, optional) – Boolean to enable recording of terminal output, required to call export_html()
, export_svg()
, and export_text()
. Defaults to False.
markup (bool, optional) – Boolean to enable Console Markup. Defaults to True.
emoji (bool, optional) – Enable emoji code. Defaults to True.
emoji_variant (str, optional) – Optional emoji variant, either “text” or “emoji”. Defaults to None.
highlight (bool, optional) – Enable automatic highlighting. Defaults to True.
log_time (bool, optional) – Boolean to enable logging of time by log()
methods. Defaults to True.
log_path (bool, optional) – Boolean to enable the logging of the caller by log()
. Defaults to True.
log_time_format (Union[str, TimeFormatterCallable], optional) – If log_time
is enabled, either string for strftime or callable that formats the time. Defaults to “[%X] “.
highlighter (HighlighterType, optional) – Default highlighter.
legacy_windows (bool, optional) – Enable legacy Windows mode, or None
to auto detect. Defaults to None
.
safe_box (bool, optional) – Restrict box options that don’t render on legacy Windows.
get_datetime (Callable[[], datetime], optional) – Callable that gets the current time as a datetime.datetime object (used by Console.log), or None for datetime.now.
get_time (Callable[[], time], optional) – Callable that gets the current time in seconds, default uses time.monotonic.
Begin capturing console output. Call end_capture()
to exit capture mode and return output.
None
Play a ‘bell’ sound (if supported by the terminal).
None
A context manager to capture the result of print() or log() in a string, rather than writing it to the console.
Example
>>> from rich.console import Console >>> console = Console() >>> with console.capture() as capture: ... console.print("[bold magenta]Hello World[/]") >>> print(capture.get())
Context manager with disables writing to the terminal.
Clear the screen.
home (bool, optional) – Also move the cursor to ‘home’ position. Defaults to True.
None
Clear the Live instance.
None
Get color system string.
“standard”, “256” or “truecolor”.
Optional[str]
Insert non-printing control codes.
control_codes (str) – Control codes, such as those that may move the cursor.
control (Control)
None
Get the encoding of the console file, e.g. "utf-8"
.
A standard encoding string.
End capture mode and return captured string.
Console output.
Generate HTML from console contents (requires record=True argument in constructor).
theme (TerminalTheme, optional) – TerminalTheme object containing console colors.
clear (bool, optional) – Clear record buffer after exporting. Defaults to True
.
code_format (str, optional) – Format string to render HTML. In addition to ‘{foreground}’, ‘{background}’, and ‘{code}’, should contain ‘{stylesheet}’ if inline_styles is False
.
inline_styles (bool, optional) – If True
styles will be inlined in to spans, which makes files larger but easier to cut and paste markup. If False
, styles will be embedded in a style tag. Defaults to False.
String containing console contents as HTML.
Generate an SVG from the console contents (requires record=True in Console constructor).
title (str, optional) – The title of the tab in the output image
theme (TerminalTheme, optional) – The TerminalTheme
object to use to style the terminal
clear (bool, optional) – Clear record buffer after exporting. Defaults to True
code_format (str, optional) – Format string used to generate the SVG. Rich will inject a number of variables into the string in order to form the final SVG output. The default template used and the variables injected by Rich can be found by inspecting the console.CONSOLE_SVG_FORMAT
variable.
font_aspect_ratio (float, optional) – The width to height ratio of the font used in the code_format
string. Defaults to 0.61, which is the width to height ratio of Fira Code (the default font). If you aren’t specifying a different font inside code_format
, you probably don’t need this.
unique_id (str, optional) – unique id that is used as the prefix for various elements (CSS styles, node ids). If not set, this defaults to a computed value based on the recorded content.
Generate text from console contents (requires record=True argument in constructor).
Get the file object to write to.
Get a Style instance by its theme name or parse a definition.
Get the height of the console.
The height (in lines) of the console.
Displays a prompt and waits for input from the user. The prompt may contain color / style.
It works in the same way as Python’s builtin input()
function and provides elaborate line editing and history features if Python’s builtin readline
module is previously loaded.
markup (bool, optional) – Enable console markup (requires a str prompt). Defaults to True.
emoji (bool, optional) – Enable emoji (requires a str prompt). Defaults to True.
password (bool) – (bool, optional): Hide typed text. Defaults to False.
stream (TextIO | None) – (TextIO, optional): Optional file to read input from (rather than stdin). Defaults to None.
Text read from stdin.
Check if the alt screen was enabled.
True if the alt screen was enabled, otherwise False.
Detect dumb terminal.
True if writing to a dumb terminal, otherwise False.
Check if the console is writing to a terminal.
understanding escape sequences, otherwise False.
Write new line(s).
count (int, optional) – Number of new lines. Defaults to 1.
None
Log rich content to the terminal.
objects (positional args) – Objects to log to the terminal.
sep (str, optional) – String to write between print data. Defaults to “ “.
end (str, optional) – String to write at end of print data. Defaults to “\n”.
style (Union[str, Style], optional) – A style to apply to output. Defaults to None.
justify (str, optional) – One of “left”, “right”, “center”, or “full”. Defaults to None
.
emoji (Optional[bool], optional) – Enable emoji code, or None
to use console default. Defaults to None.
markup (Optional[bool], optional) – Enable markup, or None
to use console default. Defaults to None.
highlight (Optional[bool], optional) – Enable automatic highlighting, or None
to use console default. Defaults to None.
log_locals (bool, optional) – Boolean to enable logging of locals where log()
was called. Defaults to False.
_stack_offset (int, optional) – Offset of caller from end of call stack. Defaults to 1.
None
Measure a renderable. Returns a Measurement
object which contains information regarding the number of characters required to print the renderable.
renderable (RenderableType) – Any renderable or string.
options (Optional[ConsoleOptions], optional) – Options to use when measuring, or None to use default options. Defaults to None.
A measurement of the renderable.
This function is called when a BrokenPipeError is raised.
This can occur when piping Textual output in Linux and macOS. The default implementation is to exit the app, but you could implement this method in a subclass to change the behavior.
See https://docs.python.org/3/library/signal.html#note-on-sigpipe for details.
None
Get default console options.
Output to the terminal. This is a low-level way of writing to the terminal which unlike print()
won’t pretty print, wrap text, or apply markup, but will optionally apply highlighting and a basic style.
sep (str, optional) – String to write between print data. Defaults to “ “.
end (str, optional) – String to write at end of print data. Defaults to “\n”.
style (Union[str, Style], optional) – A style to apply to output. Defaults to None.
highlight (Optional[bool], optional) – Enable automatic highlighting, or None
to use console default. Defaults to None
.
objects (Any)
None
A context manager to display anything printed within a “pager”. The pager application is defined by the system and will typically support at least pressing a key to scroll.
Example
>>> from rich.console import Console >>> from rich.__main__ import make_test_card >>> console = Console() >>> with console.pager(): console.print(make_test_card())
A context manager.
Pop the last renderhook from the stack.
None
Remove theme from top of stack, restoring previous theme.
None
Print to the console.
objects (positional args) – Objects to log to the terminal.
sep (str, optional) – String to write between print data. Defaults to “ “.
end (str, optional) – String to write at end of print data. Defaults to “\n”.
style (Union[str, Style], optional) – A style to apply to output. Defaults to None.
justify (str, optional) – Justify method: “default”, “left”, “right”, “center”, or “full”. Defaults to None
.
overflow (str, optional) – Overflow method: “ignore”, “crop”, “fold”, or “ellipsis”. Defaults to None.
no_wrap (Optional[bool], optional) – Disable word wrapping. Defaults to None.
emoji (Optional[bool], optional) – Enable emoji code, or None
to use console default. Defaults to None
.
markup (Optional[bool], optional) – Enable markup, or None
to use console default. Defaults to None
.
highlight (Optional[bool], optional) – Enable automatic highlighting, or None
to use console default. Defaults to None
.
width (Optional[int], optional) – Width of output, or None
to auto-detect. Defaults to None
.
crop (Optional[bool], optional) – Crop output to width of terminal. Defaults to True.
soft_wrap (bool, optional) – Enable soft wrap mode which disables word wrapping and cropping of text or None
for Console default. Defaults to None
.
new_line_start (bool, False) – Insert a new line at the start if the output contains more than one line. Defaults to False
.
height (int | None)
None
Prints a rich render of the last exception and traceback.
width (Optional[int], optional) – Number of characters used to render code. Defaults to 100.
extra_lines (int, optional) – Additional lines of code to render. Defaults to 3.
theme (str, optional) – Override pygments theme used in traceback
word_wrap (bool, optional) – Enable word wrapping of long lines. Defaults to False.
show_locals (bool, optional) – Enable display of local variables. Defaults to False.
suppress (Iterable[Union[str, ModuleType]]) – Optional sequence of modules or paths to exclude from traceback.
max_frames (int) – Maximum number of frames to show in a traceback, 0 for no maximum. Defaults to 100.
None
Pretty prints JSON. Output will be valid JSON.
json (Optional[str]) – A string containing JSON.
data (Any) – If json is not supplied, then encode this data.
indent (Union[None, int, str], optional) – Number of spaces to indent. Defaults to 2.
highlight (bool, optional) – Enable highlighting of output: Defaults to True.
skip_keys (bool, optional) – Skip keys not of a basic type. Defaults to False.
ensure_ascii (bool, optional) – Escape all non-ascii characters. Defaults to False.
check_circular (bool, optional) – Check for circular references. Defaults to True.
allow_nan (bool, optional) – Allow NaN and Infinity values. Defaults to True.
default (Callable, optional) – A callable that converts values that can not be encoded in to something that can be JSON encoded. Defaults to None.
sort_keys (bool, optional) – Sort dictionary keys. Defaults to False.
None
Add a new render hook to the stack.
hook (RenderHook) – Render hook instance.
None
Push a new theme on to the top of the stack, replacing the styles from the previous theme. Generally speaking, you should call use_theme()
to get a context manager, rather than calling this method directly.
Render an object in to an iterable of Segment instances.
This method contains the logic for rendering objects with the console protocol. You are unlikely to need to use it directly, unless you are extending the library.
renderable (RenderableType) – An object supporting the console protocol, or an object that may be converted to a string.
options (ConsoleOptions, optional) – An options object, or None to use self.options. Defaults to None.
An iterable of segments that may be rendered.
Iterable[Segment]
Render objects in to a list of lines.
The output of render_lines is useful when further formatting of rendered console text is required, such as the Panel class which draws a border around any renderable object.
- Args:
renderable (RenderableType): Any object renderable in the console. options (Optional[ConsoleOptions], optional): Console options, or None to use self.options. Default to
None
. style (Style, optional): Optional style to apply to renderables. Defaults toNone
. pad (bool, optional): Pad lines shorter than render width. Defaults toTrue
. new_lines (bool, optional): Include “
“ characters at end of lines.
- Returns:
List[List[Segment]]: A list of lines, where a line is a list of Segment objects.
renderable (ConsoleRenderable | RichCast | str)
options (ConsoleOptions | None)
style (Style | None)
pad (bool)
new_lines (bool)
Convert a string to a Text instance. This is called automatically if you print or log a string.
text (str) – Text to render.
style (Union[str, Style], optional) – Style to apply to rendered text.
justify (str, optional) – Justify method: “default”, “left”, “center”, “full”, or “right”. Defaults to None
.
overflow (str, optional) – Overflow method: “crop”, “fold”, or “ellipsis”. Defaults to None
.
emoji (Optional[bool], optional) – Enable emoji, or None
to use Console default.
markup (Optional[bool], optional) – Enable markup, or None
to use Console default.
highlight (Optional[bool], optional) – Enable highlighting, or None
to use Console default.
highlighter (HighlighterType, optional) – Optional highlighter to apply.
Renderable object.
Draw a line with optional centered title.
title (str, optional) – Text to render over the rule. Defaults to “”.
characters (str, optional) – Character(s) to form the line. Defaults to “─”.
style (str, optional) – Style of line. Defaults to “rule.line”.
align (str, optional) – How to align the title, one of “left”, “center”, or “right”. Defaults to “center”.
None
Generate HTML from console contents and write to a file (requires record=True argument in constructor).
path (str) – Path to write html file.
theme (TerminalTheme, optional) – TerminalTheme object containing console colors.
clear (bool, optional) – Clear record buffer after exporting. Defaults to True
.
code_format (str, optional) – Format string to render HTML. In addition to ‘{foreground}’, ‘{background}’, and ‘{code}’, should contain ‘{stylesheet}’ if inline_styles is False
.
inline_styles (bool, optional) – If True
styles will be inlined in to spans, which makes files larger but easier to cut and paste markup. If False
, styles will be embedded in a style tag. Defaults to False.
None
Generate an SVG file from the console contents (requires record=True in Console constructor).
path (str) – The path to write the SVG to.
title (str, optional) – The title of the tab in the output image
theme (TerminalTheme, optional) – The TerminalTheme
object to use to style the terminal
clear (bool, optional) – Clear record buffer after exporting. Defaults to True
code_format (str, optional) – Format string used to generate the SVG. Rich will inject a number of variables into the string in order to form the final SVG output. The default template used and the variables injected by Rich can be found by inspecting the console.CONSOLE_SVG_FORMAT
variable.
font_aspect_ratio (float, optional) – The width to height ratio of the font used in the code_format
string. Defaults to 0.61, which is the width to height ratio of Fira Code (the default font). If you aren’t specifying a different font inside code_format
, you probably don’t need this.
unique_id (str, optional) – unique id that is used as the prefix for various elements (CSS styles, node ids). If not set, this defaults to a computed value based on the recorded content.
None
Generate text from console and save to a given location (requires record=True argument in constructor).
Context manager to enable and disable ‘alternative screen’ mode.
Enables alternative screen mode.
Note, if you enable this mode, you should ensure that is disabled before the application exits. See screen()
for a context manager that handles this for you.
Set Live instance. Used by Live context manager.
live (Live) – Live instance using this Console.
errors.LiveError – If this Console has a Live context currently active.
None
Set the title of the console terminal window.
Warning: There is no means within Rich of “resetting” the window title to its previous value, meaning the title you set will persist even after your application exits.
fish
shell resets the window title before and after each command by default, negating this issue. Windows Terminal and command prompt will also reset the title for you. Most other shells and terminals, however, do not do this.
Some terminals may require configuration changes before you can set the title. Some terminals may not support setting the title at all.
Other software (including the terminal itself, the shell, custom prompts, plugins, etc.) may also set the terminal window title. This could result in whatever value you write using this method being overwritten.
title (str) – The new title of the terminal window.
written, otherwise False. Note that a return value of True does not guarantee that the window title has actually changed, since the feature may be unsupported/disabled in some terminals.
Show or hide the cursor.
Get the size of the console.
A named tuple containing the dimensions.
Display a status and spinner.
status (RenderableType) – A status renderable (str or Text typically).
spinner (str, optional) – Name of spinner animation (see python -m rich.spinner). Defaults to “dots”.
spinner_style (StyleType, optional) – Style of spinner. Defaults to “status.spinner”.
speed (float, optional) – Speed factor for spinner animation. Defaults to 1.0.
refresh_per_second (float, optional) – Number of refreshes per second. Defaults to 12.5.
A Status object that may be used as a context manager.
Update the screen at a given offset.
renderable (RenderableType) – A Rich renderable.
region (Region, optional) – Region of screen to update, or None for entire screen. Defaults to None.
x (int, optional) – x offset. Defaults to 0.
y (int, optional) – y offset. Defaults to 0.
options (ConsoleOptions | None)
errors.NoAltScreen – If the Console isn’t in alt screen mode.
None
Update lines of the screen at a given offset.
Use a different theme for the duration of the context manager.
[description]
Get the width of the console.
The width (in characters) of the console.
Size of the terminal.
The height of the console in lines.
The width of the console in ‘cells’.
Options for __rich_console__ method.
size (ConsoleDimensions)
legacy_windows (bool)
min_width (int)
max_width (int)
is_terminal (bool)
encoding (str)
max_height (int)
justify (Literal['default', 'left', 'center', 'right', 'full'] | None)
overflow (Literal['fold', 'crop', 'ellipsis', 'ignore'] | None)
no_wrap (bool | None)
highlight (bool | None)
markup (bool | None)
height (int | None)
Check if renderables should use ascii only.
Return a copy of the options.
a copy of self.
Encoding of terminal.
Highlight override for render_str.
True if the target is a terminal, otherwise False.
Justify value override for renderable.
flag for legacy windows.
legacy_windows
Enable markup when rendering strings.
Height of container (starts as terminal)
Maximum width of renderable.
Minimum width of renderable.
Disable wrapping for text.
Overflow value override for renderable.
Return a copy of the options with height set to None
.
New console options instance.
~ConsoleOptions
Size of console.
Update values, return a copy.
width (int | NoChange)
min_width (int | NoChange)
max_width (int | NoChange)
justify (Literal['default', 'left', 'center', 'right', 'full'] | None | ~rich.console.NoChange)
overflow (Literal['fold', 'crop', 'ellipsis', 'ignore'] | None | ~rich.console.NoChange)
no_wrap (bool | None | NoChange)
highlight (bool | None | NoChange)
markup (bool | None | NoChange)
height (int | None | NoChange)
Update the width and height, and return a copy.
Update the height, and return a copy.
height (int) – New height
New Console options instance.
~ConsoleOptions
Update just the width, return a copy.
width (int) – New width (sets both min_width and max_width)
New console options instance.
~ConsoleOptions
An object that supports the console protocol.
Thread local values for Console context.
Takes a group of renderables and returns a renderable object that renders the group.
renderables (Iterable[RenderableType]) – An iterable of renderable objects.
fit (bool, optional) – Fit dimension of group to contents, or fill available space. Defaults to True.
A renderable to generate new line(s)
count (int)
A context manager that ‘pages’ content. See pager()
for usage.
Provides hooks in to the render process.
Called with a list of objects to render.
This method can return a new list of renderables, or modify and return the same list.
renderables (List[ConsoleRenderable]) – A number of renderable objects.
A replacement list of renderables.
List[ConsoleRenderable]
A string or any object that may be rendered by Rich.
alias of ConsoleRenderable
| RichCast
| str
An object that may be ‘cast’ to a console renderable.
A context manager that enables an alternative screen. See screen()
for usage.
Update the screen.
renderable (RenderableType, optional) – Optional renderable to replace current renderable, or None for no change. Defaults to None.
style (str | Style | None) – (Style, optional): Replacement style, or None for no change. Defaults to None.
renderables (ConsoleRenderable | RichCast | str)
None
Render a list of lines at a given offset.
A context manager to use a temporary theme. See use_theme()
for usage.
Detect legacy Windows.
A decorator that turns an iterable of renderables in to a group.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4