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.

__init__(self, parser, prompt, history_file, history_length)

(Not documented)

enter(self)

Enter the input context.

input(self)

Input one line from user and return it.

leave(self)

Exit the input context.

usable()

Called to determine whether this driver is usable.

class DumbInput()

The horror.

input(self)

(Not documented)

usable()

(Not documented)

class ReadlineDriver()

Base class for readline variants.

__init__(self, **args, *kwargs)

(Not documented)

enter(self)

(Not documented)

input(self)

(Not documented)

leave(self)

(Not documented)

usable()

(Not documented)

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.

System Message: ERROR/3 (<string>, line 6); backlink

Unknown interpreted text role "class".

System Message: ERROR/3 (<string>, line 6); backlink

Unknown interpreted text role "class".

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.

System Message: ERROR/3 (<string>, line 12); backlink

Unknown interpreted text role "class".

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.

System Message: ERROR/3 (<string>, line 16); backlink

Unknown interpreted text role "class".

history_file:

Defaults to ~/.<application>_history.

history_length:

Lines of history to keep.

exceptions:

See :meth:`loop`.

System Message: ERROR/3 (<string>, line 21); backlink

Unknown interpreted text role "meth".

__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`.

System Message: ERROR/3 (<string>, line 3); backlink

Unknown interpreted text role "class".