Skip to content

Commit cd7519d

Browse files
committed
refactor!(Window): Add .split(), deprecate split_window()
1 parent cad0801 commit cd7519d

File tree

1 file changed

+57
-16
lines changed

1 file changed

+57
-16
lines changed

src/libtmux/window.py

Lines changed: 57 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -197,15 +197,14 @@ def select_pane(self, target_pane: t.Union[str, int]) -> t.Optional["Pane"]:
197197

198198
return self.active_pane
199199

200-
def split_window(
200+
def split(
201201
self,
202202
target: t.Optional[t.Union[int, str]] = None,
203203
start_directory: t.Optional[str] = None,
204204
attach: bool = False,
205205
vertical: bool = True,
206206
shell: t.Optional[str] = None,
207207
size: t.Optional[t.Union[str, int]] = None,
208-
percent: t.Optional[int] = None, # deprecated
209208
environment: t.Optional[t.Dict[str, str]] = None,
210209
) -> "Pane":
211210
"""Split window and return the created :class:`Pane`.
@@ -232,9 +231,6 @@ def split_window(
232231
window upon completion is desired.
233232
size: int, optional
234233
Cell/row or percentage to occupy with respect to current window.
235-
percent: int, optional
236-
Deprecated in favor of size. Percentage to occupy with respect to current
237-
window.
238234
environment: dict, optional
239235
Environmental variables for new pane. tmux 3.0+ only. Passthrough to ``-e``.
240236
@@ -264,9 +260,10 @@ def split_window(
264260
if target is not None:
265261
tmux_args += ("-t%s" % target,)
266262
else:
263+
active_pane = self.active_pane or self.panes[0]
267264
if len(self.panes):
268265
tmux_args += (
269-
f"-t{self.session_id}:{self.window_id}.{self.panes[0].pane_index}",
266+
f"-t{self.session_id}:{self.window_id}.{active_pane.pane_index}",
270267
)
271268
else:
272269
tmux_args += (f"-t{self.session_id}:{self.window_id}",)
@@ -288,16 +285,6 @@ def split_window(
288285
else:
289286
tmux_args += (f"-l{size}",)
290287

291-
if percent is not None:
292-
# Deprecated in 3.1 in favor of -l
293-
warnings.warn(
294-
f'Deprecated in favor of size="{str(percent).rstrip("%")}%" '
295-
+ ' ("-l" flag) in tmux 3.1+.',
296-
category=DeprecationWarning,
297-
stacklevel=2,
298-
)
299-
tmux_args += (f"-p{percent}",)
300-
301288
tmux_args += ("-P", "-F%s" % "".join(tmux_formats)) # output
302289

303290
if start_directory is not None:
@@ -833,6 +820,60 @@ def width(self) -> t.Optional[str]:
833820
#
834821
# Legacy: Redundant stuff we want to remove
835822
#
823+
def split_window(
824+
self,
825+
target: t.Optional[t.Union[int, str]] = None,
826+
start_directory: t.Optional[str] = None,
827+
attach: bool = False,
828+
vertical: bool = True,
829+
shell: t.Optional[str] = None,
830+
size: t.Optional[t.Union[str, int]] = None,
831+
percent: t.Optional[int] = None, # deprecated
832+
environment: t.Optional[t.Dict[str, str]] = None,
833+
) -> "Pane":
834+
"""Split window and return the created :class:`Pane`.
835+
836+
Notes
837+
-----
838+
.. deprecated:: 0.33.0
839+
840+
Deprecated in favor of :meth:`.split()`.
841+
842+
.. versionchanged:: 0.28.0
843+
844+
``attach`` default changed from ``True`` to ``False``.
845+
846+
.. deprecated:: 0.28.0
847+
848+
``percent=25`` deprecated in favor of ``size="25%"``.
849+
"""
850+
warnings.warn(
851+
"Window.split_window() is deprecated in favor of Window.split()",
852+
category=DeprecationWarning,
853+
stacklevel=2,
854+
)
855+
856+
if percent is not None:
857+
# Deprecated in 3.1 in favor of -l
858+
warnings.warn(
859+
f'Deprecated in favor of size="{str(percent).rstrip("%")}%" '
860+
+ ' ("-l" flag) in tmux 3.1+.',
861+
category=DeprecationWarning,
862+
stacklevel=2,
863+
)
864+
if size is None:
865+
size = f"{str(percent).rstrip('%')}%"
866+
867+
return self.split(
868+
target=target,
869+
start_directory=start_directory,
870+
attach=attach,
871+
vertical=vertical,
872+
shell=shell,
873+
size=size,
874+
environment=environment,
875+
)
876+
836877
@property
837878
def attached_pane(self) -> t.Optional["Pane"]:
838879
"""Return attached :class:`Pane`.

0 commit comments

Comments
 (0)