21
21
from libtmux .pane import Pane
22
22
23
23
from . import exc
24
- from .common import PaneDict , WindowOptionDict , handle_option_error
24
+ from .common import PaneDict , WindowOptionDict , handle_option_error , has_lt_version
25
25
from .formats import FORMAT_SEPARATOR
26
26
27
27
if t .TYPE_CHECKING :
@@ -184,7 +184,8 @@ def split_window(
184
184
attach : bool = False ,
185
185
vertical : bool = True ,
186
186
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
188
189
environment : t .Optional [t .Dict [str , str ]] = None ,
189
190
) -> "Pane" :
190
191
"""Split window and return the created :class:`Pane`.
@@ -209,8 +210,11 @@ def split_window(
209
210
NOTE: When this command exits the pane will close. This feature
210
211
is useful for long-running processes where the closing of the
211
212
window upon completion is desired.
213
+ size: int, optional
214
+ Cell/row or percentage to occupy with respect to current window.
212
215
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.
214
218
environment: dict, optional
215
219
Environmental variables for new pane. tmux 3.0+ only. Passthrough to ``-e``.
216
220
@@ -228,6 +232,10 @@ def split_window(
228
232
.. versionchanged:: 0.28.0
229
233
230
234
``attach`` default changed from ``True`` to ``False``.
235
+
236
+ .. deprecated:: 0.28.0
237
+
238
+ ``percent=25`` deprecated in favor of ``size="25%"``.
231
239
"""
232
240
tmux_formats = ["#{pane_id}" + FORMAT_SEPARATOR ]
233
241
@@ -248,9 +256,28 @@ def split_window(
248
256
else :
249
257
tmux_args += ("-h" ,)
250
258
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
+
251
271
if percent is not None :
252
272
# 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
+
254
281
tmux_args += ("-P" , "-F%s" % "" .join (tmux_formats )) # output
255
282
256
283
if start_directory is not None :
0 commit comments