The Console object¶
The console
object is an interface for user interaction from within a
Node
. Among the input methods are choice lists, plain text input and password
input.
It has output methods that take the terminal size into account, like pagination and multi-column display. It takes care of the pseudo terminal underneat.
Example:
class MyNode(Node):
def do_something(self):
if self.console.confirm('Should we really do this?', default=True):
# Do it...
pass
Note
When the script runs in a shell that was started with the
--non-interactive
option, the default options will always be chosen
automatically.
-
class
deployer.console.
Console
(pty)¶ Interface for user interaction from within a
Node
.-
choice
(question, options, allow_random=False, default=None)¶ Parameters: - options (list) – List of (name, value) tuples.
- allow_random (bool) – If
True
, the default option becomes ‘choose random’.
-
confirm
(question, default=None)¶ Print this yes/no question, and return
True
when the user answers ‘Yes’.
-
in_columns
(item_iterator, margin_left=0)¶ Parameters: item_iterator – An iterable, which yields either basestring
instances, or (colored_item, length) tuples.
-
input
(label, is_password=False, answers=None, default=None)¶ Ask for plain text input. (Similar to raw_input.)
Parameters: - is_password (bool) – Show stars instead of the actual user input.
- answers – A list of the accepted answers or None.
- default – Default answer.
-
lesspipe
(line_iterator)¶ Paginator for output. This will print one page at a time. When the user presses a key, the next page is printed.
Ctrl-c
orq
will quit the paginator.Parameters: line_iterator – A generator function that yields lines (without trailing newline)
-
select_node
(root_node, prompt='Select a node', filter=None)¶ Show autocompletion for node selection.
-
select_node_isolation
(node)¶ Ask for a host, from a list of hosts.
-
-
deployer.console.
warning
(text)¶ Print a warning.