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_SCOPE_FLAG_MAP , OptionScope
16
17
from libtmux .neo import Obj , fetch_obj , fetch_objs
17
18
from libtmux .pane import Pane
18
19
@@ -353,6 +354,7 @@ def set_option(
353
354
suppress_warnings : t .Optional [bool ] = None ,
354
355
append : t .Optional [bool ] = None ,
355
356
g : t .Optional [bool ] = None ,
357
+ scope : t .Optional [OptionScope ] = None ,
356
358
) -> "Window" :
357
359
"""Set option for tmux window.
358
360
@@ -405,13 +407,18 @@ def set_option(
405
407
assert isinstance (g , bool )
406
408
flags .append ("-g" )
407
409
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
+
408
416
cmd = self .cmd (
409
417
"set-option" ,
410
- "-w" ,
411
418
f"-t{ self .session_id } :{ self .window_index } " ,
419
+ * flags ,
412
420
option ,
413
421
value ,
414
- * flags ,
415
422
)
416
423
417
424
if isinstance (cmd .stderr , list ) and len (cmd .stderr ):
@@ -428,9 +435,52 @@ def show_window_options(self, g: t.Optional[bool] = False) -> "WindowOptionDict"
428
435
429
436
"""
430
437
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
+ )
432
442
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 ]]:
434
484
"""Return a dict of options for the window.
435
485
436
486
Parameters
@@ -443,11 +493,20 @@ def show_options(self, g: t.Optional[bool] = False) -> "WindowOptionDict":
443
493
if g :
444
494
tmux_args += ("-g" ,)
445
495
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 )
451
510
452
511
output = cmd .stdout
453
512
@@ -482,10 +541,19 @@ def show_window_option(
482
541
483
542
"""
484
543
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
+ )
486
549
487
550
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 ,
489
557
) -> t .Optional [t .Union [str , int ]]:
490
558
"""Return option value for the target window.
491
559
@@ -507,9 +575,19 @@ def show_option(
507
575
if g :
508
576
tmux_args += ("-g" ,)
509
577
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
+
510
588
tmux_args += (option ,)
511
589
512
- cmd = self .cmd ("show-options" , "-w" , * tmux_args )
590
+ cmd = self .cmd ("show-options" , * tmux_args )
513
591
514
592
if len (cmd .stderr ):
515
593
handle_option_error (cmd .stderr [0 ])
0 commit comments