7
7
8
8
import dataclasses
9
9
import logging
10
- import pathlib
11
10
import shlex
12
11
import typing as t
13
12
import warnings
22
21
from libtmux .pane import Pane
23
22
24
23
from . 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
27
25
28
26
if t .TYPE_CHECKING :
29
27
from .server import Server
@@ -207,9 +205,7 @@ def split(
207
205
size : t .Optional [t .Union [str , int ]] = None ,
208
206
environment : t .Optional [t .Dict [str , str ]] = None ,
209
207
) -> "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`.
213
209
214
210
Parameters
215
211
----------
@@ -218,8 +214,6 @@ def split(
218
214
True.
219
215
start_directory : str, optional
220
216
specifies the working directory in which the new window is created.
221
- target : str
222
- ``target_pane`` to split.
223
217
vertical : str
224
218
split vertically
225
219
shell : str, optional
@@ -253,74 +247,15 @@ def split(
253
247
254
248
``percent=25`` deprecated in favor of ``size="25%"``.
255
249
"""
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
+ )
324
259
325
260
def resize (
326
261
self ,
0 commit comments