Skip to content

rich_click.rich_help_formatter

Attributes

NameDescription
RPNo description.

Classes

NameDescription
RichHelpFormatterRich Help Formatter.

Functions

NameDescription
create_consoleCreate a Rich console from a help configuration.

RPattributemodule attribute#

RP = TypeVar('RP', bound=RichPanel[Any, Any])

RichHelpFormatterclass#

class RichHelpFormatter(indent_increment: int = 2, width: int | None = None, max_width: int | None = None, *args: Any, console: Console | None = None, config: RichHelpConfiguration | None = None, export_console_as: Literal[None, 'html', 'svg', 'text'] = None, export_kwargs: dict[str, Any] | None = None, **kwargs: Any)

Bases: click.HelpFormatter

Rich Help Formatter.

This class is a container for the help configuration and Rich Console that are used internally by the help and error printing methods.

Create Rich Help Formatter.

Parameters

NameTypeDefaultDescription
indent_incrementint2Passed to click.HelpFormatter.
widthint | NoneNonePassed to click.HelpFormatter. Overrides config.width if not None.
max_widthint | NoneNonePassed to click.HelpFormatter. Overrides config.max_width if not None.
*argsAny()Args passed to click.HelpFormatter.
consoleConsole | NoneNoneUse an external console.
configRichHelpConfiguration | NoneNoneRichHelpConfiguration. If None, then build config from globals.
export_console_asLiteral[None, 'html', 'svg', 'text']NoneHow output is rendered by getvalue(). Default of None renders output normally.
export_kwargsdict[str, Any] | NoneNoneAny kwargs passed to the export method of the Console in getvalue().
**kwargsAny{}Kwargs passed to click.HelpFormatter.

command_panel_classattributeclass attributeinstance attribute#

command_panel_class: type[RichCommandPanel] = RichCommandPanel

configattributeinstance attribute#

config = config

consoleattributeinstance attribute#

console: Console

Rich Console created from the help configuration.

This console is meant only for use with the formatter and should not be created directly

export_console_asattributeclass attributeinstance attribute#

export_console_as: Literal[None, 'html', 'svg', 'text'] = export_console_as

export_kwargsattributeinstance attribute#

export_kwargs = export_kwargs or {}

option_panel_classattributeclass attributeinstance attribute#

option_panel_class: type[RichOptionPanel] = RichOptionPanel

highlighterpropertycached#

highlighter: Highlighter

widthpropertywritable#

width: int

dedentmethod#

def dedent() -> None

getvaluemethod#

def getvalue() -> str

indentmethod#

def indent() -> None

indentationmethod#

def indentation() -> Iterator[None]

rich_textmethod#

def rich_text(text: str | Text | Markdown, style: StyleType = '') -> Text | Markdown | RichClickRST

Take a string, remove indentations, and return styled text. By default, return the text as a Rich Text with the request style.

This method uses the config options prefixed text_ to influence how rendering works.

Parameters

NameTypeDefaultDescription
textstr | Text | MarkdownrequiredText to style.
styleStyleType''Rich style to apply.

Returns

Text | Markdown | RichClickRST
Text, Markdown, or RichClickRST: Styled text object

sectionmethod#

def section(name: str) -> Iterator[None]

writemethod#

def write(*objects: Any, **kwargs: Any) -> None

write_abortmethod#

def write_abort() -> None

Print richly formatted abort error.

write_dlmethod#

def write_dl(rows: Iterable[tuple[str, str]], col_max: int = 30, col_spacing: int = 2) -> None

write_errormethod#

def write_error(e: click.ClickException) -> None

write_headingmethod#

def write_heading(heading: str) -> None

write_paragraphmethod#

def write_paragraph() -> None

write_textmethod#

def write_text(text: str) -> None

write_usagemethod#

def write_usage(prog: str, args: str = '', prefix: str | None = None) -> None

create_consolefunction#

def create_console(config: RichHelpConfiguration, file: IO[str] | None = None, width: int | None = None, max_width: int | None = None) -> Console

Create a Rich console from a help configuration.

Parameters

NameTypeDefaultDescription
configRichHelpConfigurationrequiredHelp configuration to take the console settings from.
fileIO[str] | NoneNoneStream to write to. If not set, the console records its output to an in-memory buffer.
widthint | NoneNoneWidth of the console. Overrides config.width.
max_widthint | NoneNoneMaximum width of the console. Overrides config.max_width.

Returns

Console
The new console.