Skip to content

Commit 3060a4b

Browse files
committed
feat(Pane.split_window): Add direction, deprecate vertical.
1 parent e11f0a8 commit 3060a4b

File tree

1 file changed

+36
-10
lines changed

1 file changed

+36
-10
lines changed

src/libtmux/pane.py

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
from libtmux.common import has_gte_version, has_lt_version, tmux_cmd
1616
from libtmux.constants import (
1717
RESIZE_ADJUSTMENT_DIRECTION_FLAG_MAP,
18+
SPLIT_WINDOW_DIRECTION_FLAG_MAP,
1819
ResizeAdjustmentDirection,
20+
SplitWindowDirection,
1921
)
2022
from libtmux.formats import FORMAT_SEPARATOR
2123
from libtmux.neo import Obj, fetch_obj
@@ -489,15 +491,14 @@ def split(
489491
self,
490492
start_directory: t.Optional[str] = None,
491493
attach: bool = False,
492-
vertical: bool = True,
494+
direction: t.Optional[SplitWindowDirection] = None,
493495
shell: t.Optional[str] = None,
494496
size: t.Optional[t.Union[str, int]] = None,
495-
percent: t.Optional[int] = None, # deprecated
496497
environment: t.Optional[t.Dict[str, str]] = None,
498+
percent: t.Optional[int] = None, # deprecated
499+
vertical: t.Optional[bool] = None,
497500
) -> "Pane":
498-
"""Split window and return the created :class:`Pane`.
499-
500-
Used for splitting window and holding in a python object.
501+
"""Split window and return :class:`Pane`, by default beneath current pane.
501502
502503
Parameters
503504
----------
@@ -506,8 +507,8 @@ def split(
506507
True.
507508
start_directory : str, optional
508509
specifies the working directory in which the new window is created.
509-
vertical : bool, optional
510-
split vertically
510+
direction : SplitWindowDirection, optional
511+
split in direction. If none is specified, assume down.
511512
shell : str, optional
512513
execute a command on splitting the window. The pane will close
513514
when the command exits.
@@ -522,6 +523,8 @@ def split(
522523
window.
523524
environment: dict, optional
524525
Environmental variables for new pane. tmux 3.0+ only. Passthrough to ``-e``.
526+
vertical : bool, optional
527+
split vertically, deprecated by ``direction``.
525528
526529
Notes
527530
-----
@@ -534,6 +537,11 @@ def split(
534537
active. To remain on the same window and split the pane in another
535538
target window, pass in ``attach=False``.
536539
540+
.. deprecated:: 0.33.0
541+
542+
``vertical=True`` deprecated in favor of
543+
``direction=SplitWindowDirection.Below``.
544+
537545
.. versionchanged:: 0.28.0
538546
539547
``attach`` default changed from ``True`` to ``False``.
@@ -546,10 +554,28 @@ def split(
546554

547555
tmux_args: t.Tuple[str, ...] = ()
548556

549-
if vertical:
550-
tmux_args += ("-v",)
557+
if direction:
558+
tmux_args += tuple(SPLIT_WINDOW_DIRECTION_FLAG_MAP[direction])
559+
if vertical is not None:
560+
warnings.warn(
561+
"vertical is not required to pass with direction.",
562+
category=DeprecationWarning,
563+
stacklevel=2,
564+
)
565+
elif vertical is not None:
566+
warnings.warn(
567+
"vertical is deprecated in favor of direction.",
568+
category=DeprecationWarning,
569+
stacklevel=2,
570+
)
571+
if vertical:
572+
tmux_args += ("-v",)
573+
else:
574+
tmux_args += ("-h",)
551575
else:
552-
tmux_args += ("-h",)
576+
tmux_args += tuple(
577+
SPLIT_WINDOW_DIRECTION_FLAG_MAP[SplitWindowDirection.Below]
578+
)
553579

554580
if size is not None:
555581
if has_lt_version("3.1"):

0 commit comments

Comments
 (0)