1313
1414from libtmux ._internal .query_list import QueryList
1515from libtmux .common import has_gte_version , tmux_cmd
16+ from libtmux .constants import OPTION_TYPE_FLAG_MAP , OptionType
1617from libtmux .neo import Obj , fetch_obj , fetch_objs
1718from libtmux .pane import Pane
1819
@@ -354,6 +355,7 @@ def set_option(
354355 suppress_warnings : t .Optional [bool ] = None ,
355356 append : t .Optional [bool ] = None ,
356357 g : t .Optional [bool ] = None ,
358+ option_type : t .Optional [OptionType ] = None ,
357359 ) -> "Window" :
358360 """Set option for tmux window.
359361
@@ -406,9 +408,14 @@ def set_option(
406408 assert isinstance (g , bool )
407409 flags .append ("-g" )
408410
411+ if option_type is not None :
412+ assert option_type in OPTION_TYPE_FLAG_MAP
413+ flags .append (
414+ OPTION_TYPE_FLAG_MAP [option_type ],
415+ )
416+
409417 cmd = self .cmd (
410418 "set-option" ,
411- "-w" ,
412419 f"-t{ self .session_id } :{ self .window_index } " ,
413420 option ,
414421 value ,
@@ -429,9 +436,16 @@ def show_window_options(self, g: t.Optional[bool] = False) -> "WindowOptionDict"
429436
430437 """
431438 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+ option_type = OptionType .Window ,
442+ )
433443
434- def show_options (self , g : t .Optional [bool ] = False ) -> "WindowOptionDict" :
444+ def show_options (
445+ self ,
446+ g : t .Optional [bool ] = False ,
447+ option_type : t .Optional [OptionType ] = None ,
448+ ) -> "WindowOptionDict" :
435449 """Return a dict of options for the window.
436450
437451 For familiarity with tmux, the option ``option`` param forwards to pick a
@@ -451,11 +465,11 @@ def show_options(self, g: t.Optional[bool] = False) -> "WindowOptionDict":
451465 if g :
452466 tmux_args += ("-g" ,)
453467
454- tmux_args += (
455- "show-options" ,
456- "-w-" ,
457- )
458- cmd = self .cmd (* tmux_args )
468+ if option_type is not None :
469+ assert option_type in OPTION_TYPE_FLAG_MAP
470+ tmux_args += ( OPTION_TYPE_FLAG_MAP [ option_type ],)
471+
472+ cmd = self .cmd ("show-options" , * tmux_args )
459473
460474 output = cmd .stdout
461475
@@ -485,10 +499,17 @@ def show_window_option(
485499
486500 """
487501 warnings .warn ("Window.show_window_option() is deprecated" , stacklevel = 2 )
488- return self .show_option (option = option , g = g )
502+ return self .show_option (
503+ option = option ,
504+ g = g ,
505+ option_type = OptionType .Window ,
506+ )
489507
490508 def show_option (
491- self , option : str , g : bool = False
509+ self ,
510+ option : str ,
511+ g : bool = False ,
512+ option_type : t .Optional [OptionType ] = None ,
492513 ) -> t .Optional [t .Union [str , int ]]:
493514 """Return option value for the target window.
494515
@@ -510,9 +531,13 @@ def show_option(
510531 if g :
511532 tmux_args += ("-g" ,)
512533
534+ if option_type is not None :
535+ assert option_type in OPTION_TYPE_FLAG_MAP
536+ tmux_args += (OPTION_TYPE_FLAG_MAP [option_type ],)
537+
513538 tmux_args += (option ,)
514539
515- cmd = self .cmd ("show-options" , "-w" , * tmux_args )
540+ cmd = self .cmd ("show-options" , * tmux_args )
516541
517542 if len (cmd .stderr ):
518543 handle_option_error (cmd .stderr [0 ])
0 commit comments