Core Library0.xExamples

Choose documentation 1

latest

Current version

latest
English

Early release libtmux is released, and its APIs may still change between releases. This site's structure and URLs may change too.

Runnable programs

Complete programs that start a private tmux server, do one job and close it. Run them from the repository root after the toolchain setup, with tmux on PATH:

Terminal window
$ zef install .
TaskProgramRaku facilities
Create and find panesQuickstartObjects, LEAVE, a native predicate
Resize and remove panesResize panesresize, kill, fresh snapshots
Select wide panesPane queriesTyped selections, query hashes, grep, map, sort
Choose where a query runsQuery planexplain-panes, :pushdown
Add a status paneFloating panesCapability checks and a tiled fallback
Watch pane outputWatch outputPromise, Supply, react, whenever
Combine the workflowSession workflowEvents, captured graphs and query plans
Recover after a command failsBatch recoveryTyped outcomes and explicit recovery

Create and find panes

quickstart.raku splits one pane, titles both and finds editor in a fresh snapshot. The earlier snapshot still has one pane.

Terminal window
$ raku -I. examples/quickstart.raku

It prints editor: 2 panes.

Resize and remove panes

resize-panes.raku splits a pane, resizes the window and the first pane, then kills the second pane. A fresh snapshot reads each result.

Terminal window
$ raku -I. examples/resize-panes.raku

It prints window: 100x20, editor: 30 columns and panes: 1.

Select wide panes

query-panes.raku creates editor, tests and logs. .where selects wide panes, .filter finds editor, .single checks the count, and .grep, .map and .sort list the rest.

Terminal window
$ raku -I. examples/query-panes.raku

It prints Wide pane: editor and Other panes: logs, tests.

  • Bind a typed selection with :=; = copies it into a plain array.
  • Repeated traversal reads the captured members and does not refresh tmux.

Choose where a query runs

explain-query.raku explains two pane queries, runs one, and shows :pushdown<require> refusing the query that keeps a title test local.

Terminal window
$ raku -I. examples/explain-query.raku

It prints whether each query is fully pushed to tmux, the filter tmux gets, the match, and the refusal.

Add a status pane

floating-panes.raku creates an empty status pane: floating when the daemon reports pane-floating, tiled otherwise.

Terminal window
$ raku -I. examples/floating-panes.raku

It prints Status pane: floating or Status pane: tiled, then status.

Watch pane output

watch-output.raku subscribes to pane-output events, sends text to cat and collects the echoed bytes with react and whenever. Then it checks the captured screen.

Terminal window
$ raku -I. examples/watch-output.raku

It prints hello from Raku and Screen capture confirmed.

  • A deadline bounds the wait.
  • Several subscribers can share one connection.
  • Sending text and pressing Enter are separate calls.

Run the complete session workflow

session-workflow.raku creates panes, sends input, watches control-mode output and captures the screen. It filters a snapshot, then compares an exact source query with the captured pane.

Terminal window
$ raku -I. examples/session-workflow.raku

The output includes Session: 2 panes, editor: hello from Raku and Owned clients, daemon and socket cleaned up.

Recover after a command fails

batch-recovery.raku sets an option, sends an invalid command and checks that the next command was skipped. It then removes the first effect.

Terminal window
$ raku -I. examples/batch-recovery.raku

It prints the Complete, Failed and Skipped outcomes, then Recovery: removed the first effect explicitly and Owned daemon and socket cleaned up.

A failed batch does not undo commands that already succeeded.

Select a tmux executable

Every program except the quickstart takes --tmux=PATH. The quickstart runs tmux from PATH.

The example check runs every program against LIBTMUX_TEST_TMUX, compares its output and rejects leftover sockets. See Contributing.

Esc

Type to search.

Reference previewOpen reference