Skip to content

Commit ff9a760

Browse files
committed
feat(Window): scope param for Window.{set,show}_option
1 parent ca39170 commit ff9a760

File tree

1 file changed

+85
-10
lines changed

1 file changed

+85
-10
lines changed

src/libtmux/window.py

Lines changed: 85 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
from libtmux._internal.query_list import QueryList
1717
from libtmux.common import has_gte_version, tmux_cmd
1818
from libtmux.constants import (
19+
OPTION_SCOPE_FLAG_MAP,
1920
RESIZE_ADJUSTMENT_DIRECTION_FLAG_MAP,
21+
OptionScope,
2022
PaneDirection,
2123
ResizeAdjustmentDirection,
2224
WindowDirection,
@@ -447,6 +449,7 @@ def set_option(
447449
suppress_warnings: bool | None = None,
448450
append: bool | None = None,
449451
g: bool | None = None,
452+
scope: OptionScope | None = None,
450453
) -> Window:
451454
"""Set option for tmux window.
452455
@@ -499,20 +502,63 @@ def set_option(
499502
assert isinstance(g, bool)
500503
flags.append("-g")
501504

505+
if scope is not None:
506+
assert scope in OPTION_SCOPE_FLAG_MAP
507+
flags.append(
508+
OPTION_SCOPE_FLAG_MAP[scope],
509+
)
510+
502511
cmd = self.cmd(
503512
"set-option",
504513
"-w",
514+
*flags,
505515
option,
506516
value,
507-
*flags,
508517
)
509518

510519
if isinstance(cmd.stderr, list) and len(cmd.stderr):
511520
handle_option_error(cmd.stderr[0])
512521

513522
return self
514523

515-
def show_options(self, g: bool | None = False) -> WindowOptionDict:
524+
@t.overload
525+
def show_options(
526+
self,
527+
g: bool | None,
528+
scope: OptionScope | None,
529+
include_hooks: bool | None,
530+
include_parents: bool | None,
531+
values_only: t.Literal[True],
532+
) -> list[str]: ...
533+
534+
@t.overload
535+
def show_options(
536+
self,
537+
g: bool | None,
538+
scope: OptionScope | None,
539+
include_hooks: bool | None,
540+
include_parents: bool | None,
541+
values_only: None = None,
542+
) -> WindowOptionDict: ...
543+
544+
@t.overload
545+
def show_options(
546+
self,
547+
g: bool | None = None,
548+
scope: OptionScope | None = None,
549+
include_hooks: bool | None = None,
550+
include_parents: bool | None = None,
551+
values_only: t.Literal[False] = False,
552+
) -> WindowOptionDict: ...
553+
554+
def show_options(
555+
self,
556+
g: bool | None = False,
557+
scope: OptionScope | None = OptionScope.Window,
558+
include_hooks: bool | None = None,
559+
include_parents: bool | None = None,
560+
values_only: bool | None = False,
561+
) -> WindowOptionDict | list[str]:
516562
"""Return a dict of options for the window.
517563
518564
Parameters
@@ -525,11 +571,20 @@ def show_options(self, g: bool | None = False) -> WindowOptionDict:
525571
if g:
526572
tmux_args += ("-g",)
527573

528-
tmux_args += (
529-
"show-options",
530-
"-w",
531-
)
532-
cmd = self.cmd(*tmux_args)
574+
if scope is not None:
575+
assert scope in OPTION_SCOPE_FLAG_MAP
576+
tmux_args += (OPTION_SCOPE_FLAG_MAP[scope],)
577+
578+
if include_parents is not None and include_parents:
579+
tmux_args += ("-A",)
580+
581+
if include_hooks is not None and include_hooks:
582+
tmux_args += ("-H",)
583+
584+
if values_only is not None and values_only:
585+
tmux_args += ("-v",)
586+
587+
cmd = self.cmd("show-options", *tmux_args)
533588

534589
output = cmd.stdout
535590

@@ -555,6 +610,9 @@ def show_option(
555610
self,
556611
option: str,
557612
g: bool = False,
613+
scope: OptionScope | None = OptionScope.Window,
614+
include_hooks: bool | None = None,
615+
include_parents: bool | None = None,
558616
) -> str | int | None:
559617
"""Return option value for the target window.
560618
@@ -576,9 +634,19 @@ def show_option(
576634
if g:
577635
tmux_args += ("-g",)
578636

637+
if scope is not None:
638+
assert scope in OPTION_SCOPE_FLAG_MAP
639+
tmux_args += (OPTION_SCOPE_FLAG_MAP[scope],)
640+
641+
if include_parents is not None and include_parents:
642+
tmux_args += ("-A",)
643+
644+
if include_hooks is not None and include_hooks:
645+
tmux_args += ("-H",)
646+
579647
tmux_args += (option,)
580648

581-
cmd = self.cmd("show-options", "-w", *tmux_args)
649+
cmd = self.cmd("show-options", *tmux_args)
582650

583651
if len(cmd.stderr):
584652
handle_option_error(cmd.stderr[0])
@@ -1044,7 +1112,10 @@ def show_window_options(self, g: bool | None = False) -> WindowOptionDict:
10441112
category=DeprecationWarning,
10451113
stacklevel=2,
10461114
)
1047-
return self.show_options(g=g)
1115+
return self.show_options(
1116+
g=g,
1117+
scope=OptionScope.Window,
1118+
)
10481119

10491120
def show_window_option(
10501121
self,
@@ -1063,7 +1134,11 @@ def show_window_option(
10631134
category=DeprecationWarning,
10641135
stacklevel=2,
10651136
)
1066-
return self.show_option(option=option, g=g)
1137+
return self.show_option(
1138+
option=option,
1139+
g=g,
1140+
scope=OptionScope.Window,
1141+
)
10671142

10681143
def get(self, key: str, default: t.Any | None = None) -> t.Any:
10691144
"""Return key-based lookup. Deprecated by attributes.

0 commit comments

Comments
 (0)