@@ -22,81 +22,159 @@ Terminal two, `python` or `ptpython` if you have it:
22
22
$ python
23
23
```
24
24
25
- Import ` libtmux ` :
25
+ ## Setup
26
+
27
+ First, create a test session:
28
+
29
+ ``` python
30
+ >> > session = server.new_session() # Create a test session
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:
26
43
27
44
``` python
28
- import libtmux
45
+ >> > server.sessions # doctest: +ELLIPSIS
46
+ [Session($ ... ... )]
29
47
```
30
48
31
- Attach default tmux {class} ` ~libtmux.Server ` to ` t ` :
49
+ Get all windows across all sessions :
32
50
33
51
``` 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($ ... ... ))]
38
54
```
39
55
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:
41
66
42
67
``` python
43
68
>> > session = server.sessions[0 ]
44
- >> > session
45
- Session($ 1 ... )
69
+ >> > session # doctest: +ELLIPSIS
70
+ Session($ ... ... )
46
71
```
47
72
48
- Get a list of sessions :
73
+ Get windows in a session :
49
74
50
75
``` python
51
- >> > server.sessions
52
- [Session( $ 1 ... ) , Session($ 0 ... )]
76
+ >> > session.windows # doctest: +ELLIPSIS
77
+ [Window( @ ... ... , Session($ ... ... ) )]
53
78
```
54
79
55
- Iterate through sessions in a server :
80
+ Get active window and pane :
56
81
57
82
``` 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($ ... ... )))
62
88
```
63
89
64
- Grab a {class}` ~libtmux.Window ` from a session:
90
+ ## Window Level
91
+
92
+ Get a window and inspect its properties:
65
93
66
94
``` python
67
- >> > session.windows[0 ]
68
- Window(@ 1 ... :... , Session($ 1 ... ))
95
+ >> > window = session.windows[0 ]
96
+ >> > window.window_index # doctest: +ELLIPSIS
97
+ ' ...'
69
98
```
70
99
71
- Grab the currently focused window from session:
100
+ Access the window's parent session:
72
101
73
102
``` 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
76
107
```
77
108
78
- Grab the currently focused {class} ` Pane ` from session :
109
+ Get panes in a window :
79
110
80
111
``` python
81
- >> > session.active_pane
82
- Pane(% 1 Window(@ 1 ... : ... , Session($ 1 ... )))
112
+ >> > window.panes # doctest: +ELLIPSIS
113
+ [ Pane(% ... Window(@ ... ... , Session($ ... ... )))]
83
114
```
84
115
85
- Assign the attached {class} ` ~libtmux.Pane ` to ` p ` :
116
+ Get active pane :
86
117
87
118
``` python
88
- >> > p = session.active_pane
119
+ >> > window.active_pane # doctest: +ELLIPSIS
120
+ Pane(% ... Window(@ ... ... , Session($ ... ... )))
89
121
```
90
122
91
- Access the window/server of a pane:
123
+ ## Pane Level
124
+
125
+ Get a pane and traverse upwards:
92
126
93
127
``` 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
97
138
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
100
178
```
101
179
102
180
[ target ] : http://man.openbsd.org/OpenBSD-5.9/man1/tmux.1#COMMANDS
0 commit comments