16
16
from libtmux ._internal .query_list import QueryList
17
17
from libtmux .common import has_gte_version , tmux_cmd
18
18
from libtmux .constants import (
19
+ OPTION_SCOPE_FLAG_MAP ,
19
20
RESIZE_ADJUSTMENT_DIRECTION_FLAG_MAP ,
21
+ OptionScope ,
20
22
PaneDirection ,
21
23
ResizeAdjustmentDirection ,
22
24
WindowDirection ,
@@ -447,6 +449,7 @@ def set_option(
447
449
suppress_warnings : bool | None = None ,
448
450
append : bool | None = None ,
449
451
g : bool | None = None ,
452
+ scope : OptionScope | None = None ,
450
453
) -> Window :
451
454
"""Set option for tmux window.
452
455
@@ -499,20 +502,63 @@ def set_option(
499
502
assert isinstance (g , bool )
500
503
flags .append ("-g" )
501
504
505
+ if scope is not None :
506
+ assert scope in OPTION_SCOPE_FLAG_MAP
507
+ flags .append (
508
+ OPTION_SCOPE_FLAG_MAP [scope ],
509
+ )
510
+
502
511
cmd = self .cmd (
503
512
"set-option" ,
504
513
"-w" ,
514
+ * flags ,
505
515
option ,
506
516
value ,
507
- * flags ,
508
517
)
509
518
510
519
if isinstance (cmd .stderr , list ) and len (cmd .stderr ):
511
520
handle_option_error (cmd .stderr [0 ])
512
521
513
522
return self
514
523
515
- def show_options (self , g : bool | None = False ) -> WindowOptionDict :
524
+ @t .overload
525
+ def show_options (
526
+ self ,
527
+ g : bool | None ,
528
+ scope : OptionScope | None ,
529
+ include_hooks : bool | None ,
530
+ include_parents : bool | None ,
531
+ values_only : t .Literal [True ],
532
+ ) -> list [str ]: ...
533
+
534
+ @t .overload
535
+ def show_options (
536
+ self ,
537
+ g : bool | None ,
538
+ scope : OptionScope | None ,
539
+ include_hooks : bool | None ,
540
+ include_parents : bool | None ,
541
+ values_only : None = None ,
542
+ ) -> WindowOptionDict : ...
543
+
544
+ @t .overload
545
+ def show_options (
546
+ self ,
547
+ g : bool | None = None ,
548
+ scope : OptionScope | None = None ,
549
+ include_hooks : bool | None = None ,
550
+ include_parents : bool | None = None ,
551
+ values_only : t .Literal [False ] = False ,
552
+ ) -> WindowOptionDict : ...
553
+
554
+ def show_options (
555
+ self ,
556
+ g : bool | None = False ,
557
+ scope : OptionScope | None = OptionScope .Window ,
558
+ include_hooks : bool | None = None ,
559
+ include_parents : bool | None = None ,
560
+ values_only : bool | None = False ,
561
+ ) -> WindowOptionDict | list [str ]:
516
562
"""Return a dict of options for the window.
517
563
518
564
Parameters
@@ -525,11 +571,20 @@ def show_options(self, g: bool | None = False) -> WindowOptionDict:
525
571
if g :
526
572
tmux_args += ("-g" ,)
527
573
528
- tmux_args += (
529
- "show-options" ,
530
- "-w" ,
531
- )
532
- cmd = self .cmd (* tmux_args )
574
+ if scope is not None :
575
+ assert scope in OPTION_SCOPE_FLAG_MAP
576
+ tmux_args += (OPTION_SCOPE_FLAG_MAP [scope ],)
577
+
578
+ if include_parents is not None and include_parents :
579
+ tmux_args += ("-A" ,)
580
+
581
+ if include_hooks is not None and include_hooks :
582
+ tmux_args += ("-H" ,)
583
+
584
+ if values_only is not None and values_only :
585
+ tmux_args += ("-v" ,)
586
+
587
+ cmd = self .cmd ("show-options" , * tmux_args )
533
588
534
589
output = cmd .stdout
535
590
@@ -555,6 +610,9 @@ def show_option(
555
610
self ,
556
611
option : str ,
557
612
g : bool = False ,
613
+ scope : OptionScope | None = OptionScope .Window ,
614
+ include_hooks : bool | None = None ,
615
+ include_parents : bool | None = None ,
558
616
) -> str | int | None :
559
617
"""Return option value for the target window.
560
618
@@ -576,9 +634,19 @@ def show_option(
576
634
if g :
577
635
tmux_args += ("-g" ,)
578
636
637
+ if scope is not None :
638
+ assert scope in OPTION_SCOPE_FLAG_MAP
639
+ tmux_args += (OPTION_SCOPE_FLAG_MAP [scope ],)
640
+
641
+ if include_parents is not None and include_parents :
642
+ tmux_args += ("-A" ,)
643
+
644
+ if include_hooks is not None and include_hooks :
645
+ tmux_args += ("-H" ,)
646
+
579
647
tmux_args += (option ,)
580
648
581
- cmd = self .cmd ("show-options" , "-w" , * tmux_args )
649
+ cmd = self .cmd ("show-options" , * tmux_args )
582
650
583
651
if len (cmd .stderr ):
584
652
handle_option_error (cmd .stderr [0 ])
@@ -1044,7 +1112,10 @@ def show_window_options(self, g: bool | None = False) -> WindowOptionDict:
1044
1112
category = DeprecationWarning ,
1045
1113
stacklevel = 2 ,
1046
1114
)
1047
- return self .show_options (g = g )
1115
+ return self .show_options (
1116
+ g = g ,
1117
+ scope = OptionScope .Window ,
1118
+ )
1048
1119
1049
1120
def show_window_option (
1050
1121
self ,
@@ -1063,7 +1134,11 @@ def show_window_option(
1063
1134
category = DeprecationWarning ,
1064
1135
stacklevel = 2 ,
1065
1136
)
1066
- return self .show_option (option = option , g = g )
1137
+ return self .show_option (
1138
+ option = option ,
1139
+ g = g ,
1140
+ scope = OptionScope .Window ,
1141
+ )
1067
1142
1068
1143
def get (self , key : str , default : t .Any | None = None ) -> t .Any :
1069
1144
"""Return key-based lookup. Deprecated by attributes.
0 commit comments