py_trees.console module

Simple colour definitions and syntax highlighting for the console.


Colour Definitions

The current list of colour definitions include:

  • Regular: black, red, green, yellow, blue, magenta, cyan, white,

  • Bold: bold, bold_black, bold_red, bold_green, bold_yellow, bold_blue, bold_magenta, bold_cyan, bold_white

These colour definitions can be used in the following way:

import py_trees.console as console
print(console.cyan + "    Name" + console.reset + ": " + console.yellow + "Dude" + console.reset)
py_trees.console.banner(msg: str) None

Print a banner with centred text to stdout.

Args:

msg: text to centre in the banner

py_trees.console.colours = ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '']

List of all available colours.

py_trees.console.console_has_colours() bool

Detect if the console (stdout) has colourising capability.

py_trees.console.debug(msg: str) None

Print a debug message.

Args:

str: message to print

py_trees.console.define_symbol_or_fallback(original: str, fallback: str, encoding: str = 'utf-8') str

Go unicode, or fallback to ascii.

Return the correct encoding according to the specified encoding. Used to make sure we get an appropriate symbol, even if the shell is merely ascii as is often the case on, e.g. Jenkins CI.

Args:

original: the unicode string (usually just a character) fallback: the fallback ascii string encoding: the encoding to check against.

Returns:

either original or fallback depending on whether exceptions were thrown.

py_trees.console.error(msg: str) None

Print an error message.

Args:

str: message to print

py_trees.console.has_colours = False

Whether the loading program has access to colours or not.

py_trees.console.has_unicode(encoding: str = 'utf-8') bool

Define whether the specified encoding has unicode symbols.

This is usually used to check if stdout is capable of unicode or otherwise (e.g. Jenkins CI is often be configured with unicode disabled).

Args:

encoding: the encoding to check against.

Returns:

true if capable, false otherwise

py_trees.console.info(msg: str) None

Print an info message.

Args:

str: message to print

py_trees.console.logdebug(message: str) None

Prefixes [DEBUG] and colours the message green.

Args:

message: message to log.

py_trees.console.logerror(message: str) None

Prefixes [ERROR] and colours the message red.

Args:

message: message to log.

py_trees.console.logfatal(message: str) None

Prefixes [FATAL] and colours the message bold red.

Args:

message: message to log.

py_trees.console.loginfo(message: str) None

Prefixes [ INFO] to the message.

Args:

message: message to log.

py_trees.console.logwarn(message: str) None

Prefixes [ WARN] and colours the message yellow.

Args:

message: message to log.

py_trees.console.pretty_print(msg: str, colour: str = '') None

Pretty print a coloured message.

Args:

msg: text to print colour: ascii colour to use

py_trees.console.pretty_println(msg: str, colour: str = '') None

Pretty print a coloured message with a newline.

Args:

msg: text to print colour: ascii colour to use

py_trees.console.read_single_keypress() str

Wait for a single keypress on stdin.

This is a silly function to call if you need to do it a lot because it has to store stdin’s current setup, setup stdin for reading single keystrokes then read the single keystroke then revert stdin back after reading the keystroke.

Returns:

the character of the key that was pressed

Raises:

KeyboardInterrupt: if CTRL-C was pressed (keycode 0x03)

py_trees.console.warning(msg: str) None

Print a warning message.

Args:

str: message to print