From 703e80bd998dec0919089ab45dd234a78305cf28 Mon Sep 17 00:00:00 2001 From: Jinank Jain Date: Mon, 7 Oct 2019 13:26:23 +0200 Subject: [PATCH 1/4] Add percent arg to split window While spliting window tmux supports '-p' to specify the amount (in percentage) that the newly created pane will occupy with respect to current pane. So let's expose the same functionality by an extra argument percent to split_window function. Signed-off-by: Jinank Jain --- libtmux/pane.py | 5 ++++- libtmux/window.py | 8 +++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/libtmux/pane.py b/libtmux/pane.py index 5ea1f11f9..0be1d8151 100644 --- a/libtmux/pane.py +++ b/libtmux/pane.py @@ -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`. @@ -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 ------- @@ -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): diff --git a/libtmux/window.py b/libtmux/window.py index 7b5b1b1d6..f98b45a87 100644 --- a/libtmux/window.py +++ b/libtmux/window.py @@ -382,7 +382,8 @@ 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`. @@ -407,6 +408,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 ------- @@ -446,6 +449,9 @@ def split_window( else: tmux_args += ('-h',) + if percent: + tmux_args += ('-p %d' % percent,) + tmux_args += ('-P', '-F%s' % ''.join(tmux_formats)) # output if start_directory: From 5cc8a503d3e4bceb5f2bcbbfa76fd2cdeb774427 Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Sun, 25 Oct 2020 08:42:16 -0500 Subject: [PATCH 2/4] Format with black --- libtmux/window.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/libtmux/window.py b/libtmux/window.py index f98b45a87..f3c8cd359 100644 --- a/libtmux/window.py +++ b/libtmux/window.py @@ -382,8 +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, percent=None + self, + target=None, + start_directory=None, + attach=True, + vertical=True, + shell=None, + percent=None, ): """ Split window and return the created :class:`Pane`. From 3895963419bd5756342d157bd8915fddc7bd16a2 Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Sun, 25 Oct 2020 08:43:16 -0500 Subject: [PATCH 3/4] Update CHANGES --- CHANGES | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES b/CHANGES index 7ab5186a6..2eb8905ff 100644 --- a/CHANGES +++ b/CHANGES @@ -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 From f11d4f6433e07dbeb72cb85b77e7ea26ea811cef Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Sun, 25 Oct 2020 08:43:38 -0500 Subject: [PATCH 4/4] Improve type checking for percent It's unlikely a user would ever want to pass 0, but to remain true to what's passed in, allow this. --- libtmux/window.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libtmux/window.py b/libtmux/window.py index f3c8cd359..05ee34c33 100644 --- a/libtmux/window.py +++ b/libtmux/window.py @@ -454,7 +454,7 @@ def split_window( else: tmux_args += ('-h',) - if percent: + if percent is not None: tmux_args += ('-p %d' % percent,) tmux_args += ('-P', '-F%s' % ''.join(tmux_formats)) # output