cly.interactive
CLY and readline, together at last.
This module uses readline's line editing and tab completion along with CLY's grammar parser to provide an interactive command line environment.
It includes support for application specific history files, dynamic prompt, customisable completion key, interactive help and more.
Users can press ? at any time to view contextual help.
brief_exceptions(interact, context, completing, e)Display the string summary for exceptions.
verbose_exceptions(interact, context, completing, e)(Not documented)
debug_exceptions(interact, context, completing, e)(Not documented)
class InputDriver()
Abstraction for line input.
class DumbInput()
The horror.
class ReadlineDriver()
Base class for readline variants.
class PyReadlineDriver()
The IPython pure-Python pyreadline implementation.
usable()(Not documented)
class ExtendedReadlineDriver()
Use CLY's built-in readline extensions.
usable()(Not documented)
class Interact()
CLY interaction through readline. Due to readline limitations, only one Interact object can be active within an application.
Arguments:
grammar_or_parser: The :class:`~cly.parser.Parser` or :class:`~cly.builder.Grammar` to use for interaction.
application: The application name. Used to construct the history file name and prompt, if not provided.
prompt: The prompt.
data: A user-specified object to pass to the parser. The parser builds each parse :class:`~cly.parser.Context` with this object, which in turn will deliver this object on to terminal nodes that have set with_context=True.
with_context: Force current parser :class:`~cly.parser.Context` to be passed to all action nodes, unless they explicitly set the member variable with_context=False.
history_file: Defaults to ~/.<application>_history.
history_length: Lines of history to keep.
exceptions: See :meth:`loop`.
__init__(self, grammar_or_parser, application='cly', prompt=None, data=None, history_file=None, history_length=500, exceptions=None)(Not documented)
once(self)Input one command from the user and return the result of the executed command.
loop(self, exceptions=None, every=None)Repeatedly read and execute commands from the user.
- Arguments:
exceptions: A callback used to handle exceptions. It has the signature:
exceptions(interact, context, completing, e) => bool
context may be None and completing is True if exception was thrown from a completion function.
If True is returned the exception will be re-raised.
each: Called with the Interact object before each line is displayed.
print_error(self, context, e)Called by once() to print a ParseError.
error_at_cursor(self, context, text)Attempt to intelligently print an error at the current cursor offset.
dump_traceback(cls, exception)(Not documented)
best_input_driver(cls, **args, *kwargs)Select the "best" available input driver.
interact(grammar_or_parser, exceptions=None, **args, *kwargs)Start an interactive session with the given grammar or parser object.
Arguments are as for :class:`Interact`.
