diff --git a/CHANGES b/CHANGES index 437f7e4a7..ce74e5aae 100644 --- a/CHANGES +++ b/CHANGES @@ -14,6 +14,31 @@ $ pip install --user --upgrade --pre libtmux +### New features + +- `Window.set_option()` (#516) + + Learned params: + + - `format` -> `-F` + - `unset` -> `-u` + - `global` -> `-g` + - `unset_panes` -> `-U`: Also unset other panse in windows + - `prevent_overwrite`: `-o` + - `suppress_warnings`: `-q` + - `append`: `-a` + +- `Window.show_option()` (#516) +- `Window.show_options()` (#516) + +### Breaking changes + +#### Deprecations + +- Deprecated `Window.set_window_option()` in favor of `Window.set_option()` (#516) +- Deprecated `Window.show_window_option()` in favor of `Window.show_option()` (#516) +- Deprecated `Window.show_window_options()` in favor of `Window.show_options()` (#516) + ## libtmux 0.27.0 (2024-02-07) ### Improvement diff --git a/src/libtmux/common.py b/src/libtmux/common.py index c8bb6ccc4..e52189978 100644 --- a/src/libtmux/common.py +++ b/src/libtmux/common.py @@ -7,12 +7,20 @@ """ import logging import re +import shlex import shutil import subprocess import sys import typing as t from typing import Dict, Optional, Union +from libtmux.constants import ( + DEFAULT_SCOPE, + OPTION_SCOPE_FLAG_MAP, + OptionScope, + _DefaultScope, +) + from . import exc from ._compat import LooseVersion, console_to_str, str_from_console @@ -32,9 +40,270 @@ SessionDict = t.Dict[str, t.Any] WindowDict = t.Dict[str, t.Any] WindowOptionDict = t.Dict[str, t.Any] +PaneOptionDict = t.Dict[str, t.Any] PaneDict = t.Dict[str, t.Any] +class CmdProtocol(t.Protocol): + """Command protocol for tmux command.""" + + def __call__(self, cmd: str, *args: t.Any, **kwargs: t.Any) -> "tmux_cmd": + """Wrap tmux_cmd.""" + ... + + +class CmdMixin: + """Command mixin for tmux command.""" + + cmd: CmdProtocol + + +class OptionMixin(CmdMixin): + """Mixin for manager session and server level environment variables in tmux.""" + + default_scope: OptionScope | None + + def __init__(self, default_scope: OptionScope) -> None: + self.default_scope = default_scope + + def set_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, + suppress_warnings: t.Optional[bool] = None, + append: t.Optional[bool] = None, + g: t.Optional[bool] = None, + scope: t.Optional[t.Union[OptionScope, _DefaultScope]] = DEFAULT_SCOPE, + ) -> "t.Self": + """Set option for tmux window. + + Wraps ``$ tmux set-option