Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions libtmux/pane.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
10 changes: 9 additions & 1 deletion libtmux/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand All @@ -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`

Expand All @@ -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
)
Expand Down
13 changes: 12 additions & 1 deletion tests/test_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", [
Expand Down