Beispiel #1
0
def Interact(session):
    global readline
    try:
        import readline as rl  # Unix-only
        readline = rl
    except ImportError:
        pass

    try:
        if readline:
            readline.read_history_file(session.config.history_file())
            readline.set_completer_delims(Completer.DELIMS)
            readline.set_completer(Completer(session).get_completer())
            for opt in ["tab: complete", "set show-all-if-ambiguous on"]:
                readline.parse_and_bind(opt)
    except IOError:
        pass

    # Negative history means no saving state to disk.
    history_length = session.config.sys.history_length
    if readline is None:
        pass  # history currently not supported under Windows / Mac
    elif history_length >= 0:
        readline.set_history_length(history_length)
    else:
        readline.set_history_length(-history_length)

    try:
        prompt = session.ui.term.color('mailpile> ',
                                       color=session.ui.term.BLACK,
                                       weight=session.ui.term.BOLD,
                                       readline=(readline is not None))
        while not mailpile.util.QUITTING:
            try:
                with session.ui.term:
                    session.ui.block()
                    opt = raw_input(prompt).decode('utf-8').strip()
            except KeyboardInterrupt:
                session.ui.unblock(force=True)
                session.ui.notify(
                    _('Interrupted. '
                      'Press CTRL-D or type `quit` to quit.'))
                continue
            session.ui.term.check_max_width()
            session.ui.unblock(force=True)
            if opt:
                if ' ' in opt:
                    opt, arg = opt.split(' ', 1)
                else:
                    arg = ''
                try:
                    result = Action(session, opt, arg)
                    session.ui.block()
                    session.ui.display_result(result)
                except UsageError, e:
                    session.fatal_error(unicode(e))
                except UrlRedirectException, e:
                    session.fatal_error('Tried to redirect to: %s' % e.url)
Beispiel #2
0
def Interact(session):
    global readline
    try:
        import readline as rl  # Unix-only
        readline = rl
    except ImportError:
        pass

    try:
        if readline:
            readline.read_history_file(session.config.history_file())
            readline.set_completer_delims(Completer.DELIMS)
            readline.set_completer(Completer(session).get_completer())
            for opt in ["tab: complete", "set show-all-if-ambiguous on"]:
                readline.parse_and_bind(opt)
    except IOError:
        pass

    # Negative history means no saving state to disk.
    history_length = session.config.sys.history_length
    if readline is None:
        pass  # history currently not supported under Windows / Mac
    elif history_length >= 0:
        readline.set_history_length(history_length)
    else:
        readline.set_history_length(-history_length)

    try:
        prompt = session.ui.palette.color('mailpile> ',
                                          color=session.ui.palette.BLACK,
                                          weight=session.ui.palette.BOLD)
        while True:
            session.ui.block()
            opt = raw_input(prompt).decode('utf-8').strip()
            session.ui.unblock()
            if opt:
                if ' ' in opt:
                    opt, arg = opt.split(' ', 1)
                else:
                    arg = ''
                try:
                    session.ui.display_result(Action(session, opt, arg))
                except UsageError, e:
                    session.error(unicode(e))
                except UrlRedirectException, e:
                    session.error('Tried to redirect to: %s' % e.url)
def Interact(session):
    global readline
    try:
        import readline as rl  # Unix-only
        readline = rl
    except ImportError:
        pass

    try:
        if readline:
            readline.read_history_file(session.config.history_file())
            readline.set_completer_delims(Completer.DELIMS)
            readline.set_completer(Completer(session).get_completer())
            for opt in ["tab: complete", "set show-all-if-ambiguous on"]:
                readline.parse_and_bind(opt)
    except IOError:
        pass

    # Negative history means no saving state to disk.
    history_length = session.config.sys.history_length
    if readline is None:
        pass  # history currently not supported under Windows / Mac
    elif history_length >= 0:
        readline.set_history_length(history_length)
    else:
        readline.set_history_length(-history_length)

    try:
        prompt = session.ui.term.color('mailpile> ',
                                       color=session.ui.term.BLACK,
                                       weight=session.ui.term.BOLD,
                                       readline=(readline is not None))
        while not mailpile.util.QUITTING:
            try:
                with session.ui.term:
                    if Setup.Next(session.config, 'anything') != 'anything':
                        session.ui.notify(
                            _('Mailpile is unconfigured, please run `setup`'
                              ' or visit the web UI.'))
                    session.ui.block()
                    opt = threaded_raw_input(prompt)
            except KeyboardInterrupt:
                session.ui.unblock(force=True)
                session.ui.notify(
                    _('Interrupted. '
                      'Press CTRL-D or type `quit` to quit.'))
                continue
            session.ui.term.check_max_width()
            session.ui.unblock(force=True)
            if opt:
                old_render_mode, opt = FriendlyPipeTransform(session, opt)
                if ' ' in opt:
                    opt, arg = opt.split(' ', 1)
                else:
                    arg = ''
                try:
                    result = Action(session, opt, arg)
                    session.ui.block()
                    session.ui.display_result(result)
                except UsageError as e:
                    session.fatal_error(unicode(e))
                except UrlRedirectException as e:
                    session.fatal_error('Tried to redirect to: %s' % e.url)
                if old_render_mode is not None:
                    session.ui.render_mode = old_render_mode
    except EOFError:
        print()
    finally:
        session.ui.unblock(force=True)

    write_readline_history(session)