Capture a pane
Needs libtmux for Julia unreleased Install
Create a private tmux server, capture the screen of a pane running
/bin/cat, and keep the captured snapshot after the server has stopped.
Setup
Julia 1.13.0, Git, POSIX shell and tmux on Linux. Start in an empty directory. The following commands run in a POSIX shell.
Fetch the library revision used by this program.
$ git init -q source$ git -C source fetch -q --depth=1 \ https://github.com/libtmux/libtmux-julia.git \ 6f62bd72cb8d99f3759ca5e2cc3591165a03c768$ git -C source checkout -q --detach FETCH_HEADProgram
Save this complete program as owned_capture.jl.
using LibTmux
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" 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()with_server owns the daemon and its temporary socket directory. The
program asserts that the directory is gone after the block returns and that
the captured snapshot still contains its pane.
The pane has no text. Its captured screen contains blank lines, so the byte
count depends on its height; strip(screen) is empty.
Run
$ unset TMUX TMUX_PANE$ export ENV=/dev/null BASH_ENV=/dev/null SHELL=/bin/sh$ julia --startup-file=no --project=source owned_capture.jlExpected output:
Captured %0: 24 screen bytesRelated APIs
Source and verification
The complete program is examples/owned_capture.jl without the tmux
argument that the repository’s own tests use to choose an executable.
The verification runner executes these displayed files and setup commands
unchanged, checks the output, and checks that the program stopped its private
tmux server. Each example runs independently.