コード例 #1
0
ファイル: ctrl.py プロジェクト: amhk/lokatt
def main_loop(ctx):
    win = BufferWindow(ctx.root_window)
    ctx.buf = Buffer(win)

    win = StatusbarWindow(ctx.root_window)
    ctx.statusbar = Statusbar(win)

    while not ctx.done:
        type_, data = ctx.queue.get()

        if type_ == EVENT_LOGCAT:
            ctx.buf.accept(data)
            ctx.statusbar.accept(ctx.buf)

        if type_ == EVENT_KEYPRESS:
            if data == ord('q'):
                _post_command(ctx, 'quit')
            if data == ord('1'):
                _post_command(ctx, 'goto-line --lineno=1 --anchor=top')
            if data == ord('2'):
                _post_command(ctx, 'goto-line --lineno=100 --anchor=middle')
            if data == ord('3'):
                _post_command(ctx, 'goto-line --lineno=-1 --anchor=bottom')
            if data == ord('4'):
                _post_command(ctx, 'resume')

        if type_ == EVENT_COMMAND:
            logger.debug('EVENT_COMMAND: {}'.format(' '.join(data)))
            name = data[0]
            argv = data[1:]
            cmd = get_command(name)
            if cmd is not None:
                try:
                    cmd(ctx, argv)
                except ValueError as e:
                    cmd = get_command('error')
                    argv = ['{}: {}'.format(name, e.message), ]
                    cmd(ctx, argv)
            else:
                cmd = get_command('error')
                argv = ['{}: command not found'.format(name), ]
                cmd(ctx, argv)

        refresh_ui()
コード例 #2
0
ファイル: test_cmd.py プロジェクト: amhk/lokatt
 def test_goto_line(self):
     cmd = get_command('goto-line')
     self.assertIsNotNone(cmd)
     self.assertEqual('goto-line', cmd.name)
コード例 #3
0
ファイル: test_cmd.py プロジェクト: amhk/lokatt
 def test_cmd_error_exists(self):
     cmd = get_command('error')
     self.assertIsNotNone(cmd)
     self.assertEqual('error', cmd.name)
コード例 #4
0
ファイル: test_cmd.py プロジェクト: amhk/lokatt
 def test_cmd_foobar_does_not_exist(self):
     cmd = get_command('this-command-does-not-exist')
     self.assertIsNone(cmd)