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_TYPE_FLAG_MAP , OptionType
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
+ option_type : t .Optional [OptionType ] = None ,
357
359
) -> "Window" :
358
360
"""Set option for tmux window.
359
361
@@ -406,9 +408,14 @@ def set_option(
406
408
assert isinstance (g , bool )
407
409
flags .append ("-g" )
408
410
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
+
409
417
cmd = self .cmd (
410
418
"set-option" ,
411
- "-w" ,
412
419
f"-t{ self .session_id } :{ self .window_index } " ,
413
420
option ,
414
421
value ,
@@ -429,9 +436,16 @@ 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
+ option_type = OptionType .Window ,
442
+ )
433
443
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" :
435
449
"""Return a dict of options for the window.
436
450
437
451
Parameters
@@ -444,11 +458,11 @@ def show_options(self, g: t.Optional[bool] = False) -> "WindowOptionDict":
444
458
if g :
445
459
tmux_args += ("-g" ,)
446
460
447
- tmux_args += (
448
- "show-options" ,
449
- "-w-" ,
450
- )
451
- cmd = self .cmd (* tmux_args )
461
+ if option_type is not None :
462
+ assert option_type in OPTION_TYPE_FLAG_MAP
463
+ tmux_args += ( OPTION_TYPE_FLAG_MAP [ option_type ],)
464
+
465
+ cmd = self .cmd ("show-options" , * tmux_args )
452
466
453
467
output = cmd .stdout
454
468
@@ -478,10 +492,17 @@ def show_window_option(
478
492
479
493
"""
480
494
warnings .warn ("Window.show_window_option() is deprecated" , stacklevel = 2 )
481
- return self .show_option (option = option , g = g )
495
+ return self .show_option (
496
+ option = option ,
497
+ g = g ,
498
+ option_type = OptionType .Window ,
499
+ )
482
500
483
501
def show_option (
484
- self , option : str , g : bool = False
502
+ self ,
503
+ option : str ,
504
+ g : bool = False ,
505
+ option_type : t .Optional [OptionType ] = None ,
485
506
) -> t .Optional [t .Union [str , int ]]:
486
507
"""Return option value for the target window.
487
508
@@ -503,9 +524,13 @@ def show_option(
503
524
if g :
504
525
tmux_args += ("-g" ,)
505
526
527
+ if option_type is not None :
528
+ assert option_type in OPTION_TYPE_FLAG_MAP
529
+ tmux_args += (OPTION_TYPE_FLAG_MAP [option_type ],)
530
+
506
531
tmux_args += (option ,)
507
532
508
- cmd = self .cmd ("show-options" , "-w" , * tmux_args )
533
+ cmd = self .cmd ("show-options" , * tmux_args )
509
534
510
535
if len (cmd .stderr ):
511
536
handle_option_error (cmd .stderr [0 ])
0 commit comments