Example #1
0
def execute_interactive():
    """ Runs the command mode once, reading the standard input for a command
    and executing it. Will return execution once a command has been executed
    or if an invalid command was passed.
    """
    old_completer = readline.get_completer()
    readline.set_completer(__readline_completer)
    readline.parse_and_bind('tab: complete')

    term.enter_buffer()
    # default raw mode is not readline friendly.
    # restore after saving display, for restoring is destructive
    term.restore_tty()

    try:
        cmd_name = raw_input('REACH:')
    except:
        # return to raw_mode
        term.set_raw()
        readline.set_completer(old_completer)
        term.leave_buffer()
        return

    cmd_args = [x for x in cmd_name.split(' ') if x != '']
    if cmd_args and cmd_args[0] in registry:
        try:
            registry[cmd_args[0]][1](cmd_args)
        except Exception, e:
            print(e)
            term.pause()
Example #2
0
def main():
    completors = completor.init_completors(Settings.load())
    partial_host_chain = opts.get_initial_host_chain()
    current_visibility = discover_visibility()
    chain = create_chain(completors, partial_host_chain, current_visibility)

    chan = Channel.get_instance()
    chan.chain_connect(chain)
    chan.get_interactive_chan()

    term.set_raw()
    try:
        while chan.run():
            # run Forrest run
            pass
    finally:
        term.restore_tty()