diff --git a/libtmux/pane.py b/libtmux/pane.py index cfd943aa8..10498731e 100644 --- a/libtmux/pane.py +++ b/libtmux/pane.py @@ -104,17 +104,20 @@ def reset(self): self.cmd('send-keys', '-R \; clear-history') - def split_window(self, attach=False): + def split_window(self, attach=False, vertical=True): """Split window at pane and return newly created :class:`Pane`. :param attach: Attach / select pane after creation. :type attach: bool + :param vertical: split vertically + :type vertical: bool :rtype: :class:`Pane`. """ return self.window.split_window( target=self.get('pane_id'), - attach=attach + attach=attach, + vertical=vertical ) def set_width(self, width): diff --git a/libtmux/window.py b/libtmux/window.py index 0ab130731..f0b8e8a6e 100644 --- a/libtmux/window.py +++ b/libtmux/window.py @@ -346,7 +346,8 @@ def split_window( self, target=None, start_directory=None, - attach=True + attach=True, + vertical=True ): """Split window and return the created :class:`Pane`. @@ -372,6 +373,8 @@ def split_window( :type start_directory: string :param target: ``target_pane`` to split. :type target: bool + :param vertical: split vertically + :type vertical: bool :rtype: :class:`Pane` @@ -390,6 +393,11 @@ def split_window( else: tmux_args += ('-t%s' % self.panes[0].get('pane_id'),) + if vertical: + tmux_args += ('-v',) + else: + tmux_args += ('-h',) + tmux_args += ( '-P', '-F%s' % ''.join(tmux_formats) # output ) diff --git a/tests/test_window.py b/tests/test_window.py index fe9ee94b7..2643dc225 100644 --- a/tests/test_window.py +++ b/tests/test_window.py @@ -100,12 +100,23 @@ def test_attached_pane(session): def test_split_window(session): - """Window.split_window() splits window, returns new Pane.""" + """Window.split_window() splits window, returns new Pane, vertical. """ window_name = 'test split window' window = session.new_window(window_name=window_name, attach=True) pane = window.split_window() assert len(window.panes) == 2 assert isinstance(pane, Pane) + assert float(window.panes[0].height) <= ((float(window.width) + 1) / 2) + + +def test_split_window_horizontal(session): + """Window.split_window() splits window, returns new Pane, horizontal. """ + window_name = 'test split window' + window = session.new_window(window_name=window_name, attach=True) + pane = window.split_window(vertical=False) + assert len(window.panes) == 2 + assert isinstance(pane, Pane) + assert float(window.panes[0].width) <= ((float(window.width) + 1) / 2) @pytest.mark.parametrize("window_name_before,window_name_after", [