|
18 | 18 | from libtmux.pane import Pane |
19 | 19 |
|
20 | 20 | from . import exc |
21 | | -from .common import PaneDict, WindowOptionDict, handle_option_error |
| 21 | +from .common import OptionMixin, PaneDict, WindowOptionDict, handle_option_error |
22 | 22 | from .formats import FORMAT_SEPARATOR |
23 | 23 |
|
24 | 24 | if t.TYPE_CHECKING: |
|
29 | 29 |
|
30 | 30 |
|
31 | 31 | @dataclasses.dataclass() |
32 | | -class Window(Obj): |
| 32 | +class Window(Obj, OptionMixin): |
33 | 33 | """:term:`tmux(1)` :term:`Window` [window_manual]_. |
34 | 34 |
|
35 | 35 | Holds :class:`Pane` objects. |
@@ -344,89 +344,6 @@ def set_window_option( |
344 | 344 |
|
345 | 345 | return self.set_option(option=option, value=value) |
346 | 346 |
|
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 | | - |
430 | 347 | def show_window_options(self, g: t.Optional[bool] = False) -> "WindowOptionDict": |
431 | 348 | """Show options for tmux window. Deprecated by :meth:`Window.show_options()`. |
432 | 349 |
|
|
0 commit comments