py_trees_ros_viewer.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:
from . import console
print(console.cyan + " Name" + console.reset + ": " + console.yellow + "Dude" + console.reset)
- class py_trees_ros_viewer.console.LogLevel(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)
Bases:
Enum
Log levels.
- DEBUG = 1
- ERROR = 4
- INFO = 2
- WARNING = 3
- py_trees_ros_viewer.console.banner(msg)
- py_trees_ros_viewer.console.colours = ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '']
List of all available colours.
- py_trees_ros_viewer.console.console_has_colours()
Detects if the console (stdout) has colourising capability.
- py_trees_ros_viewer.console.debug(msg)
- py_trees_ros_viewer.console.define_symbol_or_fallback(original: str, fallback: str, encoding: str = 'utf-8')
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 (
str
): the unicode string (usually just a character) fallback (str
): the fallback ascii string encoding (str
, optional): the encoding to check against.- Returns:
str
: either original or fallback depending on whether exceptions were thrown.
- py_trees_ros_viewer.console.error(msg)
- py_trees_ros_viewer.console.has_colours = False
Whether the loading program has access to colours or not.
- py_trees_ros_viewer.console.has_unicode(encoding: str = 'utf-8') bool
Define whether the specified encoding has unicode symbols. Usually used to check if the stdout is capable or otherwise (e.g. Jenkins CI can often be configured with unicode disabled).
- Args:
encoding (
str
, optional): the encoding to check against.- Returns:
bool
: true if capable, false otherwise
- py_trees_ros_viewer.console.info(msg)
- py_trees_ros_viewer.console.log_level = LogLevel.INFO
Console’s current log level.
- py_trees_ros_viewer.console.logdebug(message)
Prefixes
[DEBUG]
and colours the message green.- Args:
message (
str
): message to log.
- py_trees_ros_viewer.console.logerror(message)
Prefixes
[ERROR]
and colours the message red.- Args:
message (
str
): message to log.
- py_trees_ros_viewer.console.logfatal(message)
Prefixes
[FATAL]
and colours the message bold red.- Args:
message (
str
): message to log.
- py_trees_ros_viewer.console.loginfo(message)
Prefixes
[ INFO]
to the message.- Args:
message (
str
): message to log.
- py_trees_ros_viewer.console.logwarn(message)
Prefixes
[ WARN]
and colours the message yellow.- Args:
message (
str
): message to log.
- py_trees_ros_viewer.console.pretty_print(msg, colour='')
- py_trees_ros_viewer.console.pretty_println(msg, colour='')
- py_trees_ros_viewer.console.read_single_keypress()
Waits 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:
int
: the character of the key that was pressed- Raises:
KeyboardInterrupt: if CTRL-C was pressed (keycode 0x03)
- py_trees_ros_viewer.console.warning(msg)