Skip to content

Richclient

Classes

CLITheme

Class to define styles for Rich widgets and prints in the CLI.

Functions

setup_rich_logger

setup_rich_logger(
    module_name=None,
    logger_name=None,
    logger_level=None,
    verbose=False,
    console=None,
)

Factory method to set logger with RichHandler.

The function is a copy of the method in rucio.common.utils setup_logger() with minor changes.

PARAMETER DESCRIPTION
module_name

name of the module that is calling this method

TYPE: Optional[str] DEFAULT: None

logger_name

name of the logger, typically name of the module.

TYPE: Optional[str] DEFAULT: None

logger_level

if not given, fetched from config.

TYPE: Optional[int] DEFAULT: None

verbose

verbose option set in bin/rucio

TYPE: bool DEFAULT: False

console

Rich console object

TYPE: Optional[Console] DEFAULT: None

RETURNS DESCRIPTION
Logger

logger with RichHandler

generate_table

generate_table(
    rows,
    headers=None,
    row_styles=None,
    col_alignments=None,
    table_format=CLITheme.TABLE_FMT,
)

Generates a Rich Table object from given input rows.

The elements in each row can be either plain strings or Rich renderable objects. Passing strings will display them as simple text, while using Rich objects allows you to introduce additional structure, styling, and widgets (e.g. Text, Trees) into the table. Strings with style markup will be rendered as styled text.

PARAMETER DESCRIPTION
table_format

style of the table

TYPE: Box DEFAULT: TABLE_FMT

headers

list of headers

TYPE: Optional[Sequence[RenderableType]] DEFAULT: None

rows

list of rows

TYPE: Sequence[Sequence[Union[RenderableType, int, float, bool, datetime]]]

col_alignments

list of column alignments

TYPE: Optional[list[JustifyMethod]] DEFAULT: None

row_styles

list of row styles

TYPE: Optional[Sequence[StyleType]] DEFAULT: None

RETURNS DESCRIPTION
Table

a Rich Table object

print_output

print_output(*output, console, no_pager=False)

Prints the objects using the specified Rich console object. Optionally disables the pager if specified.

The function works similarly to Rich's console.print() method but provides additional control over the pager feature.

PARAMETER DESCRIPTION
output

objects to print to the terminal

TYPE: Any DEFAULT: ()

console

Rich console object

TYPE: Console

no_pager

flag to disable the pager

TYPE: bool DEFAULT: False

get_cli_config

get_cli_config()

Returns the CLI type from the config file.

RETURNS DESCRIPTION
str

CLI type (Rich or tabulate)

get_pager

get_pager()

Returns the pager function based on the terminal availability.

RETURNS DESCRIPTION
Callable[[str], None]

pager