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
17
from libtmux .neo import Obj , fetch_obj , fetch_objs
17
18
from libtmux .pane import Pane
18
19
@@ -354,6 +355,7 @@ def set_option(
354
355
suppress_warnings : t .Optional [bool ] = None ,
355
356
append : t .Optional [bool ] = None ,
356
357
g : t .Optional [bool ] = None ,
358
+ scope : t .Optional [OptionScope ] = None ,
357
359
) -> "Window" :
358
360
"""Set option for tmux window.
359
361
@@ -406,13 +408,18 @@ def set_option(
406
408
assert isinstance (g , bool )
407
409
flags .append ("-g" )
408
410
411
+ if scope is not None :
412
+ assert scope in OPTION_SCOPE_FLAG_MAP
413
+ flags .append (
414
+ OPTION_SCOPE_FLAG_MAP [scope ],
415
+ )
416
+
409
417
cmd = self .cmd (
410
418
"set-option" ,
411
- "-w" ,
412
419
f"-t{ self .session_id } :{ self .window_index } " ,
420
+ * flags ,
413
421
option ,
414
422
value ,
415
- * flags ,
416
423
)
417
424
418
425
if isinstance (cmd .stderr , list ) and len (cmd .stderr ):
@@ -429,9 +436,52 @@ def show_window_options(self, g: t.Optional[bool] = False) -> "WindowOptionDict"
429
436
430
437
"""
431
438
warnings .warn ("Window.show_window_options() is deprecated" , stacklevel = 2 )
432
- return self .show_options (g = g )
439
+ return self .show_options (
440
+ g = g ,
441
+ scope = OptionScope .Window ,
442
+ )
433
443
434
- def show_options (self , g : t .Optional [bool ] = False ) -> "WindowOptionDict" :
444
+ @t .overload
445
+ def show_options (
446
+ self ,
447
+ g : t .Optional [bool ],
448
+ scope : t .Optional [OptionScope ],
449
+ include_hooks : t .Optional [bool ],
450
+ include_parents : t .Optional [bool ],
451
+ values_only : t .Literal [True ],
452
+ ) -> t .List [str ]:
453
+ ...
454
+
455
+ @t .overload
456
+ def show_options (
457
+ self ,
458
+ g : t .Optional [bool ],
459
+ scope : t .Optional [OptionScope ],
460
+ include_hooks : t .Optional [bool ],
461
+ include_parents : t .Optional [bool ],
462
+ values_only : t .Literal [None ] = None ,
463
+ ) -> "WindowOptionDict" :
464
+ ...
465
+
466
+ @t .overload
467
+ def show_options (
468
+ self ,
469
+ g : t .Optional [bool ] = None ,
470
+ scope : t .Optional [OptionScope ] = None ,
471
+ include_hooks : t .Optional [bool ] = None ,
472
+ include_parents : t .Optional [bool ] = None ,
473
+ values_only : t .Literal [False ] = False ,
474
+ ) -> "WindowOptionDict" :
475
+ ...
476
+
477
+ def show_options (
478
+ self ,
479
+ g : t .Optional [bool ] = False ,
480
+ scope : t .Optional [OptionScope ] = OptionScope .Window ,
481
+ include_hooks : t .Optional [bool ] = None ,
482
+ include_parents : t .Optional [bool ] = None ,
483
+ values_only : t .Optional [bool ] = False ,
484
+ ) -> t .Union ["WindowOptionDict" , t .List [str ]]:
435
485
"""Return a dict of options for the window.
436
486
437
487
Parameters
@@ -444,11 +494,20 @@ def show_options(self, g: t.Optional[bool] = False) -> "WindowOptionDict":
444
494
if g :
445
495
tmux_args += ("-g" ,)
446
496
447
- tmux_args += (
448
- "show-options" ,
449
- "-w-" ,
450
- )
451
- cmd = self .cmd (* tmux_args )
497
+ if scope is not None :
498
+ assert scope in OPTION_SCOPE_FLAG_MAP
499
+ tmux_args += (OPTION_SCOPE_FLAG_MAP [scope ],)
500
+
501
+ if include_parents is not None and include_parents :
502
+ tmux_args += ("-A" ,)
503
+
504
+ if include_hooks is not None and include_hooks :
505
+ tmux_args += ("-H" ,)
506
+
507
+ if values_only is not None and values_only :
508
+ tmux_args += ("-v" ,)
509
+
510
+ cmd = self .cmd ("show-options" , * tmux_args )
452
511
453
512
output = cmd .stdout
454
513
@@ -483,10 +542,19 @@ def show_window_option(
483
542
484
543
"""
485
544
warnings .warn ("Window.show_window_option() is deprecated" , stacklevel = 2 )
486
- return self .show_option (option = option , g = g )
545
+ return self .show_option (
546
+ option = option ,
547
+ g = g ,
548
+ scope = OptionScope .Window ,
549
+ )
487
550
488
551
def show_option (
489
- self , option : str , g : bool = False
552
+ self ,
553
+ option : str ,
554
+ g : bool = False ,
555
+ scope : t .Optional [OptionScope ] = OptionScope .Window ,
556
+ include_hooks : t .Optional [bool ] = None ,
557
+ include_parents : t .Optional [bool ] = None ,
490
558
) -> t .Optional [t .Union [str , int ]]:
491
559
"""Return option value for the target window.
492
560
@@ -508,9 +576,19 @@ def show_option(
508
576
if g :
509
577
tmux_args += ("-g" ,)
510
578
579
+ if scope is not None :
580
+ assert scope in OPTION_SCOPE_FLAG_MAP
581
+ tmux_args += (OPTION_SCOPE_FLAG_MAP [scope ],)
582
+
583
+ if include_parents is not None and include_parents :
584
+ tmux_args += ("-A" ,)
585
+
586
+ if include_hooks is not None and include_hooks :
587
+ tmux_args += ("-H" ,)
588
+
511
589
tmux_args += (option ,)
512
590
513
- cmd = self .cmd ("show-options" , "-w" , * tmux_args )
591
+ cmd = self .cmd ("show-options" , * tmux_args )
514
592
515
593
if len (cmd .stderr ):
516
594
handle_option_error (cmd .stderr [0 ])
0 commit comments