Skip to content

Richclient

CLITheme

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

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.

Parameters:

Name Type Description Default
module_name Optional[str]

name of the module that is calling this method

None
logger_name Optional[str]

name of the logger, typically name of the module.

None
logger_level Optional[int]

if not given, fetched from config.

None
verbose bool

verbose option set in bin/rucio

False
console Optional[Console]

Rich console object

None

Returns:

Type Description
Logger

logger with RichHandler

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.

Parameters:

Name Type Description Default
table_format Box

style of the table

TABLE_FMT
headers Optional[Sequence[RenderableType]]

list of headers

None
rows Sequence[Sequence[Union[RenderableType, int, float, bool, datetime]]]

list of rows

required
col_alignments Optional[list[JustifyMethod]]

list of column alignments

None
row_styles Optional[Sequence[StyleType]]

list of row styles

None

Returns:

Type Description
Table

a Rich Table object

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.

Parameters:

Name Type Description Default
output Any

objects to print to the terminal

()
console Console

Rich console object

required
no_pager bool

flag to disable the pager

False

get_cli_config()

Returns the CLI type from the config file.

Returns:

Type Description
str

CLI type (Rich or tabulate)

get_pager()

Returns the pager function based on the terminal availability.

Returns:

Type Description
Callable[[str], None]

pager