Commit ae892c0
authored
feat(tmux) Client, typed fields, native filter (#672)
libtmux 0.57.0 broadens tmux coverage. It introduces Client as a
first-class typed object, threads tmux's native -f filter through
the typed listing methods so callers can push predicates into the
tmux server, adds typed access to many more format tokens with
scope-and-version-gated -F templates, and propagates subcommand
context through LibTmuxException so downstream tools can dispatch
on which tmux command produced an error.
What's new:
- **Client object and Server.clients accessor.** New typed
dataclass for attached terminals. client_name is the stable
identifier; session_id / window_id / pane_id are attached-view
snapshots hydrated via tmux's downward format_defaults cascade.
attached_session / attached_window / attached_pane re-read
list-clients before resolving; attached_pane is session-scope
(cascade), not the client's CLIENT_ACTIVEPANE focus.
- **Server.display_message and Window.display_message.** Server
reads like #{version} and #{socket_path} work without a pane
handle; window reads (#{window_zoomed_flag},
#{window_active_clients_list}) auto-bind to the window's id.
All three display_message wrappers (including the existing
Pane.display_message) surface tmux stderr via warnings.warn
rather than dropping it silently. Callers that want to
escalate can wrap in warnings.catch_warnings with
filterwarnings("error").
- **Native filter on typed listing methods.**
Server.search_panes / search_windows / search_sessions plus the
Session and Window analogues take a filter= kwarg routed to
tmux's -f flag. tmux evaluates the predicate and drops
non-matching rows before any Python instance is constructed.
Caveat: tmux silently expands a malformed predicate to empty,
which the format engine treats as false — a typo looks
identical to "no matches".
- **Scope-and-version-aware -F templates.** The format string
libtmux sends each list-* subcommand is now scope- and
version-aware. A Session row hydrates active-window and
active-pane fields via tmux's downward cascade; a Client row
likewise hydrates the client's attached session, window, and
active pane. Tokens introduced after tmux 3.2a are gated
through FIELD_VERSION so the -F template stays safe on the
project's minimum supported tmux. Unknown tokens stay None on
the typed surface — no crash, no warning.
- **Typed Pane / Window / Session / Client format-token fields
for the 3.2a set.** Pane state (pane_dead, pane_in_mode,
pane_marked, pane_synchronized, pane_path, pane_pipe …), window
state (window_zoomed_flag, window_silence_flag, window_flags …),
session state (session_marked …), and client view
(client_session, client_readonly, client_termtype …).
- **Server.run_shell(cwd=, show_stderr=).** New kwargs map to
tmux's -c (3.4+) and -E (3.6+) flags. Older tmux warns and
ignores the kwarg instead of erroring.
- **Pane.send_keys(cmd=None, …) flag-only invocation.** Pass
cmd=None together with reset=True or repeat=N to invoke tmux's
flag-only send-keys -R / send-keys -N <n> form without any
trailing key argument.
- **Server.list_buffers(format_string=, filter=).** Project a
chosen -F template or push a buffer-name match expression
through tmux's format engine.
- **Pane.capture_pane(pending=True).** Return bytes tmux has
read from the pane but not yet committed to the terminal —
useful for diagnosing programs whose output stalls mid-sequence.
Fixes:
- Pane.reset() now clears pane scrollback. The history clear
silently no-op'd in 0.56.0, leaving the scrollback intact
(#650).
- Server.sessions / Server.clients / Server.search_sessions now
distinguish a fresh server (no daemon yet) from a real tmux
failure (permission denied, malformed daemon response). The
former still returns an empty QueryList; the latter raises
LibTmuxException instead of being swallowed.
Breaking changes:
- **LibTmuxException string form gains a subcommand prefix.**
str(exc) now begins with the originating tmux subcommand name
followed by ": ". An error from Session.last_window() used to
render as "can't find window" and now renders as "last-window:
can't find window". The wrapped-stderr type also changed:
exc.args[0] is now str (joined with "\n" when tmux emitted
multiple stderr lines); previously it was list[str]. Substring
matches and unanchored re.search patterns continue to work
unchanged.
- **Server.sessions, Server.clients, and Server.search_sessions
raise on tmux errors.** Previously, a tmux command failure was
swallowed by a bare except Exception: pass, returning an empty
QueryList indistinguishable from "no sessions/clients" or
"filter matched nothing". The wrappers now let LibTmuxException
propagate; only "no server running" / "error connecting to" on
a fresh server remain empty-result cases.
Deferred to follow-up shipments:
- Typed Obj fields for tokens tmux added in 3.4 / 3.5 / 3.6 and
the forward-looking set from tmux master. Held until tmux 3.7
reaches a tagged release.
- Per-client active-pane resolution via tmux's CLIENT_ACTIVEPANE
flag. Client.attached_pane currently follows the cascade
(session's current window's active pane); the two diverge once
a client has used select-pane -P to set its own active pane.
- A predictable error contract for display_message
(version-gated raise, per-call raise_on_stderr kwarg, or
kept-permanent warn).
Fixes #650.
Refs #670 (umbrella).
Companion: tmux-python/libtmux-mcp#48.31 files changed
Lines changed: 4260 additions & 253 deletions
File tree
- docs
- api
- topics
- src/libtmux
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
48 | 260 | | |
49 | 261 | | |
50 | 262 | | |
51 | | - | |
| 263 | + | |
52 | 264 | | |
53 | 265 | | |
54 | 266 | | |
| |||
58 | 270 | | |
59 | 271 | | |
60 | 272 | | |
61 | | - | |
| 273 | + | |
62 | 274 | | |
63 | 275 | | |
64 | 276 | | |
| |||
80 | 292 | | |
81 | 293 | | |
82 | 294 | | |
83 | | - | |
| 295 | + | |
84 | 296 | | |
85 | 297 | | |
86 | 298 | | |
| |||
94 | 306 | | |
95 | 307 | | |
96 | 308 | | |
97 | | - | |
| 309 | + | |
98 | 310 | | |
99 | 311 | | |
100 | 312 | | |
| |||
137 | 349 | | |
138 | 350 | | |
139 | 351 | | |
140 | | - | |
| 352 | + | |
141 | 353 | | |
142 | 354 | | |
143 | 355 | | |
| |||
196 | 408 | | |
197 | 409 | | |
198 | 410 | | |
199 | | - | |
| 411 | + | |
200 | 412 | | |
201 | 413 | | |
202 | 414 | | |
| |||
343 | 555 | | |
344 | 556 | | |
345 | 557 | | |
346 | | - | |
| 558 | + | |
347 | 559 | | |
348 | 560 | | |
349 | 561 | | |
| |||
0 commit comments