Skip to content

Commit c741065

Browse files
committed
docs(CHANGES) Note context managers
1 parent e2e8307 commit c741065

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

CHANGES

+25
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,31 @@ $ pip install --user --upgrade --pre libtmux
1919

2020
### Features
2121

22+
#### Context Managers for tmux Objects
23+
24+
Added context manager support for all main tmux objects:
25+
26+
- `Server`: Automatically kills the server when exiting the context
27+
- `Session`: Automatically kills the session when exiting the context
28+
- `Window`: Automatically kills the window when exiting the context
29+
- `Pane`: Automatically kills the pane when exiting the context
30+
31+
Example usage:
32+
33+
```python
34+
with Server() as server:
35+
with server.new_session() as session:
36+
with session.new_window() as window:
37+
with window.split() as pane:
38+
pane.send_keys('echo "Hello"')
39+
# Do work with the pane
40+
# Everything is cleaned up automatically when exiting contexts
41+
```
42+
43+
This makes it easier to write clean, safe code that properly cleans up tmux resources.
44+
45+
#### Server Initialization Callbacks
46+
2247
Server now accepts 2 new optional params, `socket_name_factory` and `on_init` callbacks (#565):
2348

2449
- `socket_name_factory`: Callable that generates unique socket names for new servers

0 commit comments

Comments
 (0)