13
13
14
14
from libtmux ._internal .query_list import QueryList
15
15
from libtmux .common import has_gte_version , tmux_cmd
16
- from libtmux .constants import OPTION_SCOPE_FLAG_MAP , OptionScope
16
+ from libtmux .constants import OptionScope
17
17
from libtmux .neo import Obj , fetch_obj , fetch_objs
18
18
from libtmux .pane import Pane
19
19
20
20
from . import exc
21
- from .common import OptionMixin , PaneDict , WindowOptionDict , handle_option_error
21
+ from .common import OptionMixin , PaneDict , WindowOptionDict
22
22
from .formats import FORMAT_SEPARATOR
23
23
24
24
if t .TYPE_CHECKING :
@@ -358,94 +358,6 @@ def show_window_options(self, g: t.Optional[bool] = False) -> "WindowOptionDict"
358
358
scope = OptionScope .Window ,
359
359
)
360
360
361
- @t .overload
362
- def show_options (
363
- self ,
364
- g : t .Optional [bool ],
365
- scope : t .Optional [OptionScope ],
366
- include_hooks : t .Optional [bool ],
367
- include_parents : t .Optional [bool ],
368
- values_only : t .Literal [True ],
369
- ) -> t .List [str ]:
370
- ...
371
-
372
- @t .overload
373
- def show_options (
374
- self ,
375
- g : t .Optional [bool ],
376
- scope : t .Optional [OptionScope ],
377
- include_hooks : t .Optional [bool ],
378
- include_parents : t .Optional [bool ],
379
- values_only : t .Literal [None ] = None ,
380
- ) -> "WindowOptionDict" :
381
- ...
382
-
383
- @t .overload
384
- def show_options (
385
- self ,
386
- g : t .Optional [bool ] = None ,
387
- scope : t .Optional [OptionScope ] = None ,
388
- include_hooks : t .Optional [bool ] = None ,
389
- include_parents : t .Optional [bool ] = None ,
390
- values_only : t .Literal [False ] = False ,
391
- ) -> "WindowOptionDict" :
392
- ...
393
-
394
- def show_options (
395
- self ,
396
- g : t .Optional [bool ] = False ,
397
- scope : t .Optional [OptionScope ] = OptionScope .Window ,
398
- include_hooks : t .Optional [bool ] = None ,
399
- include_parents : t .Optional [bool ] = None ,
400
- values_only : t .Optional [bool ] = False ,
401
- ) -> t .Union ["WindowOptionDict" , t .List [str ]]:
402
- """Return a dict of options for the window.
403
-
404
- Parameters
405
- ----------
406
- g : str, optional
407
- Pass ``-g`` flag for global variable, default False.
408
- """
409
- tmux_args : t .Tuple [str , ...] = ()
410
-
411
- if g :
412
- tmux_args += ("-g" ,)
413
-
414
- if scope is not None :
415
- assert scope in OPTION_SCOPE_FLAG_MAP
416
- tmux_args += (OPTION_SCOPE_FLAG_MAP [scope ],)
417
-
418
- if include_parents is not None and include_parents :
419
- tmux_args += ("-A" ,)
420
-
421
- if include_hooks is not None and include_hooks :
422
- tmux_args += ("-H" ,)
423
-
424
- if values_only is not None and values_only :
425
- tmux_args += ("-v" ,)
426
-
427
- cmd = self .cmd ("show-options" , * tmux_args )
428
-
429
- output = cmd .stdout
430
-
431
- # The shlex.split function splits the args at spaces, while also
432
- # retaining quoted sub-strings.
433
- # shlex.split('this is "a test"') => ['this', 'is', 'a test']
434
-
435
- window_options : "WindowOptionDict" = {}
436
- for item in output :
437
- try :
438
- key , val = shlex .split (item )
439
- except ValueError :
440
- logger .exception (f"Error extracting option: { item } " )
441
- assert isinstance (key , str )
442
- assert isinstance (val , str )
443
-
444
- if isinstance (val , str ) and val .isdigit ():
445
- window_options [key ] = int (val )
446
-
447
- return window_options
448
-
449
361
def show_window_option (
450
362
self ,
451
363
option : str ,
@@ -465,64 +377,6 @@ def show_window_option(
465
377
scope = OptionScope .Window ,
466
378
)
467
379
468
- def show_option (
469
- self ,
470
- option : str ,
471
- g : bool = False ,
472
- scope : t .Optional [OptionScope ] = OptionScope .Window ,
473
- include_hooks : t .Optional [bool ] = None ,
474
- include_parents : t .Optional [bool ] = None ,
475
- ) -> t .Optional [t .Union [str , int ]]:
476
- """Return option value for the target window.
477
-
478
- todo: test and return True/False for on/off string
479
-
480
- Parameters
481
- ----------
482
- option : str
483
- g : bool, optional
484
- Pass ``-g`` flag, global. Default False.
485
-
486
- Raises
487
- ------
488
- :exc:`exc.OptionError`, :exc:`exc.UnknownOption`,
489
- :exc:`exc.InvalidOption`, :exc:`exc.AmbiguousOption`
490
- """
491
- tmux_args : t .Tuple [t .Union [str , int ], ...] = ()
492
-
493
- if g :
494
- tmux_args += ("-g" ,)
495
-
496
- if scope is not None :
497
- assert scope in OPTION_SCOPE_FLAG_MAP
498
- tmux_args += (OPTION_SCOPE_FLAG_MAP [scope ],)
499
-
500
- if include_parents is not None and include_parents :
501
- tmux_args += ("-A" ,)
502
-
503
- if include_hooks is not None and include_hooks :
504
- tmux_args += ("-H" ,)
505
-
506
- tmux_args += (option ,)
507
-
508
- cmd = self .cmd ("show-options" , * tmux_args )
509
-
510
- if len (cmd .stderr ):
511
- handle_option_error (cmd .stderr [0 ])
512
-
513
- window_options_output = cmd .stdout
514
-
515
- if not len (window_options_output ):
516
- return None
517
-
518
- value_raw = next (shlex .split (item ) for item in window_options_output )
519
-
520
- value : t .Union [str , int ] = (
521
- int (value_raw [1 ]) if value_raw [1 ].isdigit () else value_raw [1 ]
522
- )
523
-
524
- return value
525
-
526
380
def rename_window (self , new_name : str ) -> "Window" :
527
381
"""Rename window.
528
382
@@ -541,8 +395,6 @@ def rename_window(self, new_name: str) -> "Window":
541
395
>>> window.rename_window('New name')
542
396
Window(@1 1:New name, Session($1 ...))
543
397
"""
544
- import shlex
545
-
546
398
lex = shlex .shlex (new_name )
547
399
lex .escape = " "
548
400
lex .whitespace_split = False
0 commit comments