Skip to content

Commit 98346f7

Browse files
committed
feat(Window.split_window): Add size argument for tmux 3.2+
1 parent f80712e commit 98346f7

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

src/libtmux/window.py

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from libtmux.pane import Pane
2222

2323
from . import exc
24-
from .common import PaneDict, WindowOptionDict, handle_option_error
24+
from .common import PaneDict, WindowOptionDict, handle_option_error, has_lt_version
2525
from .formats import FORMAT_SEPARATOR
2626

2727
if t.TYPE_CHECKING:
@@ -184,7 +184,8 @@ def split_window(
184184
attach: bool = False,
185185
vertical: bool = True,
186186
shell: t.Optional[str] = None,
187-
percent: t.Optional[int] = None,
187+
size: t.Optional[t.Union[str, int]] = None,
188+
percent: t.Optional[int] = None, # deprecated
188189
environment: t.Optional[t.Dict[str, str]] = None,
189190
) -> "Pane":
190191
"""Split window and return the created :class:`Pane`.
@@ -209,8 +210,11 @@ def split_window(
209210
NOTE: When this command exits the pane will close. This feature
210211
is useful for long-running processes where the closing of the
211212
window upon completion is desired.
213+
size: int, optional
214+
Cell/row or percentage to occupy with respect to current window.
212215
percent: int, optional
213-
percentage to occupy with respect to current window
216+
Deprecated in favor of size. Percentage to occupy with respect to current
217+
window.
214218
environment: dict, optional
215219
Environmental variables for new pane. tmux 3.0+ only. Passthrough to ``-e``.
216220
@@ -228,6 +232,10 @@ def split_window(
228232
.. versionchanged:: 0.28.0
229233
230234
``attach`` default changed from ``True`` to ``False``.
235+
236+
.. deprecated:: 0.28.0
237+
238+
``percent=25`` deprecated in favor of ``size="25%"``.
231239
"""
232240
tmux_formats = ["#{pane_id}" + FORMAT_SEPARATOR]
233241

@@ -248,9 +256,28 @@ def split_window(
248256
else:
249257
tmux_args += ("-h",)
250258

259+
if size is not None:
260+
if has_lt_version("3.1"):
261+
if isinstance(size, str) and size.endswith("%"):
262+
tmux_args += (f'-p{str(size).rstrip("%")}',)
263+
else:
264+
warnings.warn(
265+
'Ignored size. Use percent in tmux < 3.1, e.g. "size=50%"',
266+
stacklevel=2,
267+
)
268+
else:
269+
tmux_args += (f"-l{size}",)
270+
251271
if percent is not None:
252272
# Deprecated in 3.1 in favor of -l
253-
tmux_args += ("-p %d" % percent,)
273+
warnings.warn(
274+
f'Deprecated in favor of size="{str(percent).rstrip("%")}%" '
275+
+ ' ("-l" flag) in tmux 3.1+.',
276+
category=DeprecationWarning,
277+
stacklevel=2,
278+
)
279+
tmux_args += (f"-p{percent}",)
280+
254281
tmux_args += ("-P", "-F%s" % "".join(tmux_formats)) # output
255282

256283
if start_directory is not None:

0 commit comments

Comments
 (0)