libtmux 0.1.0 → 0.1.2
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 +89 -0
- data/README.md +25 -12
- data/lib/libtmux/capabilities.rb +22 -11
- data/lib/libtmux/endpoint.rb +70 -17
- data/lib/libtmux/entity.rb +1 -1
- data/lib/libtmux/native_guard.rb +8 -2
- data/lib/libtmux/server.rb +103 -59
- data/lib/libtmux/version.rb +1 -1
- data/sig/libtmux.rbs +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9c7861118a25d65384377328a89e53c6507e86cb637b3a2031ecb9e8ec143f3b
|
|
4
|
+
data.tar.gz: 7b31dfde49f96cbb624e132669f51243b2fe9a532a59e9aef54de1e68aa9834e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 787ba61c6486d96e3c4545b2ee54cc2218df87cbcee97ba2ec27a9f7c5100a75447299f8f7fbfae80e7654be68126a03fd859d4d27210be6a8e48328302d1555
|
|
7
|
+
data.tar.gz: 1f95dd29c8d83649cedabbe5de990b210115f207484d67942c86a254d504292a7108ff6758555437e1c1b37cefdf769530d5fa0b29a21b6cbb8c29c7e597e89c
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
Notable changes to `libtmux`.
|
|
4
|
+
|
|
5
|
+
Releases are numbered `0.1.N`, and each release increments `N`. The API is not
|
|
6
|
+
settled: pin an exact version to avoid a break.
|
|
7
|
+
|
|
8
|
+
The gems are released together at one version, so every release has a section
|
|
9
|
+
here. Changes that span gems, such as documentation, CI and release tooling, are
|
|
10
|
+
in the [main changelog](../../CHANGELOG.md).
|
|
11
|
+
|
|
12
|
+
## 0.1.3 (unreleased)
|
|
13
|
+
|
|
14
|
+
## 0.1.2 (2026-11-04)
|
|
15
|
+
|
|
16
|
+
No entries for `libtmux`.
|
|
17
|
+
|
|
18
|
+
## 0.1.1 (2026-10-31)
|
|
19
|
+
|
|
20
|
+
- `Window#select_layout` accepts a JSON layout only on tmux 3.8 or newer, and
|
|
21
|
+
raw `select-layout`, including control lines, now refuses one below tmux 3.8
|
|
22
|
+
instead of sending it. The `UnsupportedFeatureError` names tmux 3.8 as the
|
|
23
|
+
minimum; upgrade tmux, or apply a checksummed layout. (#67)
|
|
24
|
+
- **Behavior change:** `Endpoint.new`, `Server.new` and `Server.open` no longer
|
|
25
|
+
need a socket. With no `socket_path:` or `socket_name:`, they pick the socket
|
|
26
|
+
tmux picks when it is given none: the path in `LIBTMUX_SOCKET_PATH`, else the
|
|
27
|
+
name in `LIBTMUX_SOCKET`, else the socket `TMUX` names inside tmux, else
|
|
28
|
+
tmux's default socket. They raised `ArgumentError` before. A program started
|
|
29
|
+
inside tmux that names no socket now reaches that tmux's server; pass
|
|
30
|
+
`socket_name:` or `socket_path:` to keep it off, as a test suite should.
|
|
31
|
+
`Endpoint.from_env` still follows `TMUX` alone. Two edge cases now match
|
|
32
|
+
tmux: an empty `TMUX_TMPDIR` means `/tmp`, where `Endpoint.new(socket_name:)`
|
|
33
|
+
raised, and `Endpoint.from_env` reads `TMUX_TMPDIR` only from the hash it is
|
|
34
|
+
given and ignores a `TMUX` that starts with a comma, where it raised. (#71)
|
|
35
|
+
|
|
36
|
+
## 0.1.0 (2026-10-25)
|
|
37
|
+
|
|
38
|
+
No entries for `libtmux`.
|
|
39
|
+
|
|
40
|
+
## 0.1.0.alpha.3 (2026-10-24)
|
|
41
|
+
|
|
42
|
+
### libtmux
|
|
43
|
+
|
|
44
|
+
- Refuse commands that misbehave on one tmux release before they run: named
|
|
45
|
+
buffer deletion and rename below 3.4, raw `break-pane` and colon or period
|
|
46
|
+
names on exact 3.7, raw `split-window -p` on 3.4, and malformed layouts below
|
|
47
|
+
3.4. `Pane#break_out` now works on exact 3.7 and for a sole pane. Refusals
|
|
48
|
+
raise `UnsupportedFeatureError`. (#37)
|
|
49
|
+
- Raw `refresh-client -l`, in `Server#run` or a control line, raises
|
|
50
|
+
`UnsupportedFeatureError` below tmux 3.6a. On 3.3a, asking an attached
|
|
51
|
+
terminal for its clipboard stops the server, and on 3.4 through 3.6 the
|
|
52
|
+
server stops when that client leaves before its terminal answers. (#37)
|
|
53
|
+
- Snapshots and the daemon identity check no longer fire `after-display-message`
|
|
54
|
+
hooks. (#37)
|
|
55
|
+
- Record every tmux release gate in one internal registry and emit it as the
|
|
56
|
+
root `capabilities.json` manifest, which the docs site reads for its
|
|
57
|
+
capability pages. `Window#select_layout` raises `UnsupportedFeatureError`,
|
|
58
|
+
not `ArgumentError`, for a JSON layout below tmux 3.8-rc2. (#37)
|
|
59
|
+
|
|
60
|
+
## 0.1.0.alpha.2 (2026-10-18)
|
|
61
|
+
|
|
62
|
+
### libtmux
|
|
63
|
+
|
|
64
|
+
- Run on tmux 3.8 and tmux master (`next-3.9`). Snapshots decode metadata
|
|
65
|
+
with line feeds, `select_layout` accepts the JSON layouts that 3.8-rc2 and
|
|
66
|
+
later report, and owned servers start on releases that log more at startup.
|
|
67
|
+
(#36)
|
|
68
|
+
- **Breaking:** `Server.new` now reads the daemon's tmux release and blocks
|
|
69
|
+
for up to `version_timeout:` seconds (default five), so a socket with no
|
|
70
|
+
daemon raises `TargetNotFoundError` at construction instead of at the first
|
|
71
|
+
command. Read the result with the new `Server#tmux_version`. (#36)
|
|
72
|
+
|
|
73
|
+
## 0.1.0.alpha.1 (2026-09-20)
|
|
74
|
+
|
|
75
|
+
### libtmux
|
|
76
|
+
|
|
77
|
+
- Create sessions, windows and panes; arrange layouts, send text or keys, and
|
|
78
|
+
capture output through Ruby handles. Manage options, hooks, environment
|
|
79
|
+
values and binary buffers. [Quick start](../../README.md#quick-start).
|
|
80
|
+
- Start a private tmux server with `LibTmux::Server.start`, or borrow an
|
|
81
|
+
existing socket with `Server.open`. Block exit cleans up owned clients;
|
|
82
|
+
borrowed daemons stay running. [Ownership](../../docs/ownership-errors.md).
|
|
83
|
+
- Query immutable snapshots with `where`, `select`, `one`, `one_or_nil` and
|
|
84
|
+
`Enumerable`, without further tmux calls. `WindowLink` addresses a window's
|
|
85
|
+
placement in a session, including repeated links to the same window.
|
|
86
|
+
[Queries](../../examples/list_filter.rb) · [Linked windows](../../examples/window_links.rb).
|
|
87
|
+
- Use command deadlines and cancellation tokens, or subscribe to bounded
|
|
88
|
+
control-mode events with explicit overflow and gap reporting.
|
|
89
|
+
[Execution modes](../../docs/modes.md).
|
data/README.md
CHANGED
|
@@ -19,6 +19,9 @@ 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://libtmux.org/en/ruby/)
|
|
23
|
+
[](https://rubygems.org/gems/libtmux)
|
|
24
|
+
|
|
22
25
|
</div>
|
|
23
26
|
|
|
24
27
|
Part of [libtmux for Ruby](https://github.com/libtmux/libtmux-ruby#readme).
|
|
@@ -338,8 +341,10 @@ connected sessions: 1
|
|
|
338
341
|
sessions after client close: 1
|
|
339
342
|
```
|
|
340
343
|
|
|
341
|
-
- [`Endpoint.new`][endpoint-new] takes
|
|
342
|
-
|
|
344
|
+
- [`Endpoint.new`][endpoint-new] takes a socket path or socket name. With
|
|
345
|
+
neither, it picks the socket tmux would: `LIBTMUX_SOCKET_PATH`,
|
|
346
|
+
`LIBTMUX_SOCKET`, the server `$TMUX` names, then tmux's default socket.
|
|
347
|
+
[`Endpoint.from_env`][endpoint-from_env] follows `$TMUX` alone.
|
|
343
348
|
- A binding keeps a private link to the socket it bound, so commands never
|
|
344
349
|
reach a different daemon that later takes the same path.
|
|
345
350
|
- A ref is valid on the server that issued it. Another server raises
|
|
@@ -607,8 +612,9 @@ application owns. Require `libtmux/async`, then open a scope with
|
|
|
607
612
|
$ gem install libtmux-async
|
|
608
613
|
```
|
|
609
614
|
|
|
610
|
-
Capture every pane concurrently with [`Scope#map`][async-scope-map].
|
|
611
|
-
|
|
615
|
+
Capture every pane concurrently with [`Scope#map`][async-scope-map]. This
|
|
616
|
+
excerpt uses an open [`LibTmux::Server`][server] and the `Example.check`
|
|
617
|
+
assertion helper from the [complete program](../../examples/async_cancel.rb):
|
|
612
618
|
|
|
613
619
|
<!-- example: async_cancel/map -->
|
|
614
620
|
```ruby
|
|
@@ -708,8 +714,11 @@ server and lists every option.
|
|
|
708
714
|
[Live handles][behavior-live-handles].
|
|
709
715
|
- **A terminal emulator.** [`Pane#capture`][pane-capture] returns the bytes
|
|
710
716
|
tmux holds for the screen, with the flags above to shape them.
|
|
711
|
-
- **
|
|
712
|
-
|
|
717
|
+
- **A server it starts on its own.** [`Server.new`][server-new] and
|
|
718
|
+
[`Server.open`][server-open] bind a running server and never start one. With
|
|
719
|
+
no socket named, [`Endpoint.new`][endpoint-new] picks the one tmux would:
|
|
720
|
+
`LIBTMUX_SOCKET_PATH`, `LIBTMUX_SOCKET`, the server `TMUX` names, then tmux's
|
|
721
|
+
default socket. The recipes name a socket or own one.
|
|
713
722
|
- **Replay.** A reconnected control connection reports a gap and never replays
|
|
714
723
|
requests or missed output. See [Control flow][behavior-control-flow].
|
|
715
724
|
- **Transactions.** A [group][server-run_group] runs in order and keeps the
|
|
@@ -721,24 +730,28 @@ server and lists every option.
|
|
|
721
730
|
|
|
722
731
|
Releases are numbered `0.1.N`, and each release increments `N`. The API is not
|
|
723
732
|
settled: any release may change or remove exported identifiers, and the
|
|
724
|
-
|
|
725
|
-
See the [changelog](
|
|
733
|
+
changelogs mark each break. Pin an exact version to avoid one.
|
|
734
|
+
See the [changelog](CHANGELOG.md), and the [main
|
|
735
|
+
changelog](https://github.com/libtmux/libtmux-ruby/blob/master/CHANGELOG.md)
|
|
736
|
+
for changes that span gems.
|
|
726
737
|
|
|
727
738
|
- **Ruby 3.3 or newer.** The gem depends on `json`, `tmpdir`, `securerandom`,
|
|
728
739
|
`fiddle` and `io-console`.
|
|
729
740
|
- **tmux 3.3a or newer.** Unpatched 3.3 is below the minimum. A
|
|
730
741
|
[server handle][server] checks the connected daemon's release before it sends
|
|
731
|
-
|
|
742
|
+
the requested command, and refuses an older daemon even when its client is
|
|
743
|
+
newer.
|
|
732
744
|
- **Control connections need tmux 3.7 or newer.** An older daemon refuses
|
|
733
745
|
[`open_control`][server-open_control] before a control client attaches.
|
|
734
746
|
Subprocess operations and snapshots do not need it. The
|
|
735
747
|
[optional feature table](../../docs/reference/behavior.md#optional-tmux-features)
|
|
736
748
|
lists the other per-release requirements.
|
|
737
749
|
- **Linux, including WSL, and macOS.** The [compatibility workflow][compat]
|
|
738
|
-
runs Ruby 3.3, 3.4 and 4.0 with tmux 3.3a through 3.8 on Ubuntu 24.04.
|
|
739
|
-
|
|
750
|
+
runs Ruby 3.3, 3.4 and 4.0 with tmux 3.3a through 3.8 on Ubuntu 24.04. A push
|
|
751
|
+
and a pull request run the oldest and newest of those releases, 3.3a and 3.8,
|
|
752
|
+
and a release runs all of them. macOS is supported on a best-effort basis, and CI coverage for it is highly
|
|
740
753
|
limited.
|
|
741
|
-
- **tmux master and old daemons.** On Ubuntu
|
|
754
|
+
- **tmux master and old daemons.** On Ubuntu a release also runs the suite
|
|
742
755
|
against a pinned tmux master, and checks that tmux 3.0a, 3.1c, 3.2a and 3.3
|
|
743
756
|
daemons are refused.
|
|
744
757
|
- **Per-revision results.** Read the workflow's results for your revision
|
data/lib/libtmux/capabilities.rb
CHANGED
|
@@ -68,37 +68,48 @@ module LibTmux
|
|
|
68
68
|
end
|
|
69
69
|
end
|
|
70
70
|
|
|
71
|
+
# Public methods that send a tmux command line the caller wrote. The
|
|
72
|
+
# command guard reads each line, so a capability it consults can refuse
|
|
73
|
+
# a command through any of them, and only for the command it gates.
|
|
74
|
+
RUN_CHANNELS = %w[
|
|
75
|
+
LibTmux::Server#run LibTmux::Server#run_group LibTmux::Async::Server#run LibTmux::Async::Server#run_group
|
|
76
|
+
].freeze
|
|
77
|
+
# The control-client channels, which reach a capability only on a tmux
|
|
78
|
+
# that accepts control clients.
|
|
79
|
+
CONTROL_CHANNELS = %w[LibTmux::ControlConnection#exchange LibTmux::Async::ControlConnection#exchange].freeze
|
|
80
|
+
|
|
71
81
|
CAPABILITIES = [
|
|
72
82
|
Capability.new(id: "control-mode", name: "Control mode", since: "3.7", handling: :refuse, error: ERROR,
|
|
73
83
|
summary: "Attach a library-managed control client and stream events.",
|
|
74
|
-
apis: ["LibTmux::Server#open_control", "LibTmux::
|
|
84
|
+
apis: ["LibTmux::Server#open_control", "LibTmux::Async::Server#open_control",
|
|
85
|
+
"LibTmux::ControlConnection.open", "LibTmux::ControlConnection.new"],
|
|
75
86
|
commands: [Command.new(command: "attach-session")]),
|
|
76
87
|
Capability.new(id: "buffer-delete-named", name: "Named buffer deletion", since: "3.4", handling: :refuse, error: ERROR,
|
|
77
88
|
summary: "Delete one paste buffer by name without risking another buffer.",
|
|
78
|
-
apis: ["LibTmux::Server#delete_buffer", "LibTmux::Server#
|
|
89
|
+
apis: ["LibTmux::Server#delete_buffer", "LibTmux::Async::Server#delete_buffer", *RUN_CHANNELS],
|
|
79
90
|
commands: [Command.new(command: "delete-buffer", flags: ["-b"])]),
|
|
80
91
|
Capability.new(id: "buffer-rename", name: "Buffer rename", since: "3.4", handling: :refuse, error: ERROR,
|
|
81
92
|
summary: "Rename a paste buffer without risking another buffer.",
|
|
82
|
-
apis:
|
|
93
|
+
apis: RUN_CHANNELS,
|
|
83
94
|
commands: [Command.new(command: "set-buffer", flags: ["-b", "-n"])]),
|
|
84
95
|
Capability.new(id: "layout-without-checksum", name: "Layouts without a checksum", since: "3.4",
|
|
85
96
|
handling: :refuse, error: ERROR,
|
|
86
97
|
summary: "Apply a layout string or a named layout that tmux validates before use.",
|
|
87
|
-
apis: ["LibTmux::Window#select_layout",
|
|
98
|
+
apis: ["LibTmux::Window#select_layout", *RUN_CHANNELS],
|
|
88
99
|
commands: [Command.new(command: "select-layout")]),
|
|
89
100
|
Capability.new(id: "layout-mirrored-main", name: "Mirrored main layouts", since: "3.5",
|
|
90
101
|
handling: :refuse, error: ERROR,
|
|
91
102
|
summary: "Apply main-horizontal-mirrored and main-vertical-mirrored.",
|
|
92
103
|
apis: ["LibTmux::Window#select_layout"],
|
|
93
104
|
commands: [Command.new(command: "select-layout")]),
|
|
94
|
-
Capability.new(id: "layout-json", name: "JSON layout strings", since: "3.8
|
|
105
|
+
Capability.new(id: "layout-json", name: "JSON layout strings", since: "3.8",
|
|
95
106
|
handling: :refuse, error: ERROR,
|
|
96
107
|
summary: "Apply a layout saved in the JSON form tmux reports.",
|
|
97
|
-
apis: ["LibTmux::Window#select_layout"],
|
|
108
|
+
apis: ["LibTmux::Window#select_layout", *RUN_CHANNELS, *CONTROL_CHANNELS],
|
|
98
109
|
commands: [Command.new(command: "select-layout")]),
|
|
99
110
|
Capability.new(id: "clipboard-query", name: "Clipboard query", since: "3.6a", handling: :refuse, error: ERROR,
|
|
100
111
|
summary: "Ask an attached client's terminal for its clipboard with refresh-client -l.",
|
|
101
|
-
apis: [
|
|
112
|
+
apis: [*RUN_CHANNELS, *CONTROL_CHANNELS],
|
|
102
113
|
commands: [Command.new(command: "refresh-client", flags: ["-l"])])
|
|
103
114
|
].freeze
|
|
104
115
|
|
|
@@ -106,18 +117,18 @@ module LibTmux
|
|
|
106
117
|
Workaround.new(id: "break-pane-misnames-windows", name: "break-pane window naming", releases: ["3.7"],
|
|
107
118
|
handling: :repair,
|
|
108
119
|
summary: "break-pane gets the new window wrong on exactly tmux 3.7; Pane#break_out names it again, and raw break-pane is refused. A nested break-pane is not checked and stops an exact 3.7 daemon: name every one with -n, which avoids the crash while 3.7 still ignores the name, or upgrade to 3.7a.",
|
|
109
|
-
apis: ["LibTmux::Pane#break_out",
|
|
120
|
+
apis: ["LibTmux::Pane#break_out", *RUN_CHANNELS, *CONTROL_CHANNELS],
|
|
110
121
|
commands: [Command.new(command: "break-pane")]),
|
|
111
122
|
Workaround.new(id: "split-window-percent-size", name: "split-window -p", releases: ["3.4"],
|
|
112
123
|
handling: :refuse,
|
|
113
124
|
summary: "split-window -p is broken on tmux 3.4; use -l N%.",
|
|
114
|
-
apis:
|
|
125
|
+
apis: RUN_CHANNELS,
|
|
115
126
|
commands: [Command.new(command: "split-window", flags: ["-p"])]),
|
|
116
127
|
Workaround.new(id: "name-separators-rejected", name: "Colon and dot in names", releases: ["3.7"],
|
|
117
128
|
handling: :refuse,
|
|
118
129
|
summary: "tmux 3.7 rejects ':' and '.' in session and window names; the library refuses them before dispatch, typed or raw.",
|
|
119
|
-
apis: ["LibTmux::Server#new_session", "LibTmux::Session#new_window", "LibTmux::Session#rename",
|
|
120
|
-
"LibTmux::Window#rename",
|
|
130
|
+
apis: ["LibTmux::Server#new_session", "LibTmux::Async::Server#new_session", "LibTmux::Session#new_window", "LibTmux::Session#rename",
|
|
131
|
+
"LibTmux::Window#rename", *RUN_CHANNELS],
|
|
121
132
|
commands: [Command.new(command: "new-session", flags: ["-s"]), Command.new(command: "new-window", flags: ["-n"]),
|
|
122
133
|
Command.new(command: "rename-session"), Command.new(command: "rename-window")])
|
|
123
134
|
].freeze
|
data/lib/libtmux/endpoint.rb
CHANGED
|
@@ -5,38 +5,52 @@ require "securerandom"
|
|
|
5
5
|
require_relative "errors"
|
|
6
6
|
|
|
7
7
|
module LibTmux
|
|
8
|
-
#
|
|
8
|
+
# Executable and socket selection. Construction starts no clients.
|
|
9
|
+
#
|
|
10
|
+
# {#initialize Endpoint.new} takes a `socket_path:` or a `socket_name:`.
|
|
11
|
+
# With neither, it picks the socket as tmux does when it is given none, and
|
|
12
|
+
# `environment:` (the process environment by default) decides which: the
|
|
13
|
+
# path in `LIBTMUX_SOCKET_PATH`, else the name in `LIBTMUX_SOCKET`, else the
|
|
14
|
+
# socket `TMUX` names when run inside tmux, else tmux's `default` socket. A
|
|
15
|
+
# variable that is empty counts as unset, and a socket given as an argument
|
|
16
|
+
# ignores the variables. {.from_env} skips the `LIBTMUX_*` variables.
|
|
9
17
|
class Endpoint
|
|
10
18
|
attr_reader :executable, :socket_path
|
|
11
19
|
|
|
12
|
-
def initialize(socket_path: nil, socket_name: nil, executable: "tmux", socket_directory: nil)
|
|
13
|
-
unless
|
|
14
|
-
raise ArgumentError, "choose
|
|
20
|
+
def initialize(socket_path: nil, socket_name: nil, executable: "tmux", socket_directory: nil, environment: ENV)
|
|
21
|
+
unless socket_path.nil? || socket_name.nil?
|
|
22
|
+
raise ArgumentError, "choose at most one socket_path or socket_name"
|
|
23
|
+
end
|
|
24
|
+
origin = path_label = nil
|
|
25
|
+
if socket_path.nil? && socket_name.nil?
|
|
26
|
+
raise ArgumentError, "socket_directory applies only to socket_name" if socket_directory
|
|
27
|
+
socket_path, socket_name, origin = Internal::SocketChoice.call(environment)
|
|
15
28
|
end
|
|
16
29
|
if socket_name
|
|
17
|
-
|
|
30
|
+
label = origin || "socket_name"
|
|
31
|
+
validate_string(socket_name, label)
|
|
18
32
|
if socket_name.include?("/") || [".", ".."].include?(socket_name)
|
|
19
|
-
raise ArgumentError, "
|
|
33
|
+
raise ArgumentError, "#{label} must be a single filename"
|
|
20
34
|
end
|
|
21
|
-
directory = socket_directory ||
|
|
35
|
+
directory = socket_directory || Internal::SocketChoice.present(environment["TMUX_TMPDIR"]) || "/tmp"
|
|
22
36
|
validate_string(directory, "socket_directory")
|
|
37
|
+
path_label = socket_directory ? "socket_directory" : "TMUX_TMPDIR"
|
|
23
38
|
socket_path = File.join(directory, "tmux-#{Process.uid}", socket_name)
|
|
24
39
|
elsif socket_directory
|
|
25
40
|
raise ArgumentError, "socket_directory applies only to socket_name"
|
|
26
41
|
end
|
|
27
|
-
validate_string(socket_path, "socket_path")
|
|
42
|
+
validate_string(socket_path, origin || "socket_path")
|
|
28
43
|
validate_string(executable, "executable")
|
|
29
|
-
@socket_path =
|
|
44
|
+
@socket_path = expand(socket_path, path_label || origin || "socket_path").freeze
|
|
30
45
|
@executable = resolve_executable(executable).freeze
|
|
31
46
|
freeze
|
|
32
47
|
end
|
|
33
48
|
|
|
49
|
+
# The socket of the tmux server this process runs inside, else tmux's
|
|
50
|
+
# `default` socket. It ignores `LIBTMUX_SOCKET_PATH` and `LIBTMUX_SOCKET`.
|
|
34
51
|
def self.from_env(env = ENV, **options)
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
else
|
|
38
|
-
new(socket_name: "default", socket_directory: env["TMUX_TMPDIR"], **options)
|
|
39
|
-
end
|
|
52
|
+
socket_path, socket_name = Internal::SocketChoice.tmux(env)
|
|
53
|
+
new(socket_path: socket_path, socket_name: socket_name, environment: env, **options)
|
|
40
54
|
end
|
|
41
55
|
|
|
42
56
|
def ==(other)
|
|
@@ -49,11 +63,19 @@ module LibTmux
|
|
|
49
63
|
end
|
|
50
64
|
|
|
51
65
|
def inspect
|
|
52
|
-
"#<#{self.class}
|
|
66
|
+
"#<#{self.class} Unix socket>"
|
|
53
67
|
end
|
|
54
68
|
|
|
55
69
|
private
|
|
56
70
|
|
|
71
|
+
# File.expand_path puts the user it cannot find in its message, so the
|
|
72
|
+
# message here names the argument or variable instead.
|
|
73
|
+
def expand(path, label, base = nil)
|
|
74
|
+
base ? File.expand_path(path, base) : File.expand_path(path)
|
|
75
|
+
rescue ArgumentError
|
|
76
|
+
raise ArgumentError, "#{label} cannot be expanded to a path; its leading ~ names no home directory"
|
|
77
|
+
end
|
|
78
|
+
|
|
57
79
|
def validate_string(value, name)
|
|
58
80
|
unless value.is_a?(String) && !value.empty? && !value.include?("\0")
|
|
59
81
|
raise ArgumentError, "#{name} must be a nonempty String without NUL"
|
|
@@ -62,10 +84,10 @@ module LibTmux
|
|
|
62
84
|
|
|
63
85
|
def resolve_executable(value)
|
|
64
86
|
candidates = if value.include?(File::SEPARATOR)
|
|
65
|
-
[
|
|
87
|
+
[expand(value, "executable")]
|
|
66
88
|
else
|
|
67
89
|
ENV.fetch("PATH", "").split(File::PATH_SEPARATOR).map do |directory|
|
|
68
|
-
|
|
90
|
+
expand(value, "executable", directory.empty? ? Dir.pwd : directory)
|
|
69
91
|
end
|
|
70
92
|
end
|
|
71
93
|
candidates.find { |path| File.file?(path) && File.executable?(path) } ||
|
|
@@ -74,6 +96,37 @@ module LibTmux
|
|
|
74
96
|
end
|
|
75
97
|
|
|
76
98
|
module Internal
|
|
99
|
+
# Picks the socket tmux would use if it were given neither -S nor -L, from
|
|
100
|
+
# the variables that stand for them and the ones tmux reads itself: -S
|
|
101
|
+
# beats -L, and -L beats TMUX. Each pick is [path, name, variable], with
|
|
102
|
+
# the variable named so that a bad value is reported by name.
|
|
103
|
+
module SocketChoice
|
|
104
|
+
module_function
|
|
105
|
+
|
|
106
|
+
def call(environment)
|
|
107
|
+
if (path = present(environment["LIBTMUX_SOCKET_PATH"]))
|
|
108
|
+
[path, nil, "LIBTMUX_SOCKET_PATH"]
|
|
109
|
+
elsif (name = present(environment["LIBTMUX_SOCKET"]))
|
|
110
|
+
[nil, name, "LIBTMUX_SOCKET"]
|
|
111
|
+
else
|
|
112
|
+
tmux(environment)
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
# tmux ignores a TMUX that is empty or starts with a comma, and takes
|
|
117
|
+
# the socket path before the first comma of one that does not.
|
|
118
|
+
def tmux(environment)
|
|
119
|
+
inside = present(environment["TMUX"])
|
|
120
|
+
return [nil, "default", nil] if inside.nil? || inside.start_with?(",")
|
|
121
|
+
|
|
122
|
+
[inside.split(",", 2).first, nil, "TMUX"]
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def present(value)
|
|
126
|
+
value if value.is_a?(String) && !value.empty?
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
|
|
77
130
|
# Keep the socket inode alive and route through it; PID timestamps can repeat.
|
|
78
131
|
class SocketIdentity
|
|
79
132
|
attr_reader :key, :release
|
data/lib/libtmux/entity.rb
CHANGED
|
@@ -135,7 +135,7 @@ module LibTmux
|
|
|
135
135
|
value = layout.is_a?(Symbol) ? layout.to_s.tr("_", "-") : layout
|
|
136
136
|
budget = server.__send__(:operation_budget, timeout, cancel)
|
|
137
137
|
# Older tmux can access an invalid pointer for a malformed layout header.
|
|
138
|
-
# tmux 3.8
|
|
138
|
+
# tmux 3.8 and later report and accept saved layouts as JSON.
|
|
139
139
|
saved = /\A[0-9a-fA-F]{4},/.match?(value)
|
|
140
140
|
if !saved && value.start_with?("{")
|
|
141
141
|
json = Internal::Capabilities.capability("layout-json")
|
data/lib/libtmux/native_guard.rb
CHANGED
|
@@ -317,11 +317,17 @@ module LibTmux
|
|
|
317
317
|
end
|
|
318
318
|
|
|
319
319
|
# tmux 3.3a faults on a header that is not four hex digits and a comma, so
|
|
320
|
-
# only checksummed layouts and built-in names pass before 3.4.
|
|
320
|
+
# only checksummed layouts and built-in names pass before 3.4. A JSON layout
|
|
321
|
+
# needs tmux 3.8.
|
|
321
322
|
def check_layout(item, command, release)
|
|
323
|
+
given = flags(item, command)
|
|
324
|
+
json = Internal::Capabilities.capability("layout-json")
|
|
325
|
+
if !json.available?(release) && operands(item, command).first.to_s.start_with?("{") && given.slice("E", "n", "p").empty?
|
|
326
|
+
raise UnsupportedFeatureError.new("JSON layouts require tmux #{json.since} or newer " \
|
|
327
|
+
"(connected version #{release.text})", phase: :admission, delivery: :not_sent)
|
|
328
|
+
end
|
|
322
329
|
return if Internal::Capabilities.capability("layout-without-checksum").available?(release)
|
|
323
330
|
|
|
324
|
-
given = flags(item, command)
|
|
325
331
|
return if given.key?("E") || given.key?("n") || given.key?("p")
|
|
326
332
|
|
|
327
333
|
layout = operands(item, command).first
|
data/lib/libtmux/server.rb
CHANGED
|
@@ -30,76 +30,120 @@ module LibTmux
|
|
|
30
30
|
# The methods fall into the groups below. A {Session}, {Window}, or {Pane}
|
|
31
31
|
# carries the operations on that one thing.
|
|
32
32
|
#
|
|
33
|
-
# **Connecting.**
|
|
34
|
-
#
|
|
35
|
-
# block ends.
|
|
36
|
-
#
|
|
37
|
-
#
|
|
38
|
-
#
|
|
39
|
-
#
|
|
40
|
-
# {
|
|
33
|
+
# **Connecting.** Binding an endpoint that already exists takes the
|
|
34
|
+
# constructor or the open class method, and open with a block closes the
|
|
35
|
+
# server when the block ends. Given no `endpoint:`, `socket_path:` or
|
|
36
|
+
# `socket_name:`, both bind the socket {Endpoint#initialize Endpoint.new}
|
|
37
|
+
# picks from `LIBTMUX_SOCKET_PATH`, `LIBTMUX_SOCKET`, `TMUX` and tmux's
|
|
38
|
+
# default socket, in that order. Starting a private daemon instead creates no
|
|
39
|
+
# session, and the started server owns the daemon's exit. A server answers its
|
|
40
|
+
# {Endpoint} and whether it started its daemon, and reports the request and
|
|
41
|
+
# control slots in use, and the limits. Closing retires the server's clients;
|
|
42
|
+
# on an owned server it also stops the daemon. Open a {ControlConnection} to a
|
|
43
|
+
# session.
|
|
41
44
|
#
|
|
42
|
-
#
|
|
43
|
-
#
|
|
44
|
-
#
|
|
45
|
-
#
|
|
46
|
-
#
|
|
45
|
+
# - Bind an endpoint: {#initialize Server.new}, {Server.open}
|
|
46
|
+
# - Start a private daemon: {Server.start}
|
|
47
|
+
# - Read the endpoint: {#endpoint}
|
|
48
|
+
# - Ask whether it started the daemon: {#owned?}
|
|
49
|
+
# - Slots in use and the limits: {#diagnostics}
|
|
50
|
+
# - Retire the clients: {#close}
|
|
51
|
+
# - Open a control connection: {#open_control}
|
|
47
52
|
#
|
|
48
|
-
# **
|
|
49
|
-
#
|
|
50
|
-
#
|
|
51
|
-
#
|
|
52
|
-
# tree, and clients with `clients: true`, as one validated {Snapshot}.
|
|
53
|
+
# **Finding one thing.** Each lookup wraps an {EntityRef} in a handle without
|
|
54
|
+
# running a command. Take the ref from a handle or a snapshot record. A ref of
|
|
55
|
+
# the wrong kind raises {TargetNotFoundError}; one whose entity has gone fails
|
|
56
|
+
# at its first command.
|
|
53
57
|
#
|
|
54
|
-
#
|
|
55
|
-
# of a snapshot with `where:`, a hash of criteria or a {FilterExpr}, and
|
|
56
|
-
# answers a {Selection}; {#explain_panes} answers the plan for a query
|
|
57
|
-
# without running tmux. A {Selection} narrows with {Selection#where},
|
|
58
|
-
# {Selection#select}, {Selection#filter}, and {Selection#reject}, tests with
|
|
59
|
-
# {Selection#exists?}, and takes a single match with {Selection#one}, which
|
|
60
|
-
# raises {NoMatchError} or {MultipleMatchesError} otherwise, or
|
|
61
|
-
# {Selection#one_or_nil}. Build and compose criteria with
|
|
62
|
-
# {FilterExpr.build}, {FilterExpr#and}, {FilterExpr#or}, {FilterExpr#not},
|
|
63
|
-
# and {FilterExpr.from_json}.
|
|
58
|
+
# - Handles: {#session}, {#window}, {#pane}, {#window_link}
|
|
64
59
|
#
|
|
65
|
-
#
|
|
66
|
-
#
|
|
67
|
-
# {
|
|
68
|
-
#
|
|
69
|
-
#
|
|
70
|
-
# reaches its `window`. {Entity#snapshot} reads one handle back as a record,
|
|
71
|
-
# and {CapturedRecord#ref} with {#session}, {#window}, or {#pane} turns a
|
|
72
|
-
# record into a handle. Live handles go down one command at a time with
|
|
73
|
-
# {Session#list_windows}, {Session#list_panes}, and {Window#list_panes}, and
|
|
74
|
-
# back up with {Entity#server}.
|
|
60
|
+
# **Listing everything.** Listing sessions, windows, or panes answers frozen
|
|
61
|
+
# arrays of handles in numeric ID order, and listing window links answers
|
|
62
|
+
# every {WindowLink}. Listing clients answers one hash per client. Taking a
|
|
63
|
+
# snapshot captures the session, window, and pane tree, and clients with
|
|
64
|
+
# `clients: true`, as one validated {Snapshot}.
|
|
75
65
|
#
|
|
76
|
-
#
|
|
66
|
+
# - Handles: {#list_sessions}, {#list_windows}, {#list_panes}
|
|
67
|
+
# - Window links: {#list_window_links}
|
|
68
|
+
# - Clients: {#list_clients}
|
|
69
|
+
# - One snapshot: {#snapshot}
|
|
70
|
+
#
|
|
71
|
+
# **Querying things and getting around.** A pane search filters the panes of a
|
|
72
|
+
# snapshot with `where:`, a hash of criteria or a {FilterExpr}, and answers a
|
|
73
|
+
# {Selection}; explaining a search answers the plan for a query without
|
|
74
|
+
# running tmux. A {Selection} narrows, tests whether anything matches, and
|
|
75
|
+
# takes a single match, raising {NoMatchError} or {MultipleMatchesError}
|
|
76
|
+
# otherwise, or takes one or nil. Build and compose criteria with
|
|
77
|
+
# {FilterExpr}. A {Snapshot} answers relational questions without another
|
|
78
|
+
# command. Its records follow relations by name: a {SessionSnapshot} reaches
|
|
79
|
+
# `windows`, `panes`, and `current_window`, a {WindowSnapshot} reaches `panes`
|
|
80
|
+
# and `active_pane`, and a {PaneSnapshot} reaches its `window`. A handle reads
|
|
81
|
+
# back as a record, and a record turns into a handle through its ref and the
|
|
82
|
+
# server's lookups. Live handles go down one command at a time and back up
|
|
83
|
+
# through the server.
|
|
84
|
+
#
|
|
85
|
+
# - Search the panes of a snapshot: {#search_panes}
|
|
86
|
+
# - Explain a search without running tmux: {#explain_panes}
|
|
87
|
+
# - Narrow: {Selection#where}, {Selection#select}, {Selection#filter},
|
|
88
|
+
# {Selection#reject}
|
|
89
|
+
# - Test: {Selection#exists?}
|
|
90
|
+
# - Take one: {Selection#one}
|
|
91
|
+
# - Take one or nil: {Selection#one_or_nil}
|
|
92
|
+
# - Build criteria: {FilterExpr.build}, {FilterExpr.from_json}
|
|
93
|
+
# - Compose criteria: {FilterExpr#and}, {FilterExpr#or}, {FilterExpr#not}
|
|
94
|
+
# - Read a snapshot's records: {Snapshot#sessions}, {Snapshot#windows},
|
|
95
|
+
# {Snapshot#panes}, {Snapshot#clients}
|
|
96
|
+
# - Read a handle back as a record: {Entity#snapshot}
|
|
97
|
+
# - Turn a record into a handle: {CapturedRecord#ref}, {#session}, {#window},
|
|
98
|
+
# {#pane}
|
|
99
|
+
# - Down: {Session#list_windows}, {Session#list_panes}, {Window#list_panes}
|
|
100
|
+
# - Up: {Entity#server}
|
|
101
|
+
#
|
|
102
|
+
# **Changing things.** Creating a session starts it detached, running
|
|
77
103
|
# `command:`, an argv array rather than a shell string, and answers the
|
|
78
|
-
# {Session} or, with `receipt: true`, a {CreationReceipt}.
|
|
79
|
-
#
|
|
80
|
-
#
|
|
104
|
+
# {Session} or, with `receipt: true`, a {CreationReceipt}. Kill stops the tmux
|
|
105
|
+
# server, which closing does only for an owned server. Switching a client
|
|
106
|
+
# points the client named by `client:` at a session.
|
|
107
|
+
#
|
|
108
|
+
# - Create a session: {#new_session}
|
|
109
|
+
# - Stop the tmux server: {#kill}
|
|
110
|
+
# - Point a client at a session: {#switch_client}
|
|
81
111
|
#
|
|
82
|
-
# **Options and hooks.**
|
|
83
|
-
#
|
|
84
|
-
#
|
|
85
|
-
# {#unset_environment} read, set, and unset one variable in the server's
|
|
86
|
-
# global environment.
|
|
112
|
+
# **Options and hooks.** Ask for {Options} at server scope, or at the global
|
|
113
|
+
# session or window scope, and for {Hooks} at the global session or window
|
|
114
|
+
# scope. Read, set, and unset one variable in the server's global environment.
|
|
87
115
|
#
|
|
88
|
-
#
|
|
89
|
-
#
|
|
90
|
-
#
|
|
91
|
-
#
|
|
92
|
-
#
|
|
116
|
+
# - Options: {#options}
|
|
117
|
+
# - Hooks: {#hooks}
|
|
118
|
+
# - Read a variable: {#environment}
|
|
119
|
+
# - Set a variable: {#set_environment}
|
|
120
|
+
# - Unset a variable: {#unset_environment}
|
|
93
121
|
#
|
|
94
|
-
# **
|
|
122
|
+
# **Everything else tmux keeps.** List, read, write, and delete paste buffers.
|
|
123
|
+
# Load a configuration file. Display expands a tmux format; the argument is a
|
|
124
|
+
# format, not literal text. Wait on, signal, lock, or unlock a channel, as
|
|
125
|
+
# `action:` says.
|
|
126
|
+
#
|
|
127
|
+
# - Paste buffers: {#list_buffers}, {#read_buffer}, {#write_buffer},
|
|
128
|
+
# {#delete_buffer}
|
|
129
|
+
# - Load a configuration file: {#source_file}
|
|
130
|
+
# - Expand a format: {#display}
|
|
131
|
+
# - Wait on a channel: {#wait_for}
|
|
132
|
+
#
|
|
133
|
+
# **Things that need a terminal.** Attaching runs an interactive client on a
|
|
95
134
|
# TTY the caller supplies and keeps, blocks until that client exits, and
|
|
96
|
-
# answers a {TerminalResult}. Cancelling detaches the client and does not
|
|
97
|
-
#
|
|
135
|
+
# answers a {TerminalResult}. Cancelling detaches the client and does not stop
|
|
136
|
+
# pane commands.
|
|
137
|
+
#
|
|
138
|
+
# - Attach a client: {#attach}
|
|
139
|
+
#
|
|
140
|
+
# **Running a command.** Anything else tmux can do is reachable by running one
|
|
141
|
+
# command, which takes an argv array and keeps tmux's separators and format
|
|
142
|
+
# semantics, or by running several in one tmux invocation. A {GroupResult}
|
|
143
|
+
# cannot attribute the client's final status to a single step.
|
|
98
144
|
#
|
|
99
|
-
#
|
|
100
|
-
#
|
|
101
|
-
# semantics, or {#run_group}, which runs several in one tmux invocation. A
|
|
102
|
-
# {GroupResult} cannot attribute the client's final status to a single step.
|
|
145
|
+
# - Run one command: {#run}
|
|
146
|
+
# - Run several in one invocation: {#run_group}
|
|
103
147
|
class Server
|
|
104
148
|
attr_reader :endpoint
|
|
105
149
|
|
data/lib/libtmux/version.rb
CHANGED
data/sig/libtmux.rbs
CHANGED
|
@@ -58,7 +58,7 @@ module LibTmux
|
|
|
58
58
|
class Endpoint
|
|
59
59
|
attr_reader executable: String
|
|
60
60
|
attr_reader socket_path: String
|
|
61
|
-
def initialize: (?socket_path: String?, ?socket_name: String?, ?executable: String, ?socket_directory: String?) -> void
|
|
61
|
+
def initialize: (?socket_path: String?, ?socket_name: String?, ?executable: String, ?socket_directory: String?, ?environment: untyped) -> void
|
|
62
62
|
def self.from_env: (?untyped, **untyped) -> Endpoint
|
|
63
63
|
def ==: (untyped) -> bool
|
|
64
64
|
alias eql? ==
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: libtmux
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- libtmux contributors
|
|
@@ -85,6 +85,7 @@ executables: []
|
|
|
85
85
|
extensions: []
|
|
86
86
|
extra_rdoc_files: []
|
|
87
87
|
files:
|
|
88
|
+
- CHANGELOG.md
|
|
88
89
|
- LICENSE
|
|
89
90
|
- README.md
|
|
90
91
|
- assets/logo.png
|
|
@@ -131,7 +132,8 @@ licenses:
|
|
|
131
132
|
- MIT
|
|
132
133
|
metadata:
|
|
133
134
|
source_code_uri: https://github.com/libtmux/libtmux-ruby
|
|
134
|
-
|
|
135
|
+
changelog_uri: https://github.com/libtmux/libtmux-ruby/blob/master/gems/libtmux/CHANGELOG.md
|
|
136
|
+
documentation_uri: https://libtmux.org/en/ruby/v0.1.2/
|
|
135
137
|
rdoc_options: []
|
|
136
138
|
require_paths:
|
|
137
139
|
- lib
|