Skip to content

Commit 9b6c5d9

Browse files
committed
refactor!: Move to dataclass objects
1 parent 771e6d3 commit 9b6c5d9

20 files changed

+984
-2494
lines changed

README.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ current tmux server / session / window pane.
6969
List sessions:
7070

7171
```python
72-
>>> server.list_sessions()
72+
>>> server.sessions
7373
[Session($1 ...), Session($0 ...)]
7474
```
7575

7676
Find session:
7777

7878
```python
79-
>>> server.get_by_id('$1')
79+
>>> server.sessions.filter(session_id='$1')[0]
8080
Session($1 ...)
8181
```
8282

@@ -85,7 +85,7 @@ Find session by dict lookup:
8585
```python
8686
>>> server.sessions[0].rename_session('foo')
8787
Session($1 foo)
88-
>>> server.find_where({ "session_name": "foo" })
88+
>>> server.sessions.filter(session_name="foo")[0]
8989
Session($1 foo)
9090
```
9191

@@ -150,12 +150,14 @@ Type inside the pane (send key strokes):
150150

151151
>>> pane.send_keys('echo hey', enter=False)
152152
>>> pane.enter()
153+
Pane(%1 ...)
153154
```
154155

155156
Grab the output of pane:
156157

157158
```python
158159
>>> pane.clear() # clear the pane
160+
Pane(%1 ...)
159161
>>> pane.send_keys("cowsay 'hello'", enter=True)
160162
>>> print('\n'.join(pane.cmd('capture-pane', '-p').stdout)) # doctest: +SKIP
161163
$ cowsay 'hello'

docs/about.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ How is libtmux able to keep references to panes, windows and sessions?
8585
> Window index refers to the # of the window in the session.
8686
>
8787
> To assert pane, window and session data, libtmux will use
88-
> {meth}`Server.list_sessions()`, {meth}`Session.list_windows()`,
89-
> {meth}`Window.list_panes()` to update objects.
88+
> {meth}`Server.sessions()`, {meth}`Session.windows()`,
89+
> {meth}`Window.panes()` to update objects.
9090
9191
## Naming conventions
9292

docs/quickstart.md

+13-12
Original file line numberDiff line numberDiff line change
@@ -125,33 +125,33 @@ Windows and Panes.
125125
If you have multiple tmux sessions open, you can see that all of the
126126
methods in {class}`Server` are available.
127127

128-
We can list sessions with {meth}`Server.list_sessions`:
128+
We can list sessions with {meth}`Server.sessions`:
129129

130130
```python
131-
>>> server.list_sessions()
131+
>>> server.sessions
132132
[Session($1 ...), Session($0 ...)]
133133
```
134134

135135
This returns a list of {class}`Session` objects you can grab. We can
136136
find our current session with:
137137

138138
```python
139-
>>> server.list_sessions()[0]
139+
>>> server.sessions[0]
140140
Session($1 ...)
141141
```
142142

143143
However, this isn't guaranteed, libtmux works against current tmux information, the
144144
session's name could be changed, or another tmux session may be created,
145-
so {meth}`Server.get_by_id` and {meth}`Server.find_where` exists as a lookup.
145+
so {meth}`Server.sessions` and {meth}`Server.windows` exists as a lookup.
146146

147147
## Get session by ID
148148

149149
tmux sessions use the `$[0-9]` convention as a way to identify sessions.
150150

151-
`$1` is whatever the ID `list_sessions()` returned above.
151+
`$1` is whatever the ID `sessions()` returned above.
152152

153153
```python
154-
>>> server.get_by_id('$1')
154+
>>> server.sessions.filter(session_id='$1')[0]
155155
Session($1 ...)
156156
```
157157

@@ -163,13 +163,13 @@ You may `session = server.get_by_id('$<yourId>')` to use the session object.
163163
>>> server.sessions[0].rename_session('foo')
164164
Session($1 foo)
165165

166-
>>> server.find_where({ "session_name": "foo" })
166+
>>> server.sessions.filter(session_name="foo")[0]
167167
Session($1 foo)
168168
```
169169

170-
With `find_where`, pass in a dict and return the first object found. In
170+
With `filter`, pass in attributes and return a list of matches. In
171171
this case, a {class}`Server` holds a collection of child {class}`Session`.
172-
{class}`Session` and {class}`Window` both utilize `find_where` to sift
172+
{class}`Session` and {class}`Window` both utilize `filter` to sift
173173
through Windows and Panes, respectively.
174174

175175
So you may now use:
@@ -178,7 +178,7 @@ So you may now use:
178178
>>> server.sessions[0].rename_session('foo')
179179
Session($1 foo)
180180

181-
>>> session = server.find_where({ "session_name": "foo" })
181+
>>> session = server.sessions.filter(session_name="foo")[0]
182182
>>> session
183183
Session($1 foo)
184184
```
@@ -213,7 +213,7 @@ Let's delete that window ({meth}`Session.kill_window`).
213213
Method 1: Use passthrough to tmux's `target` system.
214214

215215
```python
216-
>>> session.kill_window(window.id)
216+
>>> session.kill_window(window.window_id)
217217
```
218218

219219
The window in the bg dissappeared. This was the equivalent of
@@ -260,7 +260,7 @@ And kill:
260260
>>> window.kill_window()
261261
```
262262

263-
Use {meth}`Session.list_windows()` and {meth}`Session.find_where()` to list and sort
263+
Use {meth}`Session.windows` and {meth}`Session.windows.filter()` to list and sort
264264
through active {class}`Window`'s.
265265

266266
## Manipulating windows
@@ -346,6 +346,7 @@ using {meth}`Pane.enter()`:
346346

347347
```python
348348
>>> pane.enter()
349+
Pane(%1 ...)
349350
```
350351

351352
### Avoid cluttering shell history

docs/reference/properties.md

+17-38
Original file line numberDiff line numberDiff line change
@@ -49,25 +49,24 @@ Session($1 libtmux_...)
4949
Quick access to basic attributes:
5050

5151
```python
52-
>>> session.name
52+
>>> session.session_name
5353
'libtmux_...'
5454

55-
>>> session.id
55+
>>> session.session_id
5656
'$1'
5757
```
5858

5959
To see all attributes for a session:
6060

6161
```python
62-
>>> sorted(list(session._info.keys()))
62+
from libtmux.neo import Obj
63+
64+
>>> sorted(list(Obj.__dataclass_fields__.keys()))
6365
['session_attached', 'session_created', ...]
6466
```
6567

66-
Some may conflict with python API, to access them, you can use `.get()`, to get the count
67-
of sessions in a window:
68-
6968
```python
70-
>>> session.get('session_windows')
69+
>>> session.session_windows
7170
'...'
7271
```
7372

@@ -85,30 +84,23 @@ Window(@1 ...:..., Session($1 ...))
8584
Basics:
8685

8786
```python
88-
>>> window.name
87+
>>> window.window_name
8988
'...'
9089

91-
>>> window.id
90+
>>> window.window_id
9291
'@1'
9392

94-
>>> window.height
93+
>>> window.window_height
9594
'...'
9695

97-
>>> window.width
96+
>>> window.window_width
9897
'...'
9998
```
10099

101-
Everything available:
102-
103-
```python
104-
>>> sorted(list(window.keys()))
105-
['session_id', 'session_name', 'window_active', ..., 'window_width']
106-
```
107-
108-
Use `get()` for details not accessible via properties:
100+
Use attribute access for details not accessible via properties:
109101

110102
```python
111-
>>> window.get('window_panes')
103+
>>> window.window_panes
112104
'1'
113105
```
114106

@@ -126,33 +118,20 @@ Pane(%1 Window(@1 ...:..., Session($1 libtmux_...)))
126118
Basics:
127119

128120
```python
129-
>>> pane.current_command
121+
>>> pane.pane_current_command
130122
'...'
131123

132-
>>> type(pane.current_command)
124+
>>> type(pane.pane_current_command)
133125
<class 'str'>
134126

135-
>>> pane.height
127+
>>> pane.pane_height
136128
'...'
137129

138-
>>> pane.width
130+
>>> pane.pane_width
139131
'...'
140132

141-
>>> pane.index
133+
>>> pane.pane_index
142134
'0'
143135
```
144136

145-
Everything:
146-
147-
````python
148-
>>> sorted(list(pane._info.keys()))
149-
['alternate_on', 'alternate_saved_x', ..., 'wrap_flag']
150-
151-
Use `get()` for details keys:
152-
153-
```python
154-
>>> pane.get('pane_width')
155-
'...'
156-
````
157-
158137
[formats]: http://man.openbsd.org/OpenBSD-5.9/man1/tmux.1#FORMATS

0 commit comments

Comments
 (0)