1616from libtmux ._internal .query_list import QueryList
1717from libtmux .common import has_gte_version , tmux_cmd
1818from libtmux .constants import (
19+ OPTION_SCOPE_FLAG_MAP ,
1920 RESIZE_ADJUSTMENT_DIRECTION_FLAG_MAP ,
21+ OptionScope ,
2022 PaneDirection ,
2123 ResizeAdjustmentDirection ,
2224 WindowDirection ,
@@ -449,6 +451,7 @@ def set_option(
449451 suppress_warnings : bool | None = None ,
450452 append : bool | None = None ,
451453 g : bool | None = None ,
454+ scope : OptionScope | None = None ,
452455 ) -> Window :
453456 """Set option for tmux window.
454457
@@ -501,20 +504,63 @@ def set_option(
501504 assert isinstance (g , bool )
502505 flags .append ("-g" )
503506
507+ if scope is not None :
508+ assert scope in OPTION_SCOPE_FLAG_MAP
509+ flags .append (
510+ OPTION_SCOPE_FLAG_MAP [scope ],
511+ )
512+
504513 cmd = self .cmd (
505514 "set-option" ,
506515 "-w" ,
516+ * flags ,
507517 option ,
508518 value ,
509- * flags ,
510519 )
511520
512521 if isinstance (cmd .stderr , list ) and len (cmd .stderr ):
513522 handle_option_error (cmd .stderr [0 ])
514523
515524 return self
516525
517- def show_options (self , g : bool | None = False ) -> WindowOptionDict :
526+ @t .overload
527+ def show_options (
528+ self ,
529+ g : bool | None ,
530+ scope : OptionScope | None ,
531+ include_hooks : bool | None ,
532+ include_parents : bool | None ,
533+ values_only : t .Literal [True ],
534+ ) -> list [str ]: ...
535+
536+ @t .overload
537+ def show_options (
538+ self ,
539+ g : bool | None ,
540+ scope : OptionScope | None ,
541+ include_hooks : bool | None ,
542+ include_parents : bool | None ,
543+ values_only : None = None ,
544+ ) -> WindowOptionDict : ...
545+
546+ @t .overload
547+ def show_options (
548+ self ,
549+ g : bool | None = None ,
550+ scope : OptionScope | None = None ,
551+ include_hooks : bool | None = None ,
552+ include_parents : bool | None = None ,
553+ values_only : t .Literal [False ] = False ,
554+ ) -> WindowOptionDict : ...
555+
556+ def show_options (
557+ self ,
558+ g : bool | None = False ,
559+ scope : OptionScope | None = OptionScope .Window ,
560+ include_hooks : bool | None = None ,
561+ include_parents : bool | None = None ,
562+ values_only : bool | None = False ,
563+ ) -> WindowOptionDict | list [str ]:
518564 """Return a dict of options for the window.
519565
520566 Parameters
@@ -527,11 +573,20 @@ def show_options(self, g: bool | None = False) -> WindowOptionDict:
527573 if g :
528574 tmux_args += ("-g" ,)
529575
530- tmux_args += (
531- "show-options" ,
532- "-w" ,
533- )
534- cmd = self .cmd (* tmux_args )
576+ if scope is not None :
577+ assert scope in OPTION_SCOPE_FLAG_MAP
578+ tmux_args += (OPTION_SCOPE_FLAG_MAP [scope ],)
579+
580+ if include_parents is not None and include_parents :
581+ tmux_args += ("-A" ,)
582+
583+ if include_hooks is not None and include_hooks :
584+ tmux_args += ("-H" ,)
585+
586+ if values_only is not None and values_only :
587+ tmux_args += ("-v" ,)
588+
589+ cmd = self .cmd ("show-options" , * tmux_args )
535590
536591 output = cmd .stdout
537592
@@ -557,6 +612,9 @@ def show_option(
557612 self ,
558613 option : str ,
559614 g : bool = False ,
615+ scope : OptionScope | None = OptionScope .Window ,
616+ include_hooks : bool | None = None ,
617+ include_parents : bool | None = None ,
560618 ) -> str | int | None :
561619 """Return option value for the target window.
562620
@@ -578,9 +636,19 @@ def show_option(
578636 if g :
579637 tmux_args += ("-g" ,)
580638
639+ if scope is not None :
640+ assert scope in OPTION_SCOPE_FLAG_MAP
641+ tmux_args += (OPTION_SCOPE_FLAG_MAP [scope ],)
642+
643+ if include_parents is not None and include_parents :
644+ tmux_args += ("-A" ,)
645+
646+ if include_hooks is not None and include_hooks :
647+ tmux_args += ("-H" ,)
648+
581649 tmux_args += (option ,)
582650
583- cmd = self .cmd ("show-options" , "-w" , * tmux_args )
651+ cmd = self .cmd ("show-options" , * tmux_args )
584652
585653 if len (cmd .stderr ):
586654 handle_option_error (cmd .stderr [0 ])
@@ -1046,7 +1114,10 @@ def show_window_options(self, g: bool | None = False) -> WindowOptionDict:
10461114 category = DeprecationWarning ,
10471115 stacklevel = 2 ,
10481116 )
1049- return self .show_options (g = g )
1117+ return self .show_options (
1118+ g = g ,
1119+ scope = OptionScope .Window ,
1120+ )
10501121
10511122 def show_window_option (
10521123 self ,
@@ -1065,7 +1136,11 @@ def show_window_option(
10651136 category = DeprecationWarning ,
10661137 stacklevel = 2 ,
10671138 )
1068- return self .show_option (option = option , g = g )
1139+ return self .show_option (
1140+ option = option ,
1141+ g = g ,
1142+ scope = OptionScope .Window ,
1143+ )
10691144
10701145 def get (self , key : str , default : t .Any | None = None ) -> t .Any :
10711146 """Return key-based lookup. Deprecated by attributes.
0 commit comments