hermes.commands.init.util.slim_click

Slim, self-made and partial implementation of some click functionality, so we don’t need to add another large dependency for simple console questions and outputs.

Attributes

PRINT_DEBUG

If true, echo() will print debug texts.

AUTO_LOG_ON_ECHO

If true, echo() will add lines to the log file based on Formats.get_log_type.

USE_FANCY_HYPERLINKS

If true, links will be hidden in the console. Not all consoles support this however.

max_steps

Set this to have a upper limit for the step-headlines created by next_step()

current_steps

The number if the last printed step

default_file_logger

The file logger used by echo if AUTO_LOG_ON_ECHO

Classes

Formats

Create a collection of name/value pairs.

ColorLogHandler

Handler instances dispatch logging events to specific destinations.

ColorLogFormatter

Own version of a terminal log formatter to print our log messages with color.

Functions

echo([text, formatting, log_as, no_log])

Prints the text with the given formatting. If log_as is set or AUTO_LOG_ON_ECHO is true it gets logged as well.

debug_info(*args, **kwargs)

confirm(→ bool)

The user gets to decide between yes (y) and no (n). The answer will be returned as bool.

answer(→ str)

Returns the user's response to the given text. It is just a wrapper for input().

press_enter_to_continue(→ None)

choose(→ int)

The user gets to make a choice between predefined answers.

headline(text)

Prints a big headline onto the console

next_step(description)

Keeps track of named steps by printing matching headlines. Make sure to set max_steps beforehand

create_console_hyperlink(→ str)

Use this to have a consistent display of hyperlinks.

Module Contents

hermes.commands.init.util.slim_click.PRINT_DEBUG = False

If true, echo() will print debug texts.

hermes.commands.init.util.slim_click.AUTO_LOG_ON_ECHO = True

If true, echo() will add lines to the log file based on Formats.get_log_type. Otherwise use the log_as parameter of the echo() command.

If true, links will be hidden in the console. Not all consoles support this however.

hermes.commands.init.util.slim_click.max_steps = 0

Set this to have a upper limit for the step-headlines created by next_step()

hermes.commands.init.util.slim_click.current_steps = 0

The number if the last printed step

hermes.commands.init.util.slim_click.default_file_logger: logging.Logger = None

The file logger used by echo if AUTO_LOG_ON_ECHO

class hermes.commands.init.util.slim_click.Formats(*args, **kwds)

Bases: enum.Enum

Create a collection of name/value pairs.

Example enumeration:

>>> class Color(Enum):
...     RED = 1
...     BLUE = 2
...     GREEN = 3

Access them by:

  • attribute access:

    >>> Color.RED
    <Color.RED: 1>
    
  • value lookup:

    >>> Color(1)
    <Color.RED: 1>
    
  • name lookup:

    >>> Color['RED']
    <Color.RED: 1>
    

Enumerations can be iterated over, and know how many members they have:

>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.

HEADER = '\x1b[95m'
OKBLUE = '\x1b[94m'
OKCYAN = '\x1b[96m'
OKGREEN = '\x1b[92m'
WARNING = '\x1b[93m'
FAIL = '\x1b[91m'
ENDC = '\x1b[0m'
BOLD = '\x1b[1m'
ITALIC = '\x1b[3m'
UNDERLINE = '\x1b[4m'
EMPTY = ''
__add__(other)
get_ansi() str
get_log_type(default: int = logging.INFO) int
wrap_around(text: str) str
hermes.commands.init.util.slim_click.echo(text: str = '', formatting: Formats = Formats.EMPTY, log_as: int = logging.NOTSET, no_log: bool = False)

Prints the text with the given formatting. If log_as is set or AUTO_LOG_ON_ECHO is true it gets logged as well. :param text: The printed text. :param formatting: You can use the Formats Enum to give the text a special color or formatting. :param log_as: Creates a log entry with the given text if this is set. :param no_log: Never creates a log entry if True.

hermes.commands.init.util.slim_click.debug_info(*args, **kwargs)
hermes.commands.init.util.slim_click.confirm(text: str, default: bool = True) bool

The user gets to decide between yes (y) and no (n). The answer will be returned as bool.

hermes.commands.init.util.slim_click.answer(text: str) str

Returns the user’s response to the given text. It is just a wrapper for input().

hermes.commands.init.util.slim_click.press_enter_to_continue(text: str = 'Press ENTER to continue') None
hermes.commands.init.util.slim_click.choose(text: str, options: list[str], default: int = 0) int

The user gets to make a choice between predefined answers.

Parameters:
  • text – Displayed text / question

  • options – List with possible answers

  • default – Selected answer (index) if the user doesn’t enter anything

Returns:

The index of the selected option

hermes.commands.init.util.slim_click.headline(text: str)

Prints a big headline onto the console

hermes.commands.init.util.slim_click.next_step(description: str)

Keeps track of named steps by printing matching headlines. Make sure to set max_steps beforehand

Use this to have a consistent display of hyperlinks.

class hermes.commands.init.util.slim_click.ColorLogHandler

Bases: logging.Handler

Handler instances dispatch logging events to specific destinations.

The base handler class. Acts as a placeholder which defines the Handler interface. Handlers can optionally use Formatter instances to format records as desired. By default, no formatter is specified; in this case, the ‘raw’ message as determined by record.message is logged.

formatter
emit(record)

Do whatever it takes to actually log the specified logging record.

This version is intended to be implemented by subclasses and so raises a NotImplementedError.

class hermes.commands.init.util.slim_click.ColorLogFormatter(_formats=None)

Bases: logging.Formatter

Own version of a terminal log formatter to print our log messages with color.

formats
format(record)

Format the specified record as text.

The record’s attribute dictionary is used as the operand to a string formatting operation which yields the returned string. Before formatting the dictionary, a couple of preparatory steps are carried out. The message attribute of the record is computed using LogRecord.getMessage(). If the formatting string uses the time (as determined by a call to usesTime(), formatTime() is called to format the event time. If there is exception information, it is formatted using formatException() and appended to the message.

static _default_format()