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
If true, echo() will print debug texts. |
|
If true, echo() will add lines to the log file based on Formats.get_log_type. |
|
If true, links will be hidden in the console. Not all consoles support this however. |
|
Set this to have a upper limit for the step-headlines created by next_step() |
|
The number if the last printed step |
|
The file logger used by echo if AUTO_LOG_ON_ECHO |
Classes
Create a collection of name/value pairs. |
|
Handler instances dispatch logging events to specific destinations. |
|
Own version of a terminal log formatter to print our log messages with color. |
Functions
|
Prints the text with the given formatting. If log_as is set or AUTO_LOG_ON_ECHO is true it gets logged as well. |
|
|
|
The user gets to decide between yes (y) and no (n). The answer will be returned as bool. |
|
Returns the user's response to the given text. It is just a wrapper for input(). |
|
|
|
The user gets to make a choice between predefined answers. |
|
Prints a big headline onto the console |
|
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. |
Module Contents
- 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.
- hermes.commands.init.util.slim_click.USE_FANCY_HYPERLINKS = False
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.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.EnumCreate 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.
- 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.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.next_step(description: str)
Keeps track of named steps by printing matching headlines. Make sure to set max_steps beforehand
- hermes.commands.init.util.slim_click.create_console_hyperlink(url: str, word: str) str
Use this to have a consistent display of hyperlinks.
- class hermes.commands.init.util.slim_click.ColorLogHandler
Bases:
logging.HandlerHandler 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.
- class hermes.commands.init.util.slim_click.ColorLogFormatter(_formats=None)
Bases:
logging.FormatterOwn version of a terminal log formatter to print our log messages with color.
- 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.