Getting started
Needs libtmux for Julia unreleased Install
LibTmux separates remote operations from captured data. Create an owned daemon for a script, or explicitly select a borrowed endpoint. Remote functions yield on I/O and work in ordinary Julia Tasks.
Start with Install, then return here for an owned-server program. Compatibility lists the supported platforms and releases.
The following source is the executable examples/owned_capture.jl program.
It creates a private session, borrows its endpoint for named selection, refuses
missing or ambiguous panes, and checks owned daemon cleanup. Reuse
capture_named_pane with an explicit Server for an existing endpoint. The
function reads observations and screen content; the caller keeps ownership.
using LibTmux
function capture_named_pane(server; session_name, pane_title) matches = filter(SessionWhere(name=session_name), sessions(snapshot(server))) length(matches) == 1 || throw(ArgumentError("expected one named session")) scoped = snapshot(server, only(matches).ref) candidates = [pane for window in windows(scoped) for pane in panes(window)] matches = filter(PaneWhere(title=pane_title), candidates) length(matches) == 1 || throw( ArgumentError("expected one pane titled $pane_title; found $(length(matches))"), ) pane = only(matches).ref (; pane, screen=capture_pane(server, pane))end
function main() endpoint = Ref{Server}() result = with_server() do server endpoint[] = server new_session(server; name="example", command=["/bin/cat"]) snap = snapshot(server) pane = only(panes(snap)) screen = capture_pane(server, pane.ref) @assert isempty(strip(screen)) @assert only(sessions(snap)).name == "example" set_title(server, pane.ref, "chosen") borrowed = Server(socket_path=server.socket_path, tmux=server.tmux) selected = capture_named_pane(borrowed; session_name="example", pane_title="chosen") @assert selected.pane == pane.ref && isempty(strip(selected.screen)) sibling = split_window(server, pane.ref; command=["/bin/cat"]) set_title(server, sibling, "chosen") for title in ("missing", "chosen") rejected = try capture_named_pane(borrowed; session_name="example", pane_title=title) false catch error error isa ArgumentError || rethrow() true end @assert rejected end @assert length(panes(snapshot(borrowed))) == 2 println("Captured ", string(pane.id), ": ", ncodeunits(screen), " screen bytes") (; snap, screen) end @assert !ispath(dirname(endpoint[].socket_path)) @assert length(panes(result.snap)) == 1 resultend
main()Use Server for a borrowed endpoint. It takes a named socket, reads
LIBTMUX_SOCKET_PATH or LIBTMUX_SOCKET, or leaves the choice to tmux. Neither
construction nor local snapshot reads contact tmux. from_env asks for
the socket TMUX names. with_server owns its daemon; ordinary server
values do not.
Next, read Captured queries for filtering and shared windows, or Ownership and I/O for effects, cancellation and control.