dav_tools.messages

Print messages on screen and ask for user input.

Submodules

Classes

FormattedText

Represents text with optional formatting options applied.

Functions

_read_input(*format_options[, secret, file])

Ask input from a user using specified styling options.

_clear_line([file, flush])

Clears the current line from any text of formatting.

message(*text[, text_min_len, default_text_options, ...])

Generic and customizable message.

debug(*text[, color, text_min_len, text_options, file])

Debugging message, which stands out from all other messages. Each messages has also a unique ID.

info(*text[, text_min_len, text_options, file])

Message indicating an information.

progress(*text[, text_min_len, text_options, file])

Message indicating an action which is still happening.

error(*text[, text_min_len, text_options, file])

Message indicating an error.

critical_error(*text[, text_min_len, exit_code, file])

Message indicating a critical error. The program terminates after showing this message.

warning(*text[, text_min_len, text_options, file])

Message indicating a warning.

success(*text[, text_min_len, text_options, file])

Message indicating a successfully completed action.

ask(question[, end, secret, file])

Prints a question to screen and returns the answer.

ask_yn(text[, default_yes, file])

Prints a question asking the user a Yes/No question.

ask_continue([text, default_yes, file])

Prints a question asking the user if they want to continue executing the program:

Package Contents

class dav_tools.messages.FormattedText(text, *options)

Represents text with optional formatting options applied.

Parameters:
  • text (str) – The text content to be formatted.

  • options (bytes) – Optional formatting options to be applied to the text.

get_format()

Constructs the formatting string based on the provided options.

Returns:

A string representing the combined formatting options.

Return type:

str

static reset_format()

Provides the reset formatting string to clear any applied styles.

Returns:

A string representing the reset formatting option.

Return type:

str

dav_tools.messages._read_input(*format_options, secret=False, file=_sys.stderr)

Ask input from a user using specified styling options.

Parameters:
  • format_options (bytes) – Text styling options.

  • secret (bool) – Whether to hide the input.

  • file – Stream to use for output.

Returns:

User input.

Return type:

str

dav_tools.messages._clear_line(file=_sys.stdout, flush=False)

Clears the current line from any text of formatting. Not really suitable for files.

Parameters:
  • file – Stream to clear.

  • flush (bool) – Whether to flush the stream after printing.

Return type:

None

dav_tools.messages.message(*text, text_min_len=[], default_text_options=[], additional_text_options=[[]], icon=None, icon_options=[], sep=' ', end='\n', file=_sys.stderr)

Generic and customizable message.

Parameters:
  • text (str | object) – The message(s) to print.

  • text_min_len (list[int]) – Minimum length for each message. Fill the remaining characters with spaces.

  • default_text_options (list) – Styling options applied to all messages.

  • additional_text_options (list[list]) – Styling options applied to single messages.

  • icon (str | None) – Character to use as icon, between [ ].

  • icon_options (list) – Styling options applied to the icon.

  • end (str) – Character to output at the end of the message.

  • file – Where to write the message.

  • sep (str)

Return type:

str

dav_tools.messages.debug(*text, color=TextFormat.Color.PURPLE, text_min_len=[], text_options=[[]], file=_sys.stderr)

Debugging message, which stands out from all other messages. Each messages has also a unique ID.

Parameters:
  • text (str | object) – The message(s) to print.

  • color (bytes) – Message color. Default = Purple

  • text_min_len (list[int]) – Minimum length for each message. Fill the remaining characters with spaces.

  • text_options (list[list]) – Styling options applied to single messages.

  • file – Where to write the message.

Return type:

None

dav_tools.messages.info(*text, text_min_len=[], text_options=[[]], file=_sys.stderr)

Message indicating an information.

Parameters:
  • text (str | object) – The message(s) to print.

  • text_min_len (list[int]) – Minimum length for each message. Fill the remaining characters with spaces.

  • text_options (list[list]) – Styling options applied to single messages.

  • file – Where to write the message.

Return type:

None

dav_tools.messages.progress(*text, text_min_len=[], text_options=[[]], file=_sys.stderr)

Message indicating an action which is still happening.

Parameters:
  • text (str | object) – The message(s) to print.

  • text_min_len (list[int]) – Minimum length for each message. Fill the remaining characters with spaces.

  • text_options (list[list]) – Styling options applied to single messages.

  • file – Where to write the message.

Return type:

None

dav_tools.messages.error(*text, text_min_len=[], text_options=[[]], file=_sys.stderr)

Message indicating an error.

Parameters:
  • text (str | object) – The message(s) to print.

  • text_min_len (list[int]) – Minimum length for each message. Fill the remaining characters with spaces.

  • text_options (list[list]) – Styling options applied to single messages.

  • file – Where to write the message.

Return type:

None

dav_tools.messages.critical_error(*text, text_min_len=[], exit_code=1, file=_sys.stderr)

Message indicating a critical error. The program terminates after showing this message.

Parameters:
  • text (str | object) – The message(s) to print.

  • text_min_len (list[int]) – Minimum length for each message. Fill the remaining characters with spaces.

  • exit_code (int) – The exit code of the program.

  • file – Where to write the message.

Return type:

None

dav_tools.messages.warning(*text, text_min_len=[], text_options=[[]], file=_sys.stderr)

Message indicating a warning.

Parameters:
  • text (str | object) – The message(s) to print.

  • text_min_len (list[int]) – Minimum length for each message. Fill the remaining characters with spaces.

  • text_options (list[list]) – Styling options applied to single messages.

  • file – Where to write the message.

Return type:

None

dav_tools.messages.success(*text, text_min_len=[], text_options=[[]], file=_sys.stderr)

Message indicating a successfully completed action.

Parameters:
  • text (str | object) – The message(s) to print.

  • text_min_len (list[int]) – Minimum length for each message. Fill the remaining characters with spaces.

  • text_options (list[list]) – Styling options applied to single messages.

  • file – Where to write the message.

Return type:

None

dav_tools.messages.ask(question, end=': ', secret=False, file=_sys.stderr)

Prints a question to screen and returns the answer.

Parameters:
  • question (str) – The question to print.

  • end – Characters to be printed at the end of the question.

  • file – Where to write the message.

  • secret (bool)

Returns:

The user’s answer.

Return type:

str

dav_tools.messages.ask_yn(text, default_yes=False, file=_sys.stderr)

Prints a question asking the user a Yes/No question. Returns the answer as a boolean (Yes = True, No = False).

Parameters:
  • text (str) – The message to print.

  • default_yes (bool) – Automatically accept when pressing Enter.

  • file – Where to write the message.

Return type:

bool

dav_tools.messages.ask_continue(text=None, default_yes=False, file=_sys.stderr)

Prints a question asking the user if they want to continue executing the program: a positive answer makes the program continues its normal execution; a negative answer terminates the program. Optionally supports a custom message.

Parameters:
  • text (str | None) – The message to print.

  • default_yes (bool) – Automatically accept when pressing Enter.

  • file – Where to write the message.

Return type:

None