libtmux 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +108 -0
- data/README.md +270 -89
- data/lib/libtmux/capabilities.rb +105 -10
- data/lib/libtmux/capture.rb +6 -11
- data/lib/libtmux/control.rb +3 -0
- data/lib/libtmux/entity.rb +176 -3
- data/lib/libtmux/errors.rb +20 -1
- data/lib/libtmux/operations.rb +7 -0
- data/lib/libtmux/option_catalog.rb +54 -0
- data/lib/libtmux/options.rb +39 -11
- data/lib/libtmux/owned.rb +11 -0
- data/lib/libtmux/process.rb +40 -11
- data/lib/libtmux/program.rb +478 -0
- data/lib/libtmux/server.rb +182 -78
- data/lib/libtmux/terminal.rb +6 -1
- data/lib/libtmux/text_wait.rb +101 -0
- data/lib/libtmux/tmux_version.rb +24 -2
- data/lib/libtmux/version.rb +1 -1
- data/lib/libtmux.rb +6 -0
- data/libexec/program_child.rb +60 -0
- data/schema/option-catalog.json +1723 -0
- data/sig/control.rbs +2 -1
- data/sig/libtmux.rbs +81 -6
- data/sig/option_catalog.rbs +26 -0
- data/sig/program.rbs +47 -0
- data/sig/terminal.rbs +1 -0
- metadata +19 -4
data/README.md
CHANGED
|
@@ -19,8 +19,10 @@ as handles, [snapshots][snapshot] you filter in plain Ruby, and
|
|
|
19
19
|
[Guides](https://libtmux.org/en/ruby/latest/guides/) ·
|
|
20
20
|
[RubyGems](https://rubygems.org/gems/libtmux)
|
|
21
21
|
|
|
22
|
-
[](https://github.com/libtmux/libtmux-ruby/actions/workflows/compatibility.yml)
|
|
23
23
|
[](https://rubygems.org/gems/libtmux)
|
|
24
|
+
[](https://libtmux.org/en/ruby/)
|
|
25
|
+
[](https://github.com/libtmux/libtmux-ruby/blob/master/LICENSE)
|
|
24
26
|
|
|
25
27
|
</div>
|
|
26
28
|
|
|
@@ -58,15 +60,16 @@ $ gem install libtmux
|
|
|
58
60
|
```
|
|
59
61
|
|
|
60
62
|
This program creates a session, adds a window, splits it, and prints each
|
|
61
|
-
window with its panes
|
|
62
|
-
server when the block exits, and the snapshot stays readable afterward:
|
|
63
|
+
window with its panes:
|
|
63
64
|
|
|
64
65
|
<!-- example: quickstart/main -->
|
|
65
66
|
```ruby
|
|
66
67
|
require "libtmux"
|
|
67
68
|
|
|
68
69
|
snapshot = LibTmux::Server.start do |server|
|
|
69
|
-
session = server.new_session(
|
|
70
|
+
session = server.new_session(
|
|
71
|
+
name: "work", window_name: "main", command: ["/bin/cat"]
|
|
72
|
+
)
|
|
70
73
|
window = session.new_window(name: "logs", command: ["/bin/cat"])
|
|
71
74
|
window.split(direction: :horizontal, size: "40%", command: ["/bin/cat"])
|
|
72
75
|
|
|
@@ -79,6 +82,12 @@ end
|
|
|
79
82
|
```
|
|
80
83
|
<!-- /example -->
|
|
81
84
|
|
|
85
|
+
Save it as `quickstart.rb` and run it:
|
|
86
|
+
|
|
87
|
+
```console
|
|
88
|
+
$ ruby quickstart.rb
|
|
89
|
+
```
|
|
90
|
+
|
|
82
91
|
It prints:
|
|
83
92
|
|
|
84
93
|
```text
|
|
@@ -86,9 +95,10 @@ main: %0
|
|
|
86
95
|
logs: %1, %2
|
|
87
96
|
```
|
|
88
97
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
98
|
+
[`Server.start`][server-start] gives the program a tmux server of its own, on
|
|
99
|
+
its own socket with an empty configuration, and closes it when the block exits.
|
|
100
|
+
It never touches a tmux you already use. Requiring the gem starts no tmux
|
|
101
|
+
process.
|
|
92
102
|
|
|
93
103
|
## Find sessions, windows, and panes
|
|
94
104
|
|
|
@@ -127,10 +137,22 @@ raises [`CommandError`][commanderror].
|
|
|
127
137
|
Read the server once, then filter that read with
|
|
128
138
|
[`where`][selection-where], [`select`][selection-select],
|
|
129
139
|
[`one`][selection-one] and [`one_or_nil`][selection-one_or_nil]. These queries
|
|
130
|
-
make no tmux calls
|
|
140
|
+
make no tmux calls:
|
|
131
141
|
|
|
132
142
|
<!-- example: quickstart/queries -->
|
|
133
143
|
```ruby
|
|
144
|
+
require "libtmux"
|
|
145
|
+
|
|
146
|
+
snapshot = LibTmux::Server.start do |server|
|
|
147
|
+
session = server.new_session(
|
|
148
|
+
name: "work", window_name: "main", command: ["/bin/cat"]
|
|
149
|
+
)
|
|
150
|
+
window = session.new_window(name: "logs", command: ["/bin/cat"])
|
|
151
|
+
window.split(direction: :horizontal, size: "40%", command: ["/bin/cat"])
|
|
152
|
+
|
|
153
|
+
server.snapshot
|
|
154
|
+
end
|
|
155
|
+
|
|
134
156
|
panes = snapshot.panes
|
|
135
157
|
active_ids = panes.where(active: true).map(&:id)
|
|
136
158
|
wide_panes = panes.select { |pane| pane.width >= 40 }
|
|
@@ -138,9 +160,23 @@ panes_by_window = panes.group_by { |pane| pane.window.name }
|
|
|
138
160
|
|
|
139
161
|
logs = snapshot.windows.one(name: "logs")
|
|
140
162
|
missing = snapshot.windows.one_or_nil(name: "missing")
|
|
163
|
+
|
|
164
|
+
puts "active: #{active_ids.join(', ')}"
|
|
165
|
+
puts "wide: #{wide_panes.map(&:id).join(', ')}"
|
|
166
|
+
puts "logs panes: #{logs.panes.length}"
|
|
167
|
+
puts "missing: #{missing.inspect}"
|
|
141
168
|
```
|
|
142
169
|
<!-- /example -->
|
|
143
170
|
|
|
171
|
+
It prints:
|
|
172
|
+
|
|
173
|
+
```text
|
|
174
|
+
active: %0, %1
|
|
175
|
+
wide: %0, %1
|
|
176
|
+
logs panes: 2
|
|
177
|
+
missing: nil
|
|
178
|
+
```
|
|
179
|
+
|
|
144
180
|
`one` raises [`NoMatchError`][nomatcherror] or
|
|
145
181
|
[`MultipleMatchesError`][multiplematcheserror] unless exactly one record
|
|
146
182
|
matches. `one_or_nil` returns `nil` for no match and still rejects duplicates.
|
|
@@ -152,8 +188,7 @@ lists every query field and wire name.
|
|
|
152
188
|
### [`Server#search_panes`][server-search_panes]: the matching panes in one call
|
|
153
189
|
|
|
154
190
|
`search_panes` captures the server and answers a selection of the panes whose
|
|
155
|
-
fields match `where:`.
|
|
156
|
-
without running tmux. This program also uses the snapshot queries above:
|
|
191
|
+
fields match `where:`. This program also uses the snapshot queries above:
|
|
157
192
|
|
|
158
193
|
<!-- example: api_query/main -->
|
|
159
194
|
```ruby
|
|
@@ -181,13 +216,45 @@ missing session: true
|
|
|
181
216
|
matching pane: %0
|
|
182
217
|
```
|
|
183
218
|
|
|
219
|
+
### [`Server#explain_panes`][server-explain_panes]: what runs in tmux, what runs in Ruby
|
|
220
|
+
|
|
221
|
+
`explain_panes` returns the plan for a pane query and sends nothing to tmux.
|
|
222
|
+
Today tmux returns the whole server and Ruby applies every criterion:
|
|
223
|
+
|
|
224
|
+
<!-- example: api_explain_panes/main -->
|
|
225
|
+
```ruby
|
|
226
|
+
require "libtmux"
|
|
227
|
+
|
|
228
|
+
LibTmux::Server.start do |server|
|
|
229
|
+
server.new_session(name: "work", command: ["/bin/cat"])
|
|
230
|
+
criteria = {active: true}
|
|
231
|
+
plan = server.explain_panes(where: criteria)
|
|
232
|
+
puts "tmux reads: #{plan.fetch(:capture)}"
|
|
233
|
+
puts "tmux filters: #{plan.fetch(:pushed) || 'nothing'}"
|
|
234
|
+
puts "Ruby filters: #{plan.fetch(:residual).fetch('where').keys.join(', ')}"
|
|
235
|
+
puts "matching panes: #{server.search_panes(where: criteria).length}"
|
|
236
|
+
end
|
|
237
|
+
```
|
|
238
|
+
<!-- /example -->
|
|
239
|
+
|
|
240
|
+
It prints:
|
|
241
|
+
|
|
242
|
+
```text
|
|
243
|
+
tmux reads: full_graph
|
|
244
|
+
tmux filters: nothing
|
|
245
|
+
Ruby filters: active
|
|
246
|
+
matching panes: 1
|
|
247
|
+
```
|
|
248
|
+
|
|
184
249
|
## Create sessions, windows, and panes
|
|
185
250
|
|
|
186
251
|
### [`Server#new_session`][server-new_session]: a session and its first window
|
|
187
252
|
|
|
188
|
-
`
|
|
189
|
-
|
|
190
|
-
|
|
253
|
+
Omit `name:` to let tmux name the detached session. Omit `command:` to
|
|
254
|
+
use tmux's `default-command` or, when empty, `default-shell`. Pass an argv
|
|
255
|
+
array to run a specific program. The receipt includes the session, window
|
|
256
|
+
and pane IDs. Keep the session reference to target it by ID and read the
|
|
257
|
+
effective name from a snapshot.
|
|
191
258
|
|
|
192
259
|
<!-- example: api_new_session/main -->
|
|
193
260
|
```ruby
|
|
@@ -197,7 +264,9 @@ LibTmux::Server.start do |server|
|
|
|
197
264
|
created = server.new_session(
|
|
198
265
|
name: "work", window_name: "main", command: ["/bin/cat"], receipt: true
|
|
199
266
|
)
|
|
200
|
-
|
|
267
|
+
ref = created.entity.ref
|
|
268
|
+
puts "session: #{ref.id}"
|
|
269
|
+
puts "name: #{server.session(ref).snapshot.name}"
|
|
201
270
|
puts "window: #{created.window.id}"
|
|
202
271
|
puts "pane: #{created.pane.id}"
|
|
203
272
|
end
|
|
@@ -208,6 +277,7 @@ It prints:
|
|
|
208
277
|
|
|
209
278
|
```text
|
|
210
279
|
session: $0
|
|
280
|
+
name: work
|
|
211
281
|
window: @0
|
|
212
282
|
pane: %0
|
|
213
283
|
```
|
|
@@ -215,10 +285,13 @@ pane: %0
|
|
|
215
285
|
Creation returns once tmux has assigned the IDs. It says nothing about whether
|
|
216
286
|
the program started or exited cleanly.
|
|
217
287
|
|
|
288
|
+
More: [Session name behavior by tmux release][behavior-creation].
|
|
289
|
+
|
|
218
290
|
### [`Session#new_window`][session-new_window]: add a window
|
|
219
291
|
|
|
220
292
|
[`Pane#split`][pane-split] and [`Window#split`][window-split] add panes the
|
|
221
|
-
same way. A new window
|
|
293
|
+
same way. A new window accepts the same optional `name:` and `command:`
|
|
294
|
+
as a session. Splits also accept `command:`.
|
|
222
295
|
|
|
223
296
|
<!-- example: api_new_window/main -->
|
|
224
297
|
```ruby
|
|
@@ -257,31 +330,59 @@ The full contract is in [Creation][behavior-creation].
|
|
|
257
330
|
`send_text` types literal text, and [`send_keys`][pane-send_keys] sends tmux key
|
|
258
331
|
names such as `Enter`. [`Pane#capture`][pane-capture] reads the screen.
|
|
259
332
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
333
|
+
Poll the pane until the CLI prompts, then send a reply. This example needs
|
|
334
|
+
tmux 3.6 or newer to read the retained pane's exit status. A
|
|
335
|
+
[control connection][server-open_control] can report output as an event on
|
|
336
|
+
tmux 3.7 or newer.
|
|
263
337
|
|
|
264
338
|
<!-- example: api_capture/main -->
|
|
265
339
|
```ruby
|
|
266
340
|
require "libtmux"
|
|
341
|
+
require "rbconfig"
|
|
342
|
+
|
|
343
|
+
def wait_until(message)
|
|
344
|
+
deadline = Process.clock_gettime(Process::CLOCK_MONOTONIC) + 5
|
|
345
|
+
loop do
|
|
346
|
+
remaining = deadline - Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
347
|
+
raise message unless remaining.positive?
|
|
348
|
+
result = yield remaining
|
|
349
|
+
return result if result
|
|
350
|
+
|
|
351
|
+
sleep [0.02, remaining].min
|
|
352
|
+
end
|
|
353
|
+
end
|
|
354
|
+
|
|
355
|
+
command = [RbConfig.ruby, "-e", <<~'RUBY']
|
|
356
|
+
$stdout.sync = true
|
|
357
|
+
puts "What is your name?"
|
|
358
|
+
name = STDIN.gets or exit 1
|
|
359
|
+
puts "Hello, #{name.chomp}!"
|
|
360
|
+
RUBY
|
|
267
361
|
|
|
268
362
|
LibTmux::Server.start do |server|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
)
|
|
273
|
-
|
|
274
|
-
|
|
363
|
+
server.options(scope: :window).set("remain-on-exit", true)
|
|
364
|
+
pane = server.new_session(
|
|
365
|
+
name: "greeting", command: command, receipt: true
|
|
366
|
+
).pane
|
|
367
|
+
|
|
368
|
+
wait_until("CLI did not prompt for a name") do |remaining|
|
|
369
|
+
lines = pane.capture(timeout: remaining).text.lines(chomp: true)
|
|
370
|
+
lines.include?("What is your name?")
|
|
371
|
+
end
|
|
372
|
+
pane.send_text("Ada")
|
|
275
373
|
pane.send_keys("Enter")
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
374
|
+
|
|
375
|
+
status = wait_until("CLI did not report an exit status") do |remaining|
|
|
376
|
+
state = pane.snapshot(timeout: remaining)
|
|
377
|
+
state.dead_status if state.dead?
|
|
378
|
+
end
|
|
379
|
+
raise "CLI exited with status #{status}" unless status == 0
|
|
380
|
+
|
|
381
|
+
greeting = pane.capture(start: "-").text.lines(chomp: true).find do |line|
|
|
382
|
+
line == "Hello, Ada!"
|
|
282
383
|
end
|
|
283
|
-
raise "
|
|
284
|
-
puts
|
|
384
|
+
raise "CLI did not greet Ada" unless greeting
|
|
385
|
+
puts greeting
|
|
285
386
|
end
|
|
286
387
|
```
|
|
287
388
|
<!-- /example -->
|
|
@@ -289,10 +390,10 @@ end
|
|
|
289
390
|
It prints:
|
|
290
391
|
|
|
291
392
|
```text
|
|
292
|
-
|
|
393
|
+
Hello, Ada!
|
|
293
394
|
```
|
|
294
395
|
|
|
295
|
-
-
|
|
396
|
+
- `remain-on-exit` keeps the screen and exit status available after the CLI exits.
|
|
296
397
|
- `capture` returns the visible screen. `start:` and `finish:` choose a range,
|
|
297
398
|
and `join:` joins wrapped lines.
|
|
298
399
|
- `escapes:`, `escape_bytes:`, `preserve_trailing:` and `trim_trailing:` change
|
|
@@ -306,6 +407,65 @@ libtmux capture ready
|
|
|
306
407
|
|
|
307
408
|
The full contract is in [Pane input and capture][behavior-capture].
|
|
308
409
|
|
|
410
|
+
## Check what the daemon supports
|
|
411
|
+
|
|
412
|
+
### [`Server#capabilities`][server-capabilities]: feature requirements and decisions
|
|
413
|
+
|
|
414
|
+
Read the connected daemon's feature report. Use its support query before
|
|
415
|
+
choosing an optional operation, or inspect the required release and refusal.
|
|
416
|
+
|
|
417
|
+
<!-- example: api_capabilities/main -->
|
|
418
|
+
```ruby
|
|
419
|
+
require "libtmux"
|
|
420
|
+
|
|
421
|
+
LibTmux::Server.start do |server|
|
|
422
|
+
report = server.capabilities
|
|
423
|
+
feature = report.feature("layout-json")
|
|
424
|
+
puts "JSON layouts require tmux #{feature.since}"
|
|
425
|
+
puts "Refusal: #{feature.error}"
|
|
426
|
+
end
|
|
427
|
+
```
|
|
428
|
+
<!-- /example -->
|
|
429
|
+
|
|
430
|
+
```text
|
|
431
|
+
JSON layouts require tmux 3.8
|
|
432
|
+
Refusal: LibTmux::UnsupportedFeatureError
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
More: [Support queries, workarounds and snapshot limits][behavior-capabilities].
|
|
436
|
+
|
|
437
|
+
### [`Pane#wait_for_text`][pane-wait_for_text]: wait for a program reply
|
|
438
|
+
|
|
439
|
+
Choose a reply that differs from the input. tmux can echo what you type.
|
|
440
|
+
|
|
441
|
+
<!-- example: api_text_wait/main -->
|
|
442
|
+
```ruby
|
|
443
|
+
require "libtmux"
|
|
444
|
+
|
|
445
|
+
program = <<~'RUBY'
|
|
446
|
+
STDOUT.sync = true
|
|
447
|
+
puts "Reply from the fixture" if gets&.chomp == "green"
|
|
448
|
+
STDIN.read
|
|
449
|
+
RUBY
|
|
450
|
+
|
|
451
|
+
LibTmux::Server.start do |server|
|
|
452
|
+
pane = server.new_session(name: "reply", command: [Gem.ruby, "-e", program],
|
|
453
|
+
receipt: true).pane
|
|
454
|
+
pane.send_text("green")
|
|
455
|
+
pane.send_keys("Enter")
|
|
456
|
+
|
|
457
|
+
reply = "Reply from the fixture"
|
|
458
|
+
result = pane.wait_for_text(reply)
|
|
459
|
+
puts result.text.lines(chomp: true).map(&:rstrip).find { |line| line == reply }
|
|
460
|
+
end
|
|
461
|
+
```
|
|
462
|
+
<!-- /example -->
|
|
463
|
+
|
|
464
|
+
It prints `Reply from the fixture`. The wait searches the visible screen and
|
|
465
|
+
includes output printed by the native `after-capture-pane` hook.
|
|
466
|
+
|
|
467
|
+
More: [Pane text waits][behavior-text-waits].
|
|
468
|
+
|
|
309
469
|
## Use the tmux server you already run
|
|
310
470
|
|
|
311
471
|
### [`Server.new`][server-new]: borrow a daemon
|
|
@@ -369,7 +529,8 @@ LibTmux::Server.start do |server|
|
|
|
369
529
|
server.new_session(name: "work", command: ["/bin/cat"])
|
|
370
530
|
cancellation = LibTmux::Cancellation.new
|
|
371
531
|
waiting = Thread.new do
|
|
372
|
-
server.run(["wait-for", "-S", "ready", ";", "wait-for", "held"],
|
|
532
|
+
server.run(["wait-for", "-S", "ready", ";", "wait-for", "held"],
|
|
533
|
+
timeout: 5, cancel: cancellation)
|
|
373
534
|
rescue LibTmux::Cancelled => error
|
|
374
535
|
error
|
|
375
536
|
end
|
|
@@ -378,7 +539,13 @@ LibTmux::Server.start do |server|
|
|
|
378
539
|
failure = waiting.value
|
|
379
540
|
puts "request: #{failure.class}"
|
|
380
541
|
puts "delivery: #{failure.delivery}"
|
|
381
|
-
|
|
542
|
+
ensure
|
|
543
|
+
begin
|
|
544
|
+
cancellation&.cancel
|
|
545
|
+
waiting&.join
|
|
546
|
+
ensure
|
|
547
|
+
cancellation&.close
|
|
548
|
+
end
|
|
382
549
|
end
|
|
383
550
|
```
|
|
384
551
|
<!-- /example -->
|
|
@@ -430,11 +597,9 @@ windows: @0
|
|
|
430
597
|
```
|
|
431
598
|
|
|
432
599
|
- Select, unlink, move, swap and display check the whole link identity in the
|
|
433
|
-
same tmux queue turn as the operation
|
|
434
|
-
- A hook that waits before dispatch cannot turn a stale link into its
|
|
600
|
+
same tmux queue turn as the operation, so a stale link never becomes its
|
|
435
601
|
replacement.
|
|
436
|
-
- Rewriting command aliases during an operation is outside that guarantee
|
|
437
|
-
coordinate configuration changes.
|
|
602
|
+
- Rewriting command aliases during an operation is outside that guarantee.
|
|
438
603
|
|
|
439
604
|
The contract is in [Window links][behavior-window-links], and the
|
|
440
605
|
[linked-windows recipe](../../docs/recipes.md#one-window-at-three-indexes)
|
|
@@ -484,6 +649,8 @@ hook: display-message created
|
|
|
484
649
|
|
|
485
650
|
The contracts are in [Options and hooks][behavior-options] and
|
|
486
651
|
[Option values][behavior-option-values].
|
|
652
|
+
Look up built-in types, choices and hook scopes in the
|
|
653
|
+
[option catalog][behavior-option-catalog].
|
|
487
654
|
|
|
488
655
|
## Watch tmux change
|
|
489
656
|
|
|
@@ -507,7 +674,10 @@ LibTmux::Server.start do |server|
|
|
|
507
674
|
puts "reply: #{reply.blocks.last.body.strip}"
|
|
508
675
|
events = control.subscribe(max_events: 64, max_bytes: 65_536)
|
|
509
676
|
window.rename("renamed")
|
|
510
|
-
event =
|
|
677
|
+
event = nil
|
|
678
|
+
until event&.raw&.start_with?("%window-renamed")
|
|
679
|
+
event = events.next(timeout: 5)
|
|
680
|
+
end
|
|
511
681
|
puts "event: #{event.raw.strip}"
|
|
512
682
|
end
|
|
513
683
|
end
|
|
@@ -612,21 +782,37 @@ application owns. Require `libtmux/async`, then open a scope with
|
|
|
612
782
|
$ gem install libtmux-async
|
|
613
783
|
```
|
|
614
784
|
|
|
615
|
-
Capture every pane concurrently with [`Scope#map`][async-scope-map]
|
|
616
|
-
is an open [`LibTmux::Server`][server]:
|
|
785
|
+
Capture every pane concurrently with [`Scope#map`][async-scope-map]:
|
|
617
786
|
|
|
618
|
-
<!-- example:
|
|
787
|
+
<!-- example: api_async_scope/main -->
|
|
619
788
|
```ruby
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
789
|
+
require "libtmux"
|
|
790
|
+
require "libtmux/async"
|
|
791
|
+
|
|
792
|
+
LibTmux::Server.start do |server|
|
|
793
|
+
server.new_session(name: "work", command: ["/bin/cat"])
|
|
794
|
+
server.new_session(name: "logs", command: ["/bin/cat"])
|
|
795
|
+
Async do |parent|
|
|
796
|
+
LibTmux::Async.open(parent: parent, server: server) do |scope|
|
|
797
|
+
refs = scope.server.list_panes.map(&:ref)
|
|
798
|
+
screens = scope.map(refs, concurrency: 2) do |ref|
|
|
799
|
+
scope.server.pane(ref).capture
|
|
800
|
+
end
|
|
801
|
+
puts "captured panes: #{screens.length}"
|
|
802
|
+
puts "all succeeded: #{screens.all?(&:success?)}"
|
|
803
|
+
end
|
|
804
|
+
end.wait
|
|
805
|
+
end
|
|
627
806
|
```
|
|
628
807
|
<!-- /example -->
|
|
629
808
|
|
|
809
|
+
It prints:
|
|
810
|
+
|
|
811
|
+
```text
|
|
812
|
+
captured panes: 2
|
|
813
|
+
all succeeded: true
|
|
814
|
+
```
|
|
815
|
+
|
|
630
816
|
### [libtmux-mcp](https://github.com/libtmux/libtmux-ruby/tree/master/gems/libtmux-mcp): a tmux server for MCP clients
|
|
631
817
|
|
|
632
818
|
An MCP server over stdio for one tmux server, with an explicit tool policy.
|
|
@@ -642,19 +828,17 @@ Installs `libtmux-mcp`; require `libtmux/mcp` to embed it through
|
|
|
642
828
|
$ gem install libtmux-mcp
|
|
643
829
|
```
|
|
644
830
|
|
|
645
|
-
|
|
646
|
-
socket
|
|
647
|
-
|
|
648
|
-
```console
|
|
649
|
-
$ tmux -L agent new-session -d -s work
|
|
650
|
-
```
|
|
651
|
-
|
|
652
|
-
Add the server to Claude Code. Until you enable more tools, it serves
|
|
831
|
+
Add the server to Claude Code. `--start-session work` starts a tmux server on
|
|
832
|
+
the socket `agent` when none answers there, with a session named `work`, and
|
|
833
|
+
stops it when the server exits. Until you enable more tools, the server serves
|
|
653
834
|
[`tmux_capabilities`][tool-tmux_capabilities] and
|
|
654
835
|
[`tmux_snapshot`][tool-tmux_snapshot]:
|
|
655
836
|
|
|
656
837
|
```console
|
|
657
|
-
$ claude mcp add tmux -- libtmux-mcp
|
|
838
|
+
$ claude mcp add tmux -- libtmux-mcp \
|
|
839
|
+
--socket-name agent \
|
|
840
|
+
--start-session work \
|
|
841
|
+
--endpoint dev
|
|
658
842
|
```
|
|
659
843
|
|
|
660
844
|
The [MCP README](../libtmux-mcp/README.md) covers other clients, every tool and
|
|
@@ -713,45 +897,36 @@ server and lists every option.
|
|
|
713
897
|
[Live handles][behavior-live-handles].
|
|
714
898
|
- **A terminal emulator.** [`Pane#capture`][pane-capture] returns the bytes
|
|
715
899
|
tmux holds for the screen, with the flags above to shape them.
|
|
716
|
-
- **A server it starts
|
|
717
|
-
[`Server.open`][server-open] bind a running server
|
|
718
|
-
|
|
719
|
-
`
|
|
720
|
-
|
|
900
|
+
- **A server it starts unasked.** [`Server.new`][server-new] and
|
|
901
|
+
[`Server.open`][server-open] bind a running server; only
|
|
902
|
+
[`Server.start`][server-start] starts one. With no socket named,
|
|
903
|
+
[`Endpoint.new`][endpoint-new] picks the socket tmux would, so a program run
|
|
904
|
+
inside tmux reaches that tmux.
|
|
721
905
|
- **Replay.** A reconnected control connection reports a gap and never replays
|
|
722
906
|
requests or missed output. See [Control flow][behavior-control-flow].
|
|
723
907
|
- **Transactions.** A [group][server-run_group] runs in order and keeps the
|
|
724
908
|
effects of the steps before a failure.
|
|
725
|
-
- **Whole-program typing.** RBS declarations ship with the gem
|
|
726
|
-
|
|
909
|
+
- **Whole-program typing.** RBS declarations ship with the gem. See
|
|
910
|
+
[Signature proof][behavior-signature].
|
|
727
911
|
|
|
728
912
|
## Support and status
|
|
729
913
|
|
|
730
|
-
Releases are numbered `0.1.N`, and
|
|
731
|
-
|
|
732
|
-
changelog
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
- **Ruby 3.3 or newer
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
[server handle][server] checks the connected daemon's release before it sends
|
|
739
|
-
a command, and refuses an older daemon even when its client is newer.
|
|
914
|
+
- **Unstable API.** Releases are numbered `0.1.N`, and any release may change
|
|
915
|
+
or remove exported identifiers. Pin an exact version. See the
|
|
916
|
+
[changelog](CHANGELOG.md), and the [main
|
|
917
|
+
changelog](https://github.com/libtmux/libtmux-ruby/blob/master/CHANGELOG.md)
|
|
918
|
+
for changes that span gems.
|
|
919
|
+
- **Ruby 3.3 or newer** and **tmux 3.3a or newer.** A [server handle][server]
|
|
920
|
+
checks the connected daemon's release before it runs a command, and refuses
|
|
921
|
+
an older daemon even when its client is newer.
|
|
740
922
|
- **Control connections need tmux 3.7 or newer.** An older daemon refuses
|
|
741
923
|
[`open_control`][server-open_control] before a control client attaches.
|
|
742
924
|
Subprocess operations and snapshots do not need it. The
|
|
743
925
|
[optional feature table](../../docs/reference/behavior.md#optional-tmux-features)
|
|
744
|
-
lists the other
|
|
745
|
-
- **Linux, including WSL, and macOS.**
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
and a release runs all of them. macOS is supported on a best-effort basis, and CI coverage for it is highly
|
|
749
|
-
limited.
|
|
750
|
-
- **tmux master and old daemons.** On Ubuntu a release also runs the suite
|
|
751
|
-
against a pinned tmux master, and checks that tmux 3.0a, 3.1c, 3.2a and 3.3
|
|
752
|
-
daemons are refused.
|
|
753
|
-
- **Per-revision results.** Read the workflow's results for your revision
|
|
754
|
-
before relying on one combination.
|
|
926
|
+
lists the other releases.
|
|
927
|
+
- **Linux, including WSL, and macOS.** CI runs on Linux; macOS is best effort.
|
|
928
|
+
See the [compatibility workflow][compat] and the
|
|
929
|
+
[CI matrix](../../.github/CONTRIBUTING.md#running-ci-against-any-tmux).
|
|
755
930
|
|
|
756
931
|
## Documentation
|
|
757
932
|
|
|
@@ -759,7 +934,7 @@ See the [changelog](../../CHANGELOG.md).
|
|
|
759
934
|
| --- | --- |
|
|
760
935
|
| [Reference](https://libtmux.org/en/ruby/latest/reference/) | Every public class and method, one page each |
|
|
761
936
|
| [Guides](https://libtmux.org/en/ruby/latest/guides/) | Getting started, server bindings and the Async scope |
|
|
762
|
-
| [Recipes](../../docs/recipes.md) | Complete programs
|
|
937
|
+
| [Recipes](../../docs/recipes.md) | Complete programs and their excerpts |
|
|
763
938
|
| [Execution modes](../../docs/modes.md) | Blocking calls, Async tasks and control subscriptions |
|
|
764
939
|
| [Ownership and errors](../../docs/ownership-errors.md) | What close and failure mean |
|
|
765
940
|
| [Public behavior](../../docs/reference/behavior.md) | Defaults, ownership, blocking and failure of each call |
|
|
@@ -773,12 +948,14 @@ MIT. See [LICENSE](LICENSE).
|
|
|
773
948
|
[async-scope-map]: https://libtmux.org/en/ruby/latest/reference/libtmux-async-scope-map/
|
|
774
949
|
[behavior-cancellation]: ../../docs/reference/behavior.md#cancellation-tokens
|
|
775
950
|
[behavior-capture]: ../../docs/reference/behavior.md#pane-input-and-capture
|
|
951
|
+
[behavior-text-waits]: ../../docs/reference/behavior.md#pane-text-waits
|
|
776
952
|
[behavior-control]: ../../docs/reference/behavior.md#control-connections
|
|
777
953
|
[behavior-control-flow]: ../../docs/reference/behavior.md#control-flow
|
|
778
954
|
[behavior-creation]: ../../docs/reference/behavior.md#creation
|
|
779
955
|
[behavior-live-handles]: ../../docs/reference/behavior.md#live-handles
|
|
780
956
|
[behavior-option-values]: ../../docs/reference/behavior.md#option-values
|
|
781
957
|
[behavior-options]: ../../docs/reference/behavior.md#options-and-hooks
|
|
958
|
+
[behavior-option-catalog]: ../../docs/reference/behavior.md#option-catalog
|
|
782
959
|
[behavior-records]: ../../docs/reference/behavior.md#captured-records
|
|
783
960
|
[behavior-signature]: ../../docs/reference/behavior.md#signature-proof
|
|
784
961
|
[behavior-window-links]: ../../docs/reference/behavior.md#window-links
|
|
@@ -810,6 +987,7 @@ MIT. See [LICENSE](LICENSE).
|
|
|
810
987
|
[optionvalue-as]: https://libtmux.org/en/ruby/latest/reference/libtmux-optionvalue-as/
|
|
811
988
|
[pane]: https://libtmux.org/en/ruby/latest/reference/libtmux-pane-14z6/
|
|
812
989
|
[pane-capture]: https://libtmux.org/en/ruby/latest/reference/libtmux-pane-capture/
|
|
990
|
+
[pane-wait_for_text]: https://libtmux.org/en/ruby/latest/reference/libtmux-pane-wait_for_text/
|
|
813
991
|
[pane-send_keys]: https://libtmux.org/en/ruby/latest/reference/libtmux-pane-send_keys/
|
|
814
992
|
[pane-send_text]: https://libtmux.org/en/ruby/latest/reference/libtmux-pane-send_text/
|
|
815
993
|
[pane-split]: https://libtmux.org/en/ruby/latest/reference/libtmux-pane-split/
|
|
@@ -848,3 +1026,6 @@ MIT. See [LICENSE](LICENSE).
|
|
|
848
1026
|
[window-split]: https://libtmux.org/en/ruby/latest/reference/libtmux-window-split/
|
|
849
1027
|
[windowlink]: https://libtmux.org/en/ruby/latest/reference/libtmux-windowlink-tusj/
|
|
850
1028
|
[workspace]: https://libtmux.org/en/ruby/latest/workspace/reference/libtmux-workspace/
|
|
1029
|
+
|
|
1030
|
+
[server-capabilities]: https://libtmux.org/en/ruby/latest/reference/libtmux-server-capabilities/
|
|
1031
|
+
[behavior-capabilities]: ../../docs/reference/behavior.md#daemon-capabilities
|