Skip to content

Add percent arg to split window #234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 25, 2020
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
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Here you can find the recent changes to libtmux

current
-------
- :issue:`234`: ``Window.split_window``: Allow passing ``percent``
- :issue:`289`: Fix warning due to invalid escape sequences
- :issue:`295`: Publish docs via our own action
- :issue:`295`: Move more packaging over to poetry, though we'll keep
Expand Down
5 changes: 4 additions & 1 deletion libtmux/pane.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def reset(self):

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

def split_window(self, attach=False, vertical=True, start_directory=None):
def split_window(self, attach=False, vertical=True, start_directory=None, percent=None):
"""
Split window at pane and return newly created :class:`Pane`.

Expand All @@ -167,6 +167,8 @@ def split_window(self, attach=False, vertical=True, start_directory=None):
split vertically
start_directory : str, optional
specifies the working directory in which the new pane is created.
percent: int, optional
percentage to occupy with respect to current pane

Returns
-------
Expand All @@ -177,6 +179,7 @@ def split_window(self, attach=False, vertical=True, start_directory=None):
start_directory=start_directory,
attach=attach,
vertical=vertical,
percent=percent,
)

def set_width(self, width):
Expand Down
13 changes: 12 additions & 1 deletion libtmux/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,13 @@ def last_pane(self):
return self.select_pane('-l')

def split_window(
self, target=None, start_directory=None, attach=True, vertical=True, shell=None
self,
target=None,
start_directory=None,
attach=True,
vertical=True,
shell=None,
percent=None,
):
"""
Split window and return the created :class:`Pane`.
Expand All @@ -407,6 +413,8 @@ def split_window(
NOTE: When this command exits the pane will close. This feature
is useful for long-running processes where the closing of the
window upon completion is desired.
percent: int, optional
percentage to occupy with respect to current window

Returns
-------
Expand Down Expand Up @@ -446,6 +454,9 @@ def split_window(
else:
tmux_args += ('-h',)

if percent is not None:
tmux_args += ('-p %d' % percent,)

tmux_args += ('-P', '-F%s' % ''.join(tmux_formats)) # output

if start_directory:
Expand Down