hermes.commands.init.util.slim_click
====================================

.. py:module:: hermes.commands.init.util.slim_click

.. autoapi-nested-parse::

   Slim, self-made and partial implementation of some `click <https://click.palletsprojects.com>`_ functionality,
   so we don't need to add another large dependency for simple console questions and outputs.



Attributes
----------

.. autoapisummary::

   hermes.commands.init.util.slim_click.PRINT_DEBUG
   hermes.commands.init.util.slim_click.AUTO_LOG_ON_ECHO
   hermes.commands.init.util.slim_click.USE_FANCY_HYPERLINKS
   hermes.commands.init.util.slim_click.max_steps
   hermes.commands.init.util.slim_click.current_steps
   hermes.commands.init.util.slim_click.default_file_logger


Classes
-------

.. autoapisummary::

   hermes.commands.init.util.slim_click.Formats
   hermes.commands.init.util.slim_click.ColorLogHandler
   hermes.commands.init.util.slim_click.ColorLogFormatter


Functions
---------

.. autoapisummary::

   hermes.commands.init.util.slim_click.echo
   hermes.commands.init.util.slim_click.debug_info
   hermes.commands.init.util.slim_click.confirm
   hermes.commands.init.util.slim_click.answer
   hermes.commands.init.util.slim_click.press_enter_to_continue
   hermes.commands.init.util.slim_click.choose
   hermes.commands.init.util.slim_click.headline
   hermes.commands.init.util.slim_click.next_step
   hermes.commands.init.util.slim_click.create_console_hyperlink


Module Contents
---------------

.. py:data:: PRINT_DEBUG
   :value: False


   If true, echo() will print debug texts.

.. py:data:: AUTO_LOG_ON_ECHO
   :value: 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.

.. py:data:: USE_FANCY_HYPERLINKS
   :value: False


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

.. py:data:: max_steps
   :value: 0


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

.. py:data:: current_steps
   :value: 0


   The number if the last printed step

.. py:data:: default_file_logger
   :type:  logging.Logger
   :value: None


   The file logger used by echo if AUTO_LOG_ON_ECHO

.. py:class:: Formats(*args, **kwds)

   Bases: :py:obj:`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.


   .. py:attribute:: HEADER
      :value: '\x1b[95m'



   .. py:attribute:: OKBLUE
      :value: '\x1b[94m'



   .. py:attribute:: OKCYAN
      :value: '\x1b[96m'



   .. py:attribute:: OKGREEN
      :value: '\x1b[92m'



   .. py:attribute:: WARNING
      :value: '\x1b[93m'



   .. py:attribute:: FAIL
      :value: '\x1b[91m'



   .. py:attribute:: ENDC
      :value: '\x1b[0m'



   .. py:attribute:: BOLD
      :value: '\x1b[1m'



   .. py:attribute:: ITALIC
      :value: '\x1b[3m'



   .. py:attribute:: UNDERLINE
      :value: '\x1b[4m'



   .. py:attribute:: EMPTY
      :value: ''



   .. py:method:: __add__(other)


   .. py:method:: get_ansi() -> str


   .. py:method:: get_log_type(default: int = logging.INFO) -> int


   .. py:method:: wrap_around(text: str) -> str


.. py:function:: 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.


.. py:function:: debug_info(*args, **kwargs)

.. py:function:: 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.


.. py:function:: answer(text: str) -> str

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


.. py:function:: press_enter_to_continue(text: str = 'Press ENTER to continue') -> None

.. py:function:: choose(text: str, options: list[str], default: int = 0) -> int

   The user gets to make a choice between predefined answers.

   :param text: Displayed text / question
   :param options: List with possible answers
   :param default: Selected answer (index) if the user doesn't enter anything
   :return: The index of the selected option


.. py:function:: headline(text: str)

   Prints a big headline onto the console


.. py:function:: next_step(description: str)

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


.. py:function:: create_console_hyperlink(url: str, word: str) -> str

   Use this to have a consistent display of hyperlinks.


.. py:class:: ColorLogHandler

   Bases: :py:obj:`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.


   .. py:attribute:: formatter


   .. py:method:: 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.



.. py:class:: ColorLogFormatter(_formats=None)

   Bases: :py:obj:`logging.Formatter`


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


   .. py:attribute:: formats


   .. py:method:: 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.



   .. py:method:: _default_format()
      :staticmethod:



