Skip to content

Commit 4b58645

Browse files
authored
Merge pull request #11 from tek/master
allow splitting panes horizontally
2 parents 81c7a84 + 05e2aa8 commit 4b58645

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

libtmux/pane.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,17 +104,20 @@ def reset(self):
104104

105105
self.cmd('send-keys', '-R \; clear-history')
106106

107-
def split_window(self, attach=False):
107+
def split_window(self, attach=False, vertical=True):
108108
"""Split window at pane and return newly created :class:`Pane`.
109109
110110
:param attach: Attach / select pane after creation.
111111
:type attach: bool
112+
:param vertical: split vertically
113+
:type vertical: bool
112114
:rtype: :class:`Pane`.
113115
114116
"""
115117
return self.window.split_window(
116118
target=self.get('pane_id'),
117-
attach=attach
119+
attach=attach,
120+
vertical=vertical
118121
)
119122

120123
def set_width(self, width):

libtmux/window.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,8 @@ def split_window(
346346
self,
347347
target=None,
348348
start_directory=None,
349-
attach=True
349+
attach=True,
350+
vertical=True
350351
):
351352
"""Split window and return the created :class:`Pane`.
352353
@@ -372,6 +373,8 @@ def split_window(
372373
:type start_directory: string
373374
:param target: ``target_pane`` to split.
374375
:type target: bool
376+
:param vertical: split vertically
377+
:type vertical: bool
375378
376379
:rtype: :class:`Pane`
377380
@@ -390,6 +393,11 @@ def split_window(
390393
else:
391394
tmux_args += ('-t%s' % self.panes[0].get('pane_id'),)
392395

396+
if vertical:
397+
tmux_args += ('-v',)
398+
else:
399+
tmux_args += ('-h',)
400+
393401
tmux_args += (
394402
'-P', '-F%s' % ''.join(tmux_formats) # output
395403
)

tests/test_window.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,23 @@ def test_attached_pane(session):
100100

101101

102102
def test_split_window(session):
103-
"""Window.split_window() splits window, returns new Pane."""
103+
"""Window.split_window() splits window, returns new Pane, vertical. """
104104
window_name = 'test split window'
105105
window = session.new_window(window_name=window_name, attach=True)
106106
pane = window.split_window()
107107
assert len(window.panes) == 2
108108
assert isinstance(pane, Pane)
109+
assert float(window.panes[0].height) <= ((float(window.width) + 1) / 2)
110+
111+
112+
def test_split_window_horizontal(session):
113+
"""Window.split_window() splits window, returns new Pane, horizontal. """
114+
window_name = 'test split window'
115+
window = session.new_window(window_name=window_name, attach=True)
116+
pane = window.split_window(vertical=False)
117+
assert len(window.panes) == 2
118+
assert isinstance(pane, Pane)
119+
assert float(window.panes[0].width) <= ((float(window.width) + 1) / 2)
109120

110121

111122
@pytest.mark.parametrize("window_name_before,window_name_after", [

0 commit comments

Comments
 (0)