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
def test_resizing_window(self): lines = [u'$rw', u'>1 + 1', u'usually 2', u'>2 + 2', u'notquite 4', u'>3', u'3', u'>'] termstate = terminal_dsl.TerminalState( lines=lines, cursor_line=7, cursor_offset=1, width=11, height=6, history_height=3) with UndoScenario(termstate) as t: UndoScenario.initialize(t, termstate) tmux.stepwise_resize_width(t, 11) self.assertEqual(tmux.all_contents(t), lines)
def assert_undo(self, diagram, slow=False): states = [terminal_dsl.parse_term_state(x)[1] for x in terminal_dsl.divide_term_states(diagram)] if len(states) < 2: raise ValueError("Diagram has only one state") with UndoScenario(states[0]) as t: UndoScenario.initialize(t, states[0]) if slow: time.sleep(1) for before, after in zip(states[:-1], states[1:]): self.resize(before, after, t) if slow: time.sleep(1) if self.should_undo(before, after): restore(t) if slow: time.sleep(1) actual = terminal_dsl.TerminalState.from_tmux_pane(t) self.assertEqual(after, actual, after.visible_diff(actual)) self.assertEqual(tmux.all_contents(t), rewrite.linesplit(after.lines, after.width))
def test_contents(self): with tmux.TmuxPane(20, 5) as t: tmux.send_command(t, 'echo 01234567890123456789') tmux.send_command(t, 'echo 01234567890123456789') self.assertEqual(tmux.all_contents(t), ['$echo 01234567890123', '456789', '01234567890123456789', '$echo 01234567890123', '456789', '01234567890123456789', '$']) self.assertEqual(tmux.all_lines(t), ['$echo 01234567890123' '456789', '01234567890123456789', '$echo 01234567890123' '456789', '01234567890123456789', '$'])