1313
1414from libtmux ._internal .query_list import QueryList
1515from libtmux .common import has_gte_version , tmux_cmd
16+ from libtmux .constants import OPTION_SCOPE_FLAG_MAP , OptionScope
1617from libtmux .neo import Obj , fetch_obj , fetch_objs
1718from libtmux .pane import Pane
1819
@@ -353,6 +354,7 @@ def set_option(
353354 suppress_warnings : t .Optional [bool ] = None ,
354355 append : t .Optional [bool ] = None ,
355356 g : t .Optional [bool ] = None ,
357+ scope : t .Optional [OptionScope ] = None ,
356358 ) -> "Window" :
357359 """Set option for tmux window.
358360
@@ -405,13 +407,18 @@ def set_option(
405407 assert isinstance (g , bool )
406408 flags .append ("-g" )
407409
410+ if scope is not None :
411+ assert scope in OPTION_SCOPE_FLAG_MAP
412+ flags .append (
413+ OPTION_SCOPE_FLAG_MAP [scope ],
414+ )
415+
408416 cmd = self .cmd (
409417 "set-option" ,
410- "-w" ,
411418 f"-t{ self .session_id } :{ self .window_index } " ,
419+ * flags ,
412420 option ,
413421 value ,
414- * flags ,
415422 )
416423
417424 if isinstance (cmd .stderr , list ) and len (cmd .stderr ):
@@ -428,9 +435,52 @@ def show_window_options(self, g: t.Optional[bool] = False) -> "WindowOptionDict"
428435
429436 """
430437 warnings .warn ("Window.show_window_options() is deprecated" , stacklevel = 2 )
431- return self .show_options (g = g )
438+ return self .show_options (
439+ g = g ,
440+ scope = OptionScope .Window ,
441+ )
432442
433- def show_options (self , g : t .Optional [bool ] = False ) -> "WindowOptionDict" :
443+ @t .overload
444+ def show_options (
445+ self ,
446+ g : t .Optional [bool ],
447+ scope : t .Optional [OptionScope ],
448+ include_hooks : t .Optional [bool ],
449+ include_parents : t .Optional [bool ],
450+ values_only : t .Literal [True ],
451+ ) -> t .List [str ]:
452+ ...
453+
454+ @t .overload
455+ def show_options (
456+ self ,
457+ g : t .Optional [bool ],
458+ scope : t .Optional [OptionScope ],
459+ include_hooks : t .Optional [bool ],
460+ include_parents : t .Optional [bool ],
461+ values_only : t .Literal [None ] = None ,
462+ ) -> "WindowOptionDict" :
463+ ...
464+
465+ @t .overload
466+ def show_options (
467+ self ,
468+ g : t .Optional [bool ] = None ,
469+ scope : t .Optional [OptionScope ] = None ,
470+ include_hooks : t .Optional [bool ] = None ,
471+ include_parents : t .Optional [bool ] = None ,
472+ values_only : t .Literal [False ] = False ,
473+ ) -> "WindowOptionDict" :
474+ ...
475+
476+ def show_options (
477+ self ,
478+ g : t .Optional [bool ] = False ,
479+ scope : t .Optional [OptionScope ] = OptionScope .Window ,
480+ include_hooks : t .Optional [bool ] = None ,
481+ include_parents : t .Optional [bool ] = None ,
482+ values_only : t .Optional [bool ] = False ,
483+ ) -> t .Union ["WindowOptionDict" , t .List [str ]]:
434484 """Return a dict of options for the window.
435485
436486 Parameters
@@ -443,11 +493,20 @@ def show_options(self, g: t.Optional[bool] = False) -> "WindowOptionDict":
443493 if g :
444494 tmux_args += ("-g" ,)
445495
446- tmux_args += (
447- "show-options" ,
448- "-w-" ,
449- )
450- cmd = self .cmd (* tmux_args )
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+ if values_only is not None and values_only :
507+ tmux_args += ("-v" ,)
508+
509+ cmd = self .cmd ("show-options" , * tmux_args )
451510
452511 output = cmd .stdout
453512
@@ -482,10 +541,19 @@ def show_window_option(
482541
483542 """
484543 warnings .warn ("Window.show_window_option() is deprecated" , stacklevel = 2 )
485- return self .show_option (option = option , g = g )
544+ return self .show_option (
545+ option = option ,
546+ g = g ,
547+ scope = OptionScope .Window ,
548+ )
486549
487550 def show_option (
488- self , option : str , g : bool = False
551+ self ,
552+ option : str ,
553+ g : bool = False ,
554+ scope : t .Optional [OptionScope ] = OptionScope .Window ,
555+ include_hooks : t .Optional [bool ] = None ,
556+ include_parents : t .Optional [bool ] = None ,
489557 ) -> t .Optional [t .Union [str , int ]]:
490558 """Return option value for the target window.
491559
@@ -507,9 +575,19 @@ def show_option(
507575 if g :
508576 tmux_args += ("-g" ,)
509577
578+ if scope is not None :
579+ assert scope in OPTION_SCOPE_FLAG_MAP
580+ tmux_args += (OPTION_SCOPE_FLAG_MAP [scope ],)
581+
582+ if include_parents is not None and include_parents :
583+ tmux_args += ("-A" ,)
584+
585+ if include_hooks is not None and include_hooks :
586+ tmux_args += ("-H" ,)
587+
510588 tmux_args += (option ,)
511589
512- cmd = self .cmd ("show-options" , "-w" , * tmux_args )
590+ cmd = self .cmd ("show-options" , * tmux_args )
513591
514592 if len (cmd .stderr ):
515593 handle_option_error (cmd .stderr [0 ])
0 commit comments