Пример #1
0
    def test_scroll_down(self):
        with tmux.TmuxPane(40, 8) as t:
            tmux.send_command(t, 'true')
            tmux.send_command(t, 'true')
            tmux.send_command(t, 'true')
            tmux.send_command(t, 'true')
            tmux.send_command(t, 'true')
            tmux.send_command(t, 'python rewrite.py', prompt=u'>')
            self.assertEqual(tmux.visible(t),
                             (['$true']*5 +
                              ['$python rewrite.py',
                               '>']))
            self.assertEqual(tmux.cursor_pos(t), (6, 1))
            save()
            tmux.send_command(t, 'hello!', prompt=u'>')
            save()

            tmux.send_command(t, 'hi again!', prompt=u'>')
            save()
            self.assertEqual(tmux.visible(t),
                             ['$true']*4 + ['$python rewrite.py',
                                            '>hello!',
                                            '>hi again!',
                                            '>'])
            restore(t)

            self.assertEqual(tmux.visible_after_prompt(t, '>'),
                             ['$true']*4 + ['$python rewrite.py',
                                            '>hello!',
                                            '>'])
            self.assertEqual(tmux.cursor_pos(t), (6, 1))
Пример #2
0
 def test_simple(self):
     with tmux.TmuxPane(10, 10) as t:
         t.send_keys('true 1')
         self.assertEqual(tmux.visible(t), ['$ true 1',
                                            '$'])
         self.assertEqual(tmux.scrollback(t), [])
         t.send_keys('true 2')
         self.assertEqual(tmux.visible(t), ['$ true 1',
                                            '$ true 2',
                                            '$'])
         self.assertEqual(tmux.scrollback(t), [])
Пример #3
0
    def test_simple_save_and_restore(self):
        with tmux.TmuxPane(40, 10) as t:
            tmux.send_command(t, 'python rewrite.py', prompt=u'>')
            self.assertEqual(tmux.visible(t), ['$python rewrite.py', '>'])
            self.assertEqual(tmux.cursor_pos(t), (1, 1))
            save()

            tmux.send_command(t, 'hello!', prompt=u'>')
            self.assertEqual(tmux.visible(t),
                             ['$python rewrite.py', '>hello!', '>'])
            restore(t)

            self.assertEqual(tmux.visible_after_prompt(t, '>'),
                             ['$python rewrite.py', '>'])
            self.assertEqual(tmux.cursor_pos(t), (1, 1))
Пример #4
0
    def from_tmux_pane(cls, pane):
        import tmux
        lines = tmux.all_lines(pane)
        history_height = len(tmux.scrollback(pane))
        print('tmux.all_contents:', tmux.all_contents(pane))
        print('tmux.visible:', tmux.visible(pane))
        print('history_height:', history_height)
        print('tmux.scrollback:', tmux.scrollback(pane))
        width, height = tmux.width(pane), tmux.height(pane)

        cursor_row, cursor_col = tmux.cursor_pos(pane)

        #TODO deal with cursors not at the bottom

        termstate = TerminalState(
            lines=lines,
            cursor_line=len(lines) - 1,
            cursor_offset=len(lines[-1]),
            width=width,
            height=height,
            history_height=history_height)
        print(termstate)

        #assert termstate.cursor_row == cursor_row
        #assert termstate.cursor_column == cursor_col

        return termstate
Пример #5
0
 def test_initialize(self):
     lines = ['$rw', '>a', 'b', 'c', '>d', 'e', '>']
     termstate = terminal_dsl.TerminalState(
         lines, cursor_line=6, cursor_offset=1,
         width=10, height=10, history_height=0)
     with UndoScenario(termstate) as t:
         UndoScenario.initialize(t, termstate)
         output = tmux.visible(t)
         self.assertEqual(output, lines)
Пример #6
0
    def test_scroll_off(self):
        """Scroll down causing recorded output to scroll off the top."""
        with tmux.TmuxPane(40, 3) as t:
            tmux.send_command(t, 'python rewrite.py', prompt=u'>')
            save()
            self.assertEqual(tmux.visible(t), ['$python rewrite.py', '>'])
            self.assertEqual(tmux.cursor_pos(t), (1, 1))

            tmux.send_command(t, 'hello!', prompt=u'>')
            save()

            tmux.send_command(t, 'hi again!', prompt=u'>')
            save()
            self.assertEqual(tmux.visible(t),
                             ['>hello!', '>hi again!', '>'])
            restore(t)
            self.assertEqual(tmux.visible_after_prompt(t, '>'),
                             ['>hello!', '>'])
            self.assertEqual(tmux.cursor_pos(t), (1, 1))
Пример #7
0
 def test_simple(self):
     with tmux.TmuxPane(10, 10) as t:
         tmux.send_command(t, 'true 1')
         self.assertEqual(tmux.visible(t), ['$true 1',
                                            '$'])
         tmux.send_command(t, 'true 2')
         termstate = terminal_dsl.TerminalState.from_tmux_pane(t)
         expected = terminal_dsl.TerminalState(
             lines=['$true 1', '$true 2', '$'],
             cursor_line=2, cursor_offset=1, width=10, height=10,
             history_height=0)
     self.assertEqual(expected, termstate, expected.visible_diff(termstate))
Пример #8
0
    def test_rewind_to_scrolled_off_prompt(self):
        """Recreating history in visible area because undo goes offscreen

        For this we need to track history, do math to place
        this history in the visible window, and track scrolling
        or cursor position to know that we've run out of space.
        I think we don't need an emulator yet - just cursor querying should do.
        """
        with tmux.TmuxPane(60, 3) as t:
            tmux.send_command(t, 'python rewrite.py', prompt=u'>')
            save()
            self.assertEqual(tmux.visible(t), ['$python rewrite.py', '>'])
            self.assertEqual(tmux.cursor_pos(t), (1, 1))

            tmux.send_command(t, 'hi there!', prompt=u'>')
            save()

            tmux.send_command(t, 'hello!', prompt=u'>')
            tmux.send_command(t, 'hi again!', prompt=u'>')
            tmux.send_command(t, 'hey!', prompt=u'>')
            save()
            self.assertEqual(tmux.scrollback(t),
                             ['$python rewrite.py',
                              '>hi there!',
                              '>hello!'])
            self.assertEqual(tmux.visible(t),
                             ['>hi again!',
                              '>hey!',
                              '>'])
            restore(t)
            self.assertEqual(tmux.scrollback(t),
                             ['$python rewrite.py',
                              '>hi there!',
                              '>hello!',
                              '#<---History contiguity broken by rewind--->'])
            self.assertEqual(tmux.visible_after_prompt(t, '>'),
                             ['>hi there!',
                              '>'])
            self.assertEqual(tmux.cursor_pos(t), (1, 1))
Пример #9
0
 def test_cursor_query(self):
     with tmux.TmuxPane(40, 10) as t:
         tmux.send_command(t, 'true 1234')
         tmux.send_command(t, 'true 1234')
         program = "import findcursor, sys; print(findcursor.get_cursor_position(sys.stdout, sys.stdin))"
         tmux.send_command(t, 'python -c "%s"' % (program, ))
         lines = tmux.visible(t)
         while lines[-1] == u'$':
             lines.pop()
         line = lines[-1]
         self.assertTrue(len(line) > 1, repr(line))
         row, col = [int(x) for x in re.search(
             r'[(](\d+), (\d+)[)]', line).groups()]
         self.assertEqual(tmux.cursor_pos(t), (row+1, col+1))
Пример #10
0
    def test_resize(self):
        """lines and cursor pos wrap, reported by line

        The front of the current line retains its position!"""
        with tmux.TmuxPane(10, 10) as t:
            self.assertEqual(tmux.cursor_pos(t), (0, 1))
            tmux.send_command(t, 'true 123456789')
            self.assertEqual(tmux.visible(t),
                             ['$true 1234', '56789', '$'])
            self.assertEqual(tmux.cursor_pos(t), (2, 1))
            t.set_width(5)
            self.assertEqual(tmux.cursor_pos(t), (2, 1))
            self.assertEqual(tmux.visible_after_prompt(t),
                             [' 1234', '56789', '$'])
            tmux.stepwise_resize_width(t, 20)
            tmux.stepwise_resize_height(t, 20)
Пример #11
0
 def test_simple(self):
     """Test sending commands and reading formatted output with tmux."""
     with ActualUndo(80, 30) as t:
         tmux.send_command(t, 'ipy', prompt=IPyPrompt.in_formatted(1))
         tmux.send_command(t, 'a = 1', prompt=IPyPrompt.in_formatted(2))
         tmux.send_command(t, 'a', prompt=IPyPrompt.in_formatted(3))
         tmux.send_command(t, 'def foo():',
                           prompt=IPyPrompt.new_l_formatted())
         tmux.send_command(t, 'print "hi"',
                           prompt=IPyPrompt.new_l_formatted())
         tmux.send_command(t, ' ', prompt=IPyPrompt.in_formatted(4))
         output = tmux.visible(t)
         lines = [IPyPrompt.in_formatted(1) + ' \x1b[39ma = 1',
                  IPyPrompt.in_formatted(2) + ' \x1b[39ma',
                  IPyPrompt.out_formatted(2) + ' \x1b[39m1',
                  IPyPrompt.in_formatted(3) + ' \x1b[39mdef foo():',
                  IPyPrompt.new_l_formatted() + '    print "hi"',
                  IPyPrompt.new_l_formatted() + '',
                  IPyPrompt.in_formatted(4)]
         self.assertEqual(output[-7:], lines)
Пример #12
0
 def test_send_command(self):
     with tmux.TmuxPane(20, 20) as t:
         tmux.send_command(t, 'sleep .1; echo hi')
         self.assertEqual(tmux.visible(t), ['$sleep .1; echo hi',
                                            'hi',
                                            '$'])