Example #1
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
Example #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), [])
Example #3
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))
Example #4
0
    def initialize(cls, pane, termstate):

        lines = termstate.lines[:]
        assert lines.pop(0) == '$rw'
        tmux.send_command(pane, 'rw', prompt=u'>')
        save()
        first_line = lines.pop(0)
        assert first_line.startswith('>')
        pane.tmux('send-keys', first_line[1:])
        pane.enter()
        tmux.wait_until_cursor_moves(pane, 1, 1)
        for i, line in enumerate(lines):
            if i == termstate.cursor_line:
                assert len(lines) == i - 1
                pane.tmux('send-keys', line)
            elif line.startswith('>'):
                tmux.send_command(pane, '>', enter=False, prompt=u'>')
                save()
                pane.tmux('send-keys', line[1:])
                if i != len(lines) - 1:
                    pane.enter()
            else:
                if line != '':
                    row, col = tmux.cursor_pos(pane)
                    pane.tmux('send-keys', line)
                    tmux.wait_until_cursor_moves(pane, row, col)
                if i != len(lines) - 1:
                    pane.enter()
        row, col = tmux.cursor_pos(pane)

        additional_required_blank_rows = (
            termstate.history_height - len(tmux.scrollback(pane)) +
            termstate.height - row - 1)
        assert additional_required_blank_rows >= 0
        assert col == len(line) % termstate.width  # TODO allow other columns
        if additional_required_blank_rows == 1:
            pane.tmux('1c'+str(col))
            pane.enter()
        elif additional_required_blank_rows > 1:
            for _ in range(additional_required_blank_rows - 1):
                pane.enter()
            for _ in range(additional_required_blank_rows - 2):
                pane.tmux('send-keys', 'up2')
                pane.enter()
            pane.tmux('send-keys', 'uc'+str(col))
            pane.enter()