Module colorprint

flush_service()

Clears up the “sticky” messages printed with the service function

Returns:

None

Return type:

None

See also

service

print temporary messages to screen

printerr(text, *args, **kwargs)

Prints a message to stderr, optionally using colors

Wraps the builtin print() with convenient options. If a log file is defined, it prints to the logfile too (see set_logfile).

Parameters:
  • text (str | any) – text to be printed. If not str, it is converted to str

  • end (str) – by default, a newline is added to each input text. Provide end=’’ to avoid it, or another character to use a different end of line character

  • how (str) – any number of comma-separated termcodes to markup your text, among: black blink blue bright cyan dim green hidden magenta red reverse underscore white yellow

  • keywords (dict) – use this to automatically highlight all occurrences of certain words. dictionary structured like word:termcode, so that all occurrences of word in text is marked with termcode(s) Note: using many keywords makes the function slower

Returns:

None

Return type:

None

service(text, **kwargs)

Print a temporary message to screen (stderr) meant to be flushed out and re-printed again modified, e.g. in a progress bar style.

Parameters:
  • text (str) – message to be printed

  • how (str) – termcodes for markup. See write()

Returns:

None

Return type:

None

set_logfile(fileh_or_path)

Sets a logfile where all messages printed with printed with write() or printerr() are also sent.

Parameters:

fileh_or_path (file | str) – file path specification or buffer of desired logfile

Returns:

None

Return type:

None

set_markup_keywords(kwords)

Set a syntax to always print certain words using a specific markup (when using write or printerr)

Parameters:

kwords (dict) – dictionary like key:termcode, where key is any string, and termcode any comma-separated combination of these: black blink blue bright cyan dim green hidden magenta red reverse underscore white yellow

Note

Using many keywords makes printing slower, so beware

Returns:

None

Return type:

None

set_markup_usage(setting)

Turns off or on the usage of colors and other terminal markup

Parameters:

setting (bool) – new setting, use False to turn off markup, True to turn back on

Returns:

None

Return type:

None

write(text, end='\n', how='', keywords={}, is_service=False, is_stderror=False)

Prints a message to stdout, optionally using colors

Wraps the builtin print() with convenient options. If a log file is defined, it prints to the logfile too (see set_logfile).

Parameters:
  • text (str | any) – text to be printed. If not str, it is converted to str

  • end (str) – by default, a newline is added to each input text. Provide end=’’ to avoid it, or another character to use a different end of line character

  • how (str) – any number of comma-separated termcodes to markup your text, among: black blink blue bright cyan dim green hidden magenta red reverse underscore white yellow

  • keywords (dict) – use this to automatically highlight all occurrences of certain words. dictionary structured like word:termcode, so that all occurrences of word in text is marked with termcode(s) Note: using many keywords makes the function slower

Returns:

None

Return type:

None