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
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":
451
465
if g :
452
466
tmux_args += ("-g" ,)
453
467
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 )
459
473
460
474
output = cmd .stdout
461
475
@@ -485,10 +499,17 @@ def show_window_option(
485
499
486
500
"""
487
501
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
+ )
489
507
490
508
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 ,
492
513
) -> t .Optional [t .Union [str , int ]]:
493
514
"""Return option value for the target window.
494
515
@@ -510,9 +531,13 @@ def show_option(
510
531
if g :
511
532
tmux_args += ("-g" ,)
512
533
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
+
513
538
tmux_args += (option ,)
514
539
515
- cmd = self .cmd ("show-options" , "-w" , * tmux_args )
540
+ cmd = self .cmd ("show-options" , * tmux_args )
516
541
517
542
if len (cmd .stderr ):
518
543
handle_option_error (cmd .stderr [0 ])
0 commit comments