pycopm.utils.terminal module#

Format command-line messages for pycopm.

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:
streamobject, optional

Output stream used to determine ANSI-color support.

Returns:
bool

Whether ANSI color output is enabled for the stream.

Parameters:

stream (object)

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:
textstr

Text to format.

codestr

ANSI Select Graphic Rendition code.

streamobject, optional

Output stream used to determine ANSI-color support.

Returns:
str

Colored text, or unchanged text when colors are disabled.

Parameters:
  • text (str)

  • code (str)

  • stream (object)

Return type:

str

cli_warning_value(value)[source]#

Format a deprecated CLI option or value.

Parameters:
valuestr

Value to inspect or format.

Returns:
str

Quoted value colored as a warning when supported.

Parameters:

value (str)

Return type:

str

cli_correct_value(value)[source]#

Format a correct CLI option or value.

Parameters:
valuestr

Value to inspect or format.

Returns:
str

Quoted value colored as a valid alternative when supported.

Parameters:

value (str)

Return type:

str

cli_error_value(value)[source]#

Format an invalid CLI option or value.

Parameters:
valuestr

Value to inspect or format.

Returns:
str

Quoted value colored as invalid when supported.

Parameters:

value (str)

Return type:

str

cli_info_value(value)[source]#

Format an informational CLI option or value.

Parameters:
valuestr

Value to inspect or format.

Returns:
str

Quoted value colored as information when supported.

Parameters:

value (str)

Return type:

str

pycopm_error(message)[source]#

Raise a fatal command-line error.

Parameters:
messagestr

Human-readable message to display or append.

Raises:
SystemExit

Always raised with the formatted error message.

Parameters:

message (str)

Return type:

NoReturn

pycopm_warning(message)[source]#

Display a non-fatal command-line warning.

Parameters:
messagestr

Human-readable message to display or append.

Parameters:

message (str)

Return type:

None

pycopm_info(message)[source]#

Display an informational command-line message.

Parameters:
messagestr

Human-readable message to display or append.

Parameters:

message (str)

Return type:

None

pycopm_tip(message)[source]#

Display a command-line suggestion.

Parameters:
messagestr

Human-readable message to display or append.

Parameters:

message (str)

Return type:

None

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

Display the generated output location and filenames.

Parameters:
msgstr

Optional success text printed before the output location.

output_dirstr

Directory containing the generated files.

filenameslist[str]

Generated filenames to report.

Parameters:
  • msg (str)

  • output_dir (str)

  • filenames (list[str])

Return type:

None

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

Format the pycopm program name.

Parameters:
streamobject, optional

Output stream used to determine ANSI-color support.

Returns:
str

Formatted program name.

Parameters:

stream (object)

Return type:

str