Terminal utilities

Utilities for logging and asking for user input.

Logging

roastery.term.log(*contents: str, style: str | None = None, header: str | None = None)[source]

Log contents to the terminal in a given style.

Parameters:
  • contents (str) – String containing the log message in Rich Markup.

  • style (str | None) – Style to forward to rich.Text

  • header (str | None) – Header text to preface the log message with.

roastery.term.info(*contents: str)[source]

Log the contents to the terminal in informational style.

Parameters:

contents (str) – String containing the log message in Rich Markup.

roastery.term.error(*contents: str)[source]

Log the contents to the terminal as an error.

Parameters:

contents (str) – String containing the log message in Rich Markup.

roastery.term.warn(*contents: str)[source]

Log the contents to the terminal as a warning.

Parameters:

contents (str) – String containing the log message in Rich Markup.

roastery.term.hint(*contents: str)[source]

Log the contents to the terminal as a hint.

Parameters:

contents (str) – String containing the log message in Rich Markup.

roastery.term.executing(command: list[str])[source]

Log that the program is executing a command

Parameters:

command (list[str]) – The command that the program is executing. This is a list, to allow easy integration with subprocess.run().

User input

roastery.term.ask(question: str, *, default: str = None) str[source]

Ask the user a question, returning their answer.

Users will be able to enter their answer in a readline-style environment with vi-style keybindings.

Parameters:
  • question (str) – Question to prompt the user with.

  • default (str) – Default to pre-populate the readline env

Return type:

str

Prompt the user to choose from a set of options using fuzzy search.

Fuzzy search is implemented by fzf.

Parameters:
  • prompt (str) – Search prompt to set in fzf.

  • options (list[str]) – List of options that the user can choose from.

Raises:

KeyboardInterrupt – If the user did not confirm the selection.

Return type:

str