pyopmnearwell.utils.terminal module#

Format command-line messages for pyopmnearwell.

ANSI colors are applied when supported by the selected stream. The module provides consistent formatting for invalid, accepted, deprecated, and informational values, plus fatal errors, warnings, tips, progress messages, and generated-file reports.

_supports_color(stream=<_io.TextIOWrapper name='<stderr>' mode='w' encoding='utf-8'>)[source]#

Check whether an output stream supports ANSI colors.

Parameters:

stream (object, optional) -- Output stream used to determine ANSI-color support.

Returns:

Whether ANSI color output is enabled for the stream.

Return type:

bool

_colorize(text, code, stream=<_io.TextIOWrapper name='<stderr>' mode='w' encoding='utf-8'>)[source]#

Wrap text in an ANSI color sequence when supported.

Parameters:
  • text (str) -- Text to format.

  • code (str) -- ANSI Select Graphic Rendition code.

  • stream (object, optional) -- Output stream used to determine ANSI-color support.

Returns:

Colored text, or unchanged text when colors are disabled.

Return type:

str

cli_warning_value(value)[source]#

Format a deprecated CLI option or value.

Parameters:

value (str) -- Value to inspect or format.

Returns:

Quoted value colored as a warning when supported.

Return type:

str

cli_correct_value(value)[source]#

Format a correct CLI option or value.

Parameters:

value (str) -- Value to inspect or format.

Returns:

Quoted value colored as a valid alternative when supported.

Return type:

str

cli_error_value(value)[source]#

Format an invalid CLI option or value.

Parameters:

value (str) -- Value to inspect or format.

Returns:

Quoted value colored as invalid when supported.

Return type:

str

cli_info_value(value)[source]#

Format an informational CLI option or value.

Parameters:

value (str) -- Value to inspect or format.

Returns:

Quoted value colored as information when supported.

Return type:

str

pyopmnearwell_error(message)[source]#

Raise a fatal command-line error.

Parameters:

message (str) -- Human-readable message to display or append.

Raises:

SystemExit -- Always raised with the formatted error message.

Return type:

NoReturn

pyopmnearwell_warning(message)[source]#

Display a non-fatal command-line warning.

Parameters:

message (str) -- Human-readable message to display or append.

Return type:

None

pyopmnearwell_info(message)[source]#

Display an informational command-line message.

Parameters:

message (str) -- Human-readable message to display or append.

Return type:

None

pyopmnearwell_tip(message)[source]#

Display a command-line suggestion.

Parameters:

message (str) -- Human-readable message to display or append.

Return type:

None

pyopmnearwell_success(msg, output_dir, filenames)[source]#

Display the generated output location and filenames.

Parameters:
  • msg (str) -- Optional success text printed before the output location.

  • output_dir (str) -- Directory containing the generated files.

  • filenames (list[str]) -- Generated filenames to report.

Return type:

None

pyopmnearwell_name(stream=<_io.TextIOWrapper name='<stderr>' mode='w' encoding='utf-8'>)[source]#

Format the pyopmnearwell program name.

Parameters:

stream (object, optional) -- Output stream used to determine ANSI-color support.

Returns:

Formatted program name.

Return type:

str