Skip to content

Commit b250ccd

Browse files
committed
Window: Use OptionMixin.set_option()
1 parent facacbd commit b250ccd

File tree

1 file changed

+2
-85
lines changed

1 file changed

+2
-85
lines changed

src/libtmux/window.py

Lines changed: 2 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from libtmux.pane import Pane
1919

2020
from . import exc
21-
from .common import PaneDict, WindowOptionDict, handle_option_error
21+
from .common import OptionMixin, PaneDict, WindowOptionDict, handle_option_error
2222
from .formats import FORMAT_SEPARATOR
2323

2424
if t.TYPE_CHECKING:
@@ -29,7 +29,7 @@
2929

3030

3131
@dataclasses.dataclass()
32-
class Window(Obj):
32+
class Window(Obj, OptionMixin):
3333
""":term:`tmux(1)` :term:`Window` [window_manual]_.
3434
3535
Holds :class:`Pane` objects.
@@ -344,89 +344,6 @@ def set_window_option(
344344

345345
return self.set_option(option=option, value=value)
346346

347-
def set_option(
348-
self,
349-
option: str,
350-
value: t.Union[int, str],
351-
_format: t.Optional[bool] = None,
352-
unset: t.Optional[bool] = None,
353-
unset_panes: t.Optional[bool] = None,
354-
prevent_overwrite: t.Optional[bool] = None,
355-
suppress_warnings: t.Optional[bool] = None,
356-
append: t.Optional[bool] = None,
357-
g: t.Optional[bool] = None,
358-
scope: t.Optional[OptionScope] = None,
359-
) -> "Window":
360-
"""Set option for tmux window.
361-
362-
Wraps ``$ tmux set-option <option> <value>``.
363-
364-
Parameters
365-
----------
366-
option : str
367-
option to set, e.g. 'aggressive-resize'
368-
value : str
369-
window option value. True/False will turn in 'on' and 'off',
370-
also accepts string of 'on' or 'off' directly.
371-
372-
Raises
373-
------
374-
:exc:`exc.OptionError`, :exc:`exc.UnknownOption`,
375-
:exc:`exc.InvalidOption`, :exc:`exc.AmbiguousOption`
376-
"""
377-
flags: t.List[str] = []
378-
if isinstance(value, bool) and value:
379-
value = "on"
380-
elif isinstance(value, bool) and not value:
381-
value = "off"
382-
383-
if unset is not None and unset:
384-
assert isinstance(unset, bool)
385-
flags.append("-u")
386-
387-
if unset_panes is not None and unset_panes:
388-
assert isinstance(unset_panes, bool)
389-
flags.append("-U")
390-
391-
if _format is not None and _format:
392-
assert isinstance(_format, bool)
393-
flags.append("-F")
394-
395-
if prevent_overwrite is not None and prevent_overwrite:
396-
assert isinstance(prevent_overwrite, bool)
397-
flags.append("-o")
398-
399-
if suppress_warnings is not None and suppress_warnings:
400-
assert isinstance(suppress_warnings, bool)
401-
flags.append("-q")
402-
403-
if append is not None and append:
404-
assert isinstance(append, bool)
405-
flags.append("-a")
406-
407-
if g is not None and g:
408-
assert isinstance(g, bool)
409-
flags.append("-g")
410-
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-
417-
cmd = self.cmd(
418-
"set-option",
419-
f"-t{self.session_id}:{self.window_index}",
420-
*flags,
421-
option,
422-
value,
423-
)
424-
425-
if isinstance(cmd.stderr, list) and len(cmd.stderr):
426-
handle_option_error(cmd.stderr[0])
427-
428-
return self
429-
430347
def show_window_options(self, g: t.Optional[bool] = False) -> "WindowOptionDict":
431348
"""Show options for tmux window. Deprecated by :meth:`Window.show_options()`.
432349

0 commit comments

Comments
 (0)