Skip to content

Commit 274113f

Browse files
committed
feat(Window.kill): Add Window.kill(), deprecate kill_window()
1 parent ced0438 commit 274113f

File tree

4 files changed

+72
-7
lines changed

4 files changed

+72
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ Close window:
117117

118118
```python
119119
>>> w = session.attached_window
120-
>>> w.kill_window()
120+
>>> w.kill()
121121
```
122122

123123
Grab remaining tmux window:

docs/quickstart.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ Window(@2 2:check this out, Session($1 ...))
260260
And kill:
261261

262262
```python
263-
>>> window.kill_window()
263+
>>> window.kill()
264264
```
265265

266266
Use {meth}`Session.windows` and {meth}`Session.windows.filter()` to list and sort

src/libtmux/test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ def temp_window(
242242
Return a context manager with a temporary window.
243243
244244
The window will destroy itself upon closing with :meth:`window.
245-
kill_window()`.
245+
kill()`.
246246
247247
If no ``window_name`` is entered, :func:`get_test_window_name` will make
248248
an unused window name.
@@ -290,7 +290,7 @@ def temp_window(
290290
yield window
291291
finally:
292292
if len(session.windows.filter(window_id=window_id)) > 0:
293-
window.kill_window()
293+
window.kill()
294294
return
295295

296296

src/libtmux/window.py

Lines changed: 68 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -597,16 +597,59 @@ def rename_window(self, new_name: str) -> "Window":
597597

598598
return self
599599

600-
def kill_window(self) -> None:
601-
"""Kill the current :class:`Window` object. ``$ tmux kill-window``."""
600+
def kill(
601+
self,
602+
all_except: t.Optional[bool] = None,
603+
) -> None:
604+
"""Kill :class:`Window`.
605+
606+
``$ tmux kill-window``.
607+
608+
Examples
609+
--------
610+
Kill a window:
611+
>>> window_1 = session.new_window()
612+
613+
>>> window_1 in session.windows
614+
True
615+
616+
>>> window_1.kill()
617+
618+
>>> window_1 not in session.windows
619+
True
620+
621+
Kill all windows except the current one:
622+
>>> one_window_to_rule_them_all = session.new_window()
623+
624+
>>> other_windows = session.new_window(
625+
... ), session.new_window()
626+
627+
>>> all([w in session.windows for w in other_windows])
628+
True
629+
630+
>>> one_window_to_rule_them_all.kill(all_except=True)
631+
632+
>>> all([w not in session.windows for w in other_windows])
633+
True
634+
635+
>>> one_window_to_rule_them_all in session.windows
636+
True
637+
"""
638+
flags: t.Tuple[str, ...] = ()
639+
640+
if all_except:
641+
flags += ("-a",)
642+
602643
proc = self.cmd(
603644
"kill-window",
604-
f"-t{self.session_id}:{self.window_index}",
645+
*flags,
605646
)
606647

607648
if proc.stderr:
608649
raise exc.LibTmuxException(proc.stderr)
609650

651+
return None
652+
610653
def move_window(
611654
self,
612655
destination: str = "",
@@ -749,6 +792,28 @@ def width(self) -> t.Optional[str]:
749792
#
750793
# Legacy: Redundant stuff we want to remove
751794
#
795+
def kill_window(self) -> None:
796+
"""Kill the current :class:`Window` object. ``$ tmux kill-window``.
797+
798+
Notes
799+
-----
800+
.. deprecated:: 0.30
801+
802+
Deprecated in favor of :meth:`.kill()`.
803+
"""
804+
warnings.warn(
805+
"Window.kill_server() is deprecated in favor of Window.kill()",
806+
category=DeprecationWarning,
807+
stacklevel=2,
808+
)
809+
proc = self.cmd(
810+
"kill-window",
811+
f"-t{self.session_id}:{self.window_index}",
812+
)
813+
814+
if proc.stderr:
815+
raise exc.LibTmuxException(proc.stderr)
816+
752817
def get(self, key: str, default: t.Optional[t.Any] = None) -> t.Any:
753818
"""Return key-based lookup. Deprecated by attributes.
754819

0 commit comments

Comments
 (0)