rich_click.rich_context
Classes
| Name | Description |
|---|---|
RichContext | The context of a rich-click command: a click Context that formats help and errors with Rich. |
RichContextMixin | Rich help formatting for a click Context, as a mixin with no click base class. |
Functions
| Name | Description |
|---|---|
get_current_context | Return the context of the command that runs now. |
RichContextclass#
class RichContext(RichContextMixin, click.Context)Bases: RichContextMixin, click.Context
The context of a rich-click command: a click Context that formats help and errors with Rich.
Inherited from rich_click.rich_context.RichContextMixin
consoleattributeclass attributeinstance attribute#
console: Console | None = Noneerrors_in_output_formatattributeclass attributeinstance attribute#
errors_in_output_format: bool = Falseexport_console_asattributeclass attributeinstance attribute#
export_console_as: Literal['html', 'svg', 'text'] | None = Noneformatter_classattributeclass attributeinstance attribute#
formatter_class: type[RichHelpFormatter] = RichHelpFormatterhelp_configattributeinstance attribute#
help_config = parent.help_confighelp_to_stderrattributeclass attributeinstance attribute#
help_to_stderr: bool = Falsemake_formattermethod#
def make_formatter(error_mode: bool = False) -> RichHelpFormatterCreate the Rich Help Formatter.
RichContextMixinclass#
class RichContextMixin(*args: Any, rich_console: Console | None = None, rich_help_config: Mapping[str, Any] | RichHelpConfiguration | None = None, export_console_as: Literal['html', 'svg', 'text'] | None = None, errors_in_output_format: bool | None = None, help_to_stderr: bool | None = None, **kwargs: Any)Bases: _ContextBase
Rich help formatting for a click Context, as a mixin with no click base class.
RichContext combines this mixin with click.Context. A click fork combines it
with its own Context class, such as asyncclick.Context. Because the mixin has
no click base class, it does not add click’s synchronous methods to the fork.
Create a context. An argument that is not set takes its value from the parent context.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
*args | Any | () | Positional arguments for the click Context. |
rich_console | Console | None | None | Rich console to print help and errors with. |
rich_help_config | Mapping[str, Any] | RichHelpConfiguration | None | None | How to format help and errors, as a RichHelpConfiguration or a dict of
its fields. A dict changes only the fields it names. |
export_console_as | Literal['html', 'svg', 'text'] | None | None | Export help as "html", "svg" or "text", not as terminal output. |
errors_in_output_format | bool | None | None | Export errors in the export_console_as format too. |
help_to_stderr | bool | None | None | Print help to stderr, not stdout. |
**kwargs | Any | {} | Keyword arguments for the click Context. |
consoleattributeclass attributeinstance attribute#
console: Console | None = Noneerrors_in_output_formatattributeclass attributeinstance attribute#
errors_in_output_format: bool = Falseexport_console_asattributeclass attributeinstance attribute#
export_console_as: Literal['html', 'svg', 'text'] | None = Noneformatter_classattributeclass attributeinstance attribute#
formatter_class: type[RichHelpFormatter] = RichHelpFormatterhelp_configattributeinstance attribute#
help_config = parent.help_confighelp_to_stderrattributeclass attributeinstance attribute#
help_to_stderr: bool = Falsemake_formattermethod#
def make_formatter(error_mode: bool = False) -> RichHelpFormatterCreate the Rich Help Formatter.
get_current_contextfunction#
def get_current_context(silent: bool = False) -> RichContext | NoneReturn the context of the command that runs now.
Use it in helper functions that need the context but do not get it from the pass_context decorator.
Parameters
Returns
RichContext | None- The context, or
Noneif no command runs andsilentis true.