Skip to content

Commit

Permalink
feat!(Window): Set option flags
Browse files Browse the repository at this point in the history
  • Loading branch information
tony committed Feb 5, 2024
1 parent eee721b commit 345311a
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/libtmux/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,15 @@ def select_layout(self, layout: t.Optional[str] = None) -> "Window":

return self

def set_window_option(self, option: str, value: t.Union[int, str]) -> "Window":
def set_window_option(
self,
option: str,
value: t.Union[int, str],
format: t.Optional[bool] = None,
unset: t.Optional[bool] = None,
unset_panes: t.Optional[bool] = None,
prevent_overwrite: t.Optional[bool] = None,
) -> "Window":
"""Set option for tmux window.
Wraps ``$ tmux set-window-option <option> <value>``.
Expand All @@ -345,16 +353,34 @@ def set_window_option(self, option: str, value: t.Union[int, str]) -> "Window":
:exc:`exc.OptionError`, :exc:`exc.UnknownOption`,
:exc:`exc.InvalidOption`, :exc:`exc.AmbiguousOption`
"""
flags: list[str] = []
if isinstance(value, bool) and value:
value = "on"
elif isinstance(value, bool) and not value:
value = "off"

if unset is not None and unset:
assert isinstance(unset, bool)
flags.append("-u")

if unset_panes is not None and unset_panes:
assert isinstance(unset_panes, bool)
flags.append("-U")

if format is not None and format:
assert isinstance(format, bool)
flags.append("-F")

if prevent_overwrite is not None and prevent_overwrite:
assert isinstance(prevent_overwrite, bool)
flags.append("-o")

cmd = self.cmd(
"set-window-option",
f"-t{self.session_id}:{self.window_index}",
option,
value,
*flags,
)

if isinstance(cmd.stderr, list) and len(cmd.stderr):
Expand Down

0 comments on commit 345311a

Please sign in to comment.