77
88import dataclasses
99import logging
10- import pathlib
1110import shlex
1211import typing as t
1312import warnings
2221from libtmux .pane import Pane
2322
2423from . import exc
25- from .common import PaneDict , WindowOptionDict , handle_option_error , has_lt_version
26- from .formats import FORMAT_SEPARATOR
24+ from .common import PaneDict , WindowOptionDict , handle_option_error
2725
2826if t .TYPE_CHECKING :
2927 from .server import Server
@@ -207,9 +205,7 @@ def split(
207205 size : t .Optional [t .Union [str , int ]] = None ,
208206 environment : t .Optional [t .Dict [str , str ]] = None ,
209207 ) -> "Pane" :
210- """Split window and return the created :class:`Pane`.
211-
212- Used for splitting window and holding in a python object.
208+ """Split window on active pane and return the created :class:`Pane`.
213209
214210 Parameters
215211 ----------
@@ -218,8 +214,6 @@ def split(
218214 True.
219215 start_directory : str, optional
220216 specifies the working directory in which the new window is created.
221- target : str
222- ``target_pane`` to split.
223217 vertical : str
224218 split vertically
225219 shell : str, optional
@@ -253,74 +247,15 @@ def split(
253247
254248 ``percent=25`` deprecated in favor of ``size="25%"``.
255249 """
256- tmux_formats = ["#{pane_id}" + FORMAT_SEPARATOR ]
257-
258- tmux_args : t .Tuple [str , ...] = ()
259-
260- if target is not None :
261- tmux_args += ("-t%s" % target ,)
262- else :
263- active_pane = self .active_pane or self .panes [0 ]
264- if len (self .panes ):
265- tmux_args += (
266- f"-t{ self .session_id } :{ self .window_id } .{ active_pane .pane_index } " ,
267- )
268- else :
269- tmux_args += (f"-t{ self .session_id } :{ self .window_id } " ,)
270-
271- if vertical :
272- tmux_args += ("-v" ,)
273- else :
274- tmux_args += ("-h" ,)
275-
276- if size is not None :
277- if has_lt_version ("3.1" ):
278- if isinstance (size , str ) and size .endswith ("%" ):
279- tmux_args += (f'-p{ str (size ).rstrip ("%" )} ' ,)
280- else :
281- warnings .warn (
282- 'Ignored size. Use percent in tmux < 3.1, e.g. "size=50%"' ,
283- stacklevel = 2 ,
284- )
285- else :
286- tmux_args += (f"-l{ size } " ,)
287-
288- tmux_args += ("-P" , "-F%s" % "" .join (tmux_formats )) # output
289-
290- if start_directory is not None :
291- # as of 2014-02-08 tmux 1.9-dev doesn't expand ~ in new-window -c.
292- start_path = pathlib .Path (start_directory ).expanduser ()
293- tmux_args += (f"-c{ start_path } " ,)
294-
295- if not attach :
296- tmux_args += ("-d" ,)
297-
298- if environment :
299- if has_gte_version ("3.0" ):
300- for k , v in environment .items ():
301- tmux_args += (f"-e{ k } ={ v } " ,)
302- else :
303- logger .warning (
304- "Environment flag ignored, tmux 3.0 or newer required." ,
305- )
306-
307- if shell :
308- tmux_args += (shell ,)
309-
310- pane_cmd = self .cmd ("split-window" , * tmux_args )
311-
312- # tmux < 1.7. This is added in 1.7.
313- if pane_cmd .stderr :
314- if "pane too small" in pane_cmd .stderr :
315- raise exc .LibTmuxException (pane_cmd .stderr )
316-
317- raise exc .LibTmuxException (pane_cmd .stderr , self .__dict__ , self .panes )
318-
319- pane_output = pane_cmd .stdout [0 ]
320-
321- pane_formatters = dict (zip (["pane_id" ], pane_output .split (FORMAT_SEPARATOR )))
322-
323- return Pane .from_pane_id (server = self .server , pane_id = pane_formatters ["pane_id" ])
250+ active_pane = self .active_pane or self .panes [0 ]
251+ return active_pane .split (
252+ start_directory = start_directory ,
253+ attach = attach ,
254+ vertical = vertical ,
255+ shell = shell ,
256+ size = size ,
257+ environment = environment ,
258+ )
324259
325260 def resize (
326261 self ,
0 commit comments