Skip to content

Commit a0400e2

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

File tree

1 file changed

+90
-12
lines changed

1 file changed

+90
-12
lines changed

src/libtmux/window.py

Lines changed: 90 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
from libtmux._internal.query_list import QueryList
1515
from libtmux.common import has_gte_version, tmux_cmd
16+
from libtmux.constants import OPTION_SCOPE_FLAG_MAP, OptionScope
1617
from libtmux.neo import Obj, fetch_obj, fetch_objs
1718
from 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+
scope: t.Optional[OptionScope] = None,
357359
) -> "Window":
358360
"""Set option for tmux window.
359361
@@ -406,13 +408,18 @@ def set_option(
406408
assert isinstance(g, bool)
407409
flags.append("-g")
408410

411+
if scope is not None:
412+
assert scope in OPTION_SCOPE_FLAG_MAP
413+
flags.append(
414+
OPTION_SCOPE_FLAG_MAP[scope],
415+
)
416+
409417
cmd = self.cmd(
410418
"set-option",
411-
"-w",
412419
f"-t{self.session_id}:{self.window_index}",
420+
*flags,
413421
option,
414422
value,
415-
*flags,
416423
)
417424

418425
if isinstance(cmd.stderr, list) and len(cmd.stderr):
@@ -429,9 +436,52 @@ 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+
scope=OptionScope.Window,
442+
)
433443

434-
def show_options(self, g: t.Optional[bool] = False) -> "WindowOptionDict":
444+
@t.overload
445+
def show_options(
446+
self,
447+
g: t.Optional[bool],
448+
scope: t.Optional[OptionScope],
449+
include_hooks: t.Optional[bool],
450+
include_parents: t.Optional[bool],
451+
values_only: t.Literal[True],
452+
) -> t.List[str]:
453+
...
454+
455+
@t.overload
456+
def show_options(
457+
self,
458+
g: t.Optional[bool],
459+
scope: t.Optional[OptionScope],
460+
include_hooks: t.Optional[bool],
461+
include_parents: t.Optional[bool],
462+
values_only: t.Literal[None] = None,
463+
) -> "WindowOptionDict":
464+
...
465+
466+
@t.overload
467+
def show_options(
468+
self,
469+
g: t.Optional[bool] = None,
470+
scope: t.Optional[OptionScope] = None,
471+
include_hooks: t.Optional[bool] = None,
472+
include_parents: t.Optional[bool] = None,
473+
values_only: t.Literal[False] = False,
474+
) -> "WindowOptionDict":
475+
...
476+
477+
def show_options(
478+
self,
479+
g: t.Optional[bool] = False,
480+
scope: t.Optional[OptionScope] = OptionScope.Window,
481+
include_hooks: t.Optional[bool] = None,
482+
include_parents: t.Optional[bool] = None,
483+
values_only: t.Optional[bool] = False,
484+
) -> t.Union["WindowOptionDict", t.List[str]]:
435485
"""Return a dict of options for the window.
436486
437487
Parameters
@@ -444,11 +494,20 @@ def show_options(self, g: t.Optional[bool] = False) -> "WindowOptionDict":
444494
if g:
445495
tmux_args += ("-g",)
446496

447-
tmux_args += (
448-
"show-options",
449-
"-w-",
450-
)
451-
cmd = self.cmd(*tmux_args)
497+
if scope is not None:
498+
assert scope in OPTION_SCOPE_FLAG_MAP
499+
tmux_args += (OPTION_SCOPE_FLAG_MAP[scope],)
500+
501+
if include_parents is not None and include_parents:
502+
tmux_args += ("-A",)
503+
504+
if include_hooks is not None and include_hooks:
505+
tmux_args += ("-H",)
506+
507+
if values_only is not None and values_only:
508+
tmux_args += ("-v",)
509+
510+
cmd = self.cmd("show-options", *tmux_args)
452511

453512
output = cmd.stdout
454513

@@ -483,10 +542,19 @@ def show_window_option(
483542
484543
"""
485544
warnings.warn("Window.show_window_option() is deprecated", stacklevel=2)
486-
return self.show_option(option=option, g=g)
545+
return self.show_option(
546+
option=option,
547+
g=g,
548+
scope=OptionScope.Window,
549+
)
487550

488551
def show_option(
489-
self, option: str, g: bool = False
552+
self,
553+
option: str,
554+
g: bool = False,
555+
scope: t.Optional[OptionScope] = OptionScope.Window,
556+
include_hooks: t.Optional[bool] = None,
557+
include_parents: t.Optional[bool] = None,
490558
) -> t.Optional[t.Union[str, int]]:
491559
"""Return option value for the target window.
492560
@@ -508,9 +576,19 @@ def show_option(
508576
if g:
509577
tmux_args += ("-g",)
510578

579+
if scope is not None:
580+
assert scope in OPTION_SCOPE_FLAG_MAP
581+
tmux_args += (OPTION_SCOPE_FLAG_MAP[scope],)
582+
583+
if include_parents is not None and include_parents:
584+
tmux_args += ("-A",)
585+
586+
if include_hooks is not None and include_hooks:
587+
tmux_args += ("-H",)
588+
511589
tmux_args += (option,)
512590

513-
cmd = self.cmd("show-options", "-w", *tmux_args)
591+
cmd = self.cmd("show-options", *tmux_args)
514592

515593
if len(cmd.stderr):
516594
handle_option_error(cmd.stderr[0])

0 commit comments

Comments
 (0)