@@ -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
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