Skip to content

Commit f62e443

Browse files
committed
feat(Window): option_type param for Window.{set,show}_option
1 parent d941d81 commit f62e443

File tree

1 file changed

+36
-11
lines changed

1 file changed

+36
-11
lines changed

src/libtmux/window.py

Lines changed: 36 additions & 11 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_TYPE_FLAG_MAP, OptionType
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+
option_type: t.Optional[OptionType] = None,
357359
) -> "Window":
358360
"""Set option for tmux window.
359361
@@ -406,9 +408,14 @@ def set_option(
406408
assert isinstance(g, bool)
407409
flags.append("-g")
408410

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+
409417
cmd = self.cmd(
410418
"set-option",
411-
"-w",
412419
f"-t{self.session_id}:{self.window_index}",
413420
option,
414421
value,
@@ -429,9 +436,16 @@ 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+
option_type=OptionType.Window,
442+
)
433443

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":
435449
"""Return a dict of options for the window.
436450
437451
Parameters
@@ -444,11 +458,11 @@ def show_options(self, g: t.Optional[bool] = False) -> "WindowOptionDict":
444458
if g:
445459
tmux_args += ("-g",)
446460

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)
452466

453467
output = cmd.stdout
454468

@@ -478,10 +492,17 @@ def show_window_option(
478492
479493
"""
480494
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+
)
482500

483501
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,
485506
) -> t.Optional[t.Union[str, int]]:
486507
"""Return option value for the target window.
487508
@@ -503,9 +524,13 @@ def show_option(
503524
if g:
504525
tmux_args += ("-g",)
505526

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+
506531
tmux_args += (option,)
507532

508-
cmd = self.cmd("show-options", "-w", *tmux_args)
533+
cmd = self.cmd("show-options", *tmux_args)
509534

510535
if len(cmd.stderr):
511536
handle_option_error(cmd.stderr[0])

0 commit comments

Comments
 (0)