Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5d3e428

Browse filesBrowse files
authored
docs(traversal) Add more doctests (#567)
2 parents 4a08aa1 + 283ee32 commit 5d3e428
Copy full SHA for 5d3e428

File tree

Expand file treeCollapse file tree

2 files changed

+118
-35
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+118
-35
lines changed

‎CHANGES

Copy file name to clipboardExpand all lines: CHANGES
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ Add `TestServer` pytest fixture for creating temporary tmux servers (#565):
3333
- Includes comprehensive test coverage and documentation
3434
- Available in doctest namespace
3535

36+
### Documentation
37+
38+
- Fix links to the "Topics" section
39+
- More docs for "Traversal" Topic (#567)
40+
3641
## libtmux 0.42.1 (2024-02-15)
3742

3843
### Bug fixes

‎docs/topics/traversal.md

Copy file name to clipboardExpand all lines: docs/topics/traversal.md
+113-35Lines changed: 113 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -22,81 +22,159 @@ Terminal two, `python` or `ptpython` if you have it:
2222
$ python
2323
```
2424

25-
Import `libtmux`:
25+
## Setup
26+
27+
First, create a test session:
28+
29+
```python
30+
>>> session = server.new_session() # Create a test session using existing server
31+
```
32+
33+
## Server Level
34+
35+
View the server's representation:
36+
37+
```python
38+
>>> server # doctest: +ELLIPSIS
39+
Server(socket_name=...)
40+
```
41+
42+
Get all sessions in the server:
2643

2744
```python
28-
import libtmux
45+
>>> server.sessions # doctest: +ELLIPSIS
46+
[Session($... ...)]
2947
```
3048

31-
Attach default tmux {class}`~libtmux.Server` to `t`:
49+
Get all windows across all sessions:
3250

3351
```python
34-
>>> import libtmux
35-
>>> t = libtmux.Server();
36-
>>> t
37-
Server(socket_path=/tmp/tmux-.../default)
52+
>>> server.windows # doctest: +ELLIPSIS
53+
[Window(@... ..., Session($... ...))]
3854
```
3955

40-
Get first session {class}`~libtmux.Session` to `session`:
56+
Get all panes across all windows:
57+
58+
```python
59+
>>> server.panes # doctest: +ELLIPSIS
60+
[Pane(%... Window(@... ..., Session($... ...)))]
61+
```
62+
63+
## Session Level
64+
65+
Get first session:
4166

4267
```python
4368
>>> session = server.sessions[0]
44-
>>> session
45-
Session($1 ...)
69+
>>> session # doctest: +ELLIPSIS
70+
Session($... ...)
4671
```
4772

48-
Get a list of sessions:
73+
Get windows in a session:
4974

5075
```python
51-
>>> server.sessions
52-
[Session($1 ...), Session($0 ...)]
76+
>>> session.windows # doctest: +ELLIPSIS
77+
[Window(@... ..., Session($... ...))]
5378
```
5479

55-
Iterate through sessions in a server:
80+
Get active window and pane:
5681

5782
```python
58-
>>> for sess in server.sessions:
59-
... print(sess)
60-
Session($1 ...)
61-
Session($0 ...)
83+
>>> session.active_window # doctest: +ELLIPSIS
84+
Window(@... ..., Session($... ...))
85+
86+
>>> session.active_pane # doctest: +ELLIPSIS
87+
Pane(%... Window(@... ..., Session($... ...)))
6288
```
6389

64-
Grab a {class}`~libtmux.Window` from a session:
90+
## Window Level
91+
92+
Get a window and inspect its properties:
6593

6694
```python
67-
>>> session.windows[0]
68-
Window(@1 ...:..., Session($1 ...))
95+
>>> window = session.windows[0]
96+
>>> window.window_index # doctest: +ELLIPSIS
97+
'...'
6998
```
7099

71-
Grab the currently focused window from session:
100+
Access the window's parent session:
72101

73102
```python
74-
>>> session.active_window
75-
Window(@1 ...:..., Session($1 ...))
103+
>>> window.session # doctest: +ELLIPSIS
104+
Session($... ...)
105+
>>> window.session.session_id == session.session_id
106+
True
76107
```
77108

78-
Grab the currently focused {class}`Pane` from session:
109+
Get panes in a window:
79110

80111
```python
81-
>>> session.active_pane
82-
Pane(%1 Window(@1 ...:..., Session($1 ...)))
112+
>>> window.panes # doctest: +ELLIPSIS
113+
[Pane(%... Window(@... ..., Session($... ...)))]
83114
```
84115

85-
Assign the attached {class}`~libtmux.Pane` to `p`:
116+
Get active pane:
86117

87118
```python
88-
>>> p = session.active_pane
119+
>>> window.active_pane # doctest: +ELLIPSIS
120+
Pane(%... Window(@... ..., Session($... ...)))
89121
```
90122

91-
Access the window/server of a pane:
123+
## Pane Level
124+
125+
Get a pane and traverse upwards:
92126

93127
```python
94-
>>> p = session.active_pane
95-
>>> p.window
96-
Window(@1 ...:..., Session($1 ...))
128+
>>> pane = window.panes[0]
129+
>>> pane.window.window_id == window.window_id
130+
True
131+
>>> pane.session.session_id == session.session_id
132+
True
133+
>>> pane.server is server
134+
True
135+
```
136+
137+
## Filtering and Finding Objects
97138

98-
>>> p.server
99-
Server(socket_name=libtmux_test...)
139+
Find windows by index:
140+
141+
```python
142+
>>> session.windows.filter(window_index=window.window_index) # doctest: +ELLIPSIS
143+
[Window(@... ..., Session($... ...))]
144+
```
145+
146+
Get a specific pane by ID:
147+
148+
```python
149+
>>> window.panes.get(pane_id=pane.pane_id) # doctest: +ELLIPSIS
150+
Pane(%... Window(@... ..., Session($... ...)))
151+
```
152+
153+
## Checking Relationships
154+
155+
Check if objects are related:
156+
157+
```python
158+
>>> window in session.windows
159+
True
160+
>>> pane in window.panes
161+
True
162+
>>> session in server.sessions
163+
True
164+
```
165+
166+
Check if a window is active:
167+
168+
```python
169+
>>> window.window_id == session.active_window.window_id
170+
True
171+
```
172+
173+
Check if a pane is active:
174+
175+
```python
176+
>>> pane.pane_id == window.active_pane.pane_id
177+
True
100178
```
101179

102180
[target]: http://man.openbsd.org/OpenBSD-5.9/man1/tmux.1#COMMANDS

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.