zabgrab.ui.console¶
Terminal implementation of the UI port.
Diagnostics and prompts go to stderr; data (tables, TOML, …) goes to stdout via
RichUI.print_data(), so piping stdout always gives clean output.
Functions
|
Tell whether the user can be prompted. |
|
Make the warning given when a yes/no question is answered by its default. |
Classes
Highlights the specific, useful details in plain-text messages. |
|
|
User interaction via rich, implementing |
Highlights TOML: sections, keys, strings, numbers and booleans. |
- class zabgrab.ui.console.MessageHighlighter[source]¶
Bases:
RegexHighlighterHighlights the specific, useful details in plain-text messages.
Later patterns take precedence where matches overlap.
- class zabgrab.ui.console.TomlHighlighter[source]¶
Bases:
RegexHighlighterHighlights TOML: sections, keys, strings, numbers and booleans.
Use it on lines that aren’t comments (see
highlighted_toml).Later patterns take precedence, so e.g. text inside strings is only a string.
- zabgrab.ui.console.non_interactive_answer(question, default, fix)[source]¶
Make the warning given when a yes/no question is answered by its default.
- zabgrab.ui.console.is_interactive(variables, *, no_input=False, stdin=None, stderr=None)[source]¶
Tell whether the user can be prompted.
Requires stdin and stderr to be terminals, and none of
--no-input,$ZABGRAB_NO_INPUTor$CIto be set.- Parameters:
variables (mapping of str to str) – The environment variables.
no_input (bool, optional) –
--no-input.stdin (TextIO, optional) – The streams to check (by default, the process’s).
stderr (TextIO, optional) – The streams to check (by default, the process’s).
- Returns:
bool – Whether the session is interactive.
- Return type:
- class zabgrab.ui.console.RichUI(*, interactive, verbosity=0, color=None, debug=False)[source]¶
Bases:
objectUser interaction via rich, implementing
UI.- Parameters:
interactive (bool) – Whether the user can be asked questions.
verbosity (int, optional) –
0shows info and above, each-vadds a level (1shows debug), each-qremoves one (-1hides info,-2hides warnings). Errors are always shown.color (bool, optional) – Force colour on or off; by default, it’s used on terminals.
debug (bool, optional) –
--debug: show debug messages whatever the verbosity.
- err¶
The console for messages, on stderr.
- Type:
rich.console.Console
- out¶
The console for data, on stdout.
- Type:
rich.console.Console
- highlight(message, style='')[source]¶
Make a message into plain text (never markup), highlighting its details.
- debug(message)[source]¶
Show a message only with
-vor--debug.- Parameters:
message (str)
- Return type:
None
- success(message)[source]¶
Show that something worked (hidden by
-q).- Parameters:
message (str)
- Return type:
None
- warning(message)[source]¶
Show a warning (hidden by
-qq).- Parameters:
message (str)
- Return type:
None
- error(message, *, details=(), hint=None)[source]¶
Show an error, with optional detail lines and a hint on how to fix it.
- print_data(data)[source]¶
Print command output (not diagnostics) to stdout.
- Parameters:
data (ConsoleRenderable | RichCast | str)
- Return type:
None
- confirm(question, *, fix, default=True)[source]¶
Ask a yes/no question (see
zabgrab.services.ports.UI.confirm()).
- prompt(question, *, fix, parse, default=None, secret=False)[source]¶
Ask for free text (see
zabgrab.services.ports.UI.prompt()).
- choose(question, options, *, fix, default=None)[source]¶
Ask for one option (see
zabgrab.services.ports.UI.choose()).
- choose_many(question, options, *, fix)[source]¶
Ask for options (see
zabgrab.services.ports.UI.choose_many()).