rich_utils.py#

Utilities for using rich with OpenMDAO.

openmdao.utils.rich_utils.rich_wrap(s, tags=None)[source]

If rich is available, escape square brackets and wrap the given string in the provided tags.

If rich is not available or the user has set the environment variable OPENMDAO_DISABLE_RICH to a “truthy” value, just return the string.

Parameters:
sstr

The string to be wrapped in rich tags.

tagsSequence[str] or set[str], optional

The rich tags to be wrapped around s. These can either be strings.

Returns:
str

The given string wrapped in the provided rich tags.

openmdao.utils.rich_utils.strip_formatting(s)[source]

Remove formatting applied to a string by rich.

This method is useful when testing the content of rich-formatted output.

Parameters:
sstr

The string to have its rich formatting removed.

Returns:
str

String s with any ascii formatting sequences removed.

openmdao.utils.rich_utils.strip_tags(s)[source]

Remove non-escaped tags from a string.

This method is useful for determining lengths of rich-formatted text.

Parameters:
sstr

The string to have its rich formatting removed.

Returns:
str

String s with any rich tags removed.

openmdao.utils.rich_utils.use_rich()[source]

Determine if rich should be used for formatting output.

This is determined by whether or not rich is available, and by whether or not the OPENMDAO_DISABLE_RICH environment variable is set with a “truthy” value.

Returns:
bool

True if rich should be used for output, otherwise False.