onyo.lib.ui module
- class onyo.lib.ui.UI(debug=False, quiet=False, yes=False)[source]
Bases:
objectAn object to handle user interaction.
Includes printing, errors, requests, etc.
- __init__(debug=False, quiet=False, yes=False)[source]
Initialize the User Interface object for user communication of Onyo.
- Parameters:
debug (
bool(default:False)) – Activate the debug mode to display additional information via Onyo, and to print the full traceback stack if errors occur.quiet (
bool(default:False)) – Suppress all output. Requiresyes=True.yes (
bool(default:False)) – Answer “yes” to all user-interactive prompts.
- error(error, end='\\n')[source]
Print an error message.
When provided, Exceptions will print tracebacks in debug mode.
Nothing is printed when
quietisTrue.
- log_debug(*args, **kwargs)[source]
Log at
DEBUGlevel.- Parameters:
args – Passed to
logging.Logger.debug()kwargs – Passed to
logging.Logger.debug()
- Return type:
- request_user_response(question, default='yes', answers=None)[source]
Print a question and read a response from
stdin.When
yesisTrue, thedefaultanswer is used without prompting the user.When a user’s response matches any of the
answers, the corresponding return value is returned. If the user’s response doesn’t match any answers, the question is repeated.- Parameters:
question (
str) – Question that the user should respond to.default (
str(default:'yes')) – Default answer used when the answer is empty (user hit only enter) oryesisTrue.answers (
list[tuple] |None(default:None)) –List of answers and corresponding value to return for those answers. The first element is the return value, and the second is a list of strings.
Default is ‘y’, ‘Y’, or ‘yes’ return
Trueand ‘n’, ‘N’, or ‘no’ returnFalse.
- Return type:
- rich_print(*args, **kwargs)[source]
Print via the
richmodule.A proxy for
rich.Console.print.- Parameters:
stderr – Bool to use a
stderrRich Console instead of astdoutRich Console.args – Passed to
rich.Console.print()kwargs – Passed to
rich.Console.print()
- Return type:
- set_quiet(quiet=False)[source]
Toggle quiet mode.
- Parameters:
quiet (
bool(default:False)) – Suppress all output. Requiresyes=True.- Raises:
ValueError – Tried to activate quiet mode without
yes=True.- Return type: