Skip to content

Latest commit

 

History

History
947 lines (682 loc) · 31.3 KB

clojure-api.md

File metadata and controls

947 lines (682 loc) · 31.3 KB

libtmux-clojure API

Generated from public namespace and var metadata; do not edit by hand. Each heading links to its current Clojure source.

Read the guide for runnable programs and ownership. The captured-value reference documents map keys. Functions ending in ! may cross the external-state boundary.

Namespaces

Explicit tmux effects through open! and snapshot!. Captured maps retain opaque Java references; libtmux.data traverses them locally.

(append-hook! value event argv)

Appends one explicit tmux argv command to a hook. hooks! returns the ordered command vectors.

(apply-layout! window layout)

Applies an explicit tmux layout string. resize! sets explicit cell dimensions.

(await-channel! server name timeout)

Waits on an explicit tmux channel while reserving capacity for its release. Returns :signalled, :timed-out, or :server-gone; interruption propagates. signal-channel! releases this wait; declare libtmux.async/submit! work as :wait.

(await-text! pane text timeout)

Waits within a positive Duration; returns a keyword describing the outcome. Use capture! to read lines after the wait; send-keys! alone proves no completion.

(batch! server operations)

(batch! server operations options)

Runs independent argv commands using a fresh Java Batch and returns positions. Supply explicit targets. Failed/skipped outcomes are data; transport failure throws with :tmux/results. Use {:kind :wait} for groups needing a release, including blocking shell commands. No rollback or retry safety is promised. chain! carries an implicit target between dependent commands.

(buffers! server)

Lists captured buffer names and byte sizes. show-buffer! reads an individual buffer.

(capture! pane)

(capture! pane options)

Captures pane lines; :from :history includes scrollback. await-text! waits for text; libtmux.control/subscribe! observes new output.

(chain! server operations)

(chain! server operations options)

Runs dependent argv commands with tmux's implicit target between positions. Uses a fresh Java CommandChain. Failed/skipped outcomes are data; transport failure throws with :tmux/results. Use {:kind :wait} for groups needing a release, including blocking shell commands. No rollback or retry safety is promised. batch! runs commands with explicit independent targets.

(clients! server)

Acquires captured clients. detach-client! acts on a selected client reference.

(close! server)

Releases the supplied Server's local resources without killing tmux. Local closure remains available after libtmux.async/cancel!. open! creates another client.

(delete-buffer! server name)

Deletes an explicit buffer. buffers! lists the remaining buffers.

(detach-client! client)

Detaches the explicit client. clients! acquires available clients; switch-client! changes their session.

(environment! value)

(environment! value scope)

Returns values and explicitly removed names, preserving removal versus absence. unset-environment! allows inheritance; remove-environment! masks a name.

(error-summary failure)

Returns fixed error metadata without arguments or cause messages. Printing the original exception and its cause chain is not sanitized. Use this summary when handling failures from new-session! or batch!.

(expand! value format)

Evaluates an explicit tmux format at the supplied scope. capture! reads terminal lines rather than evaluating a tmux format.

(find-session! server name)

Finds a session by exact name; absence returns nil. Use sessions! when the selection needs ordinary Clojure predicates.

(hooks! value)

Returns hook names and their ordered command vectors. set-hook! replaces commands; append-hook! preserves their order.

(join-pane! pane window)

Joins a pane to a window. split-pane! creates a new pane instead of relocating an existing one.

(kill! value)

Kills the explicitly supplied session, window, or pane. close! releases a client; kill-server! ends its entire tmux daemon.

(kill-server! server)

Kills the explicit tmux server; close! only releases local resources.

(link-window! window session)

Links a window into a session. unlink-window! removes a placement; move-window! relocates one.

(move-window! window session index)

Moves a window to a session and explicit index. Use snapshot! to find the new placement after moving.

(new-session! server options)

Creates a detached session and returns a fresh captured session map. Options are :name, :window-name, :command (nonempty argv vector), :directory (path), and :environment (string keys and values). Unknown keys are rejected. A recapture failure can occur after creation; inspect error-summary before retrying a mutation.

(new-window! session options)

Creates a window and returns a fresh captured window occurrence. Takes a Session ref and :name, :command (argv), :directory, :environment, :index (nonnegative integer), and :detached? options. Use split-pane! to add panes within the new window.

(open! options)

Opens local resources for an explicit :socket-path or :socket-name endpoint. Supply exactly one endpoint. Paths accept String or java.nio.file.Path. Optional :binary is a command name or path; :config-file is a path; :timeout is a positive java.time.Duration. Unknown keys are rejected. Returns a Server for with-open; closing it does not kill tmux. Use snapshot! to acquire state and close! to release this client.

(options! value)

(options! value scope)

Reads :local options by default, or :effective inherited options. set-option! sets an override; unset-option! restores inheritance.

(panes! server)

Acquires captured pane occurrences. Use capture! for terminal contents or libtmux.data/data for detached EDN.

(paste-buffer! pane name)

Pastes an explicit buffer into a pane. set-buffer! supplies contents; await-text! observes pane output.

(raw! server argv)

Runs explicit tmux argv and returns exit status and streams; no shell. Use batch! for independent commands or chain! for dependent targets.

(refresh! entry)

Reacquires an explicit reference, retaining window and pane placement. Returns nil if that occurrence disappeared; server failure throws. Compare identity with libtmux.data/same-entity?; map equality compares observations.

(remove-environment! value name)

Marks an environment name removed for new child processes. unset-environment! removes that local marker and allows inheritance.

(rename! value name)

Renames a session or window and captures its current data.

(resize! value width height)

Resizes a window or pane to positive cell dimensions. apply-layout! arranges all panes in a window.

(run-shell! server command)

Runs an explicitly requested shell command on the server. raw! accepts tmux argv; await-channel! can gate an explicit completion signal.

(select! value)

Selects the preserved window or pane occurrence. refresh! acquires the resulting selection state.

(send-keys! pane keys)

Sends an explicit vector of tmux key names. Use send-literal! for text and await-text! for observed output.

(send-literal! pane text)

Sends literal text; completion does not mean application readiness. send-keys! sends key names; await-text! checks observed output.

(sessions! server)

Acquires captured sessions; acquisition failure throws. libtmux.data/windows traverses each session without another acquisition.

(set-buffer! server name text)

Stores literal buffer contents. show-buffer! reads the text; paste-buffer! sends it to a pane.

(set-environment! value name text)

Sets a literal environment value. environment! reads values and explicitly removed names.

(set-hook! value event argv)

Replaces a hook with one explicit tmux argv command. append-hook! adds a command; unset-hook! removes the hook.

(set-option! value name text)

Sets a literal option value at the explicit scope. Read it with options!; remove the override with unset-option!.

(show-buffer! server name)

Reads literal buffer contents. buffers! lists names and sizes without reading their contents.

(signal-channel! server name)

Signals an explicit tmux channel. Releases a corresponding await-channel! wait.

(snapshot! server)

Acquires an eager captured graph from an explicit server. Traverse one observation with libtmux.data/windows and libtmux.data/panes.

(split-pane! pane options)

Splits a Pane ref and returns a fresh captured pane occurrence. Options are :command (argv), :directory, :environment, :direction (:below, :above, :right, :left), :cells or :percent (mutually exclusive), :detached?, :empty?, :full-window?, and :zoomed?. :empty? excludes :command. A single argv element is executed literally, without shell interpolation. Use apply-layout! to arrange the resulting window.

(switch-client! client session)

Switches an explicit client to a session. detach-client! disconnects a client instead of switching its session.

(unlink-window! window)

Unlinks the preserved window occurrence. libtmux.data/same-link? distinguishes contextual placements.

(unset-environment! value name)

Removes the local environment entry, allowing inheritance. remove-environment! masks a name instead of allowing inheritance.

(unset-hook! value event)

Removes an explicit hook. hooks! reads the remaining hooks.

(unset-option! value name)

Removes a local option override. options! can read the resulting effective value.

(windows! server)

Acquires captured window occurrences. libtmux.data/panes traverses these occurrences without another acquisition.

Pure captured values from libtmux.core/snapshot!. Traverse with windows and panes, select with matching, or detach with data.

(active-pane value)

Returns the captured active pane of a window or session, or nil. panes returns all captured occurrences; libtmux.core/select! changes selection.

(active-window session)

Returns the captured active window of a session, or nil. windows returns all captured occurrences; active-pane follows the active one.

(data value)

Projects captured data to EDN, removing :tmux/ref at every map level. Instants become ISO-8601 strings; sequences and Java lists become vectors. Unsupported JVM objects throw rather than producing unreadable EDN. Detached results cannot be used by predicate; entity-key remains explicit data.

(entity-key entry)

Returns a captured physical identity, qualified by endpoint and server PID. PID reuse is not a stronger daemon-incarnation guarantee. link-key also includes placement; same-entity? compares physical identities.

(exactly-one values)

Returns the only value or throws ex-info for zero or multiple values. Stops requesting matches once ambiguity is known. Finding zero or one may scan all input; chunked producers may realize more. nil and false are values. one-or-none accepts an empty selection; establish cardinality before effects.

(from-capture capture)

Converts an authenticated Java CapturedServer to eager persistent values. Reads no live getters and issues no commands. Relations share these values; window links and pane occurrences retain their captured order and placement. libtmux.core/snapshot! acquires this Java capture and projects it for callers.

(link-key entry)

Returns the physical identity and contextual window placement. Only window and pane occurrences carry a link; missing context throws. entity-key omits placement; same-link? compares contextual occurrences.

(matching expression)

(matching expression entries)

Filters captured entries using a Java FilterExpr over their preserved refs. One argument returns a transducer; two return a lazy sequence. Both are local and preserve order and multiplicity. Detached maps have no query reference. Delegates to predicate; exactly-one checks the resulting cardinality.

(one-or-none values)

Returns the only value, nil for none, or throws for multiple values. Stops requesting matches once ambiguity is known. Finding zero or one may scan all input; chunked producers may realize more. nil and false are values. Use exactly-one when zero matches must also fail.

(panes value)

Returns captured pane occurrences in a snapshot, session, or window. Use libtmux.core/panes! for a new acquisition; active-pane selects locally.

(predicate expression)

Adapts a Java FilterExpr to a predicate over captured entries. Evaluates the preserved :tmux/ref, including Java relation semantics; editing fields in an entry does not change the reference being queried. matching provides transducer and sequence arities; data removes refs.

(same-entity? left right)

Compares physical entity identities without acquiring current state. Uses entity-key; same-link? also checks placement.

(same-link? left right)

Compares occurrences, including the session, window ID, and index. Uses link-key; same-entity? ignores placement.

(windows value)

Returns the captured window occurrences in a snapshot or session. Use libtmux.core/windows! for a new acquisition; panes stays local.

Bounded owned workers from runtime! and cancellable submit! tasks. completion-stage and then! expose Java interop with explicit scheduling.

(cancel! task)

Requests cancellation. The first accepted cancellation reason wins. task-state distinguishes cancelling from terminal; dereference only settles after cleanup.

(close-runtime! runtime)

Cancels owned tasks and callbacks and shuts down the runtime's executors. Waits within :close-timeout-ms. Interruption-resistant work can outlive that budget; it cannot be forcibly stopped. Pending cleanup throws ex-info with :tmux/error :cleanup-pending. Safe to call again; returns nil after cleanup. task-state keeps incomplete cleanup observable; cancel! targets one task.

(completion-stage task)

Returns a read-only CompletionStage completed after worker cleanup. Completing or cancelling a derived CompletableFuture does not control the task; use cancel!. Caller-attached callbacks follow Java stage scheduling. then! schedules bounded continuations; task-state exposes pending cleanup.

(runtime!)

(runtime! options)

Creates a closeable runtime owning bounded work, wait and callback lanes. Options are :max-running (default 4, minimum 2), :queue-limit (default 64, positive), and :close-timeout-ms (default 900, positive). One running slot is reserved for waits so ordinary work can release them. Closing cancels owned work and waits within the close budget; it never closes borrowed servers. Submit with submit!; close-runtime! documents incomplete cleanup.

(submit! runtime thunk)

(submit! runtime options thunk)

Submits a zero-argument function with the caller's dynamic bindings. Options are :kind (:ordinary by default, or :wait) and a positive :timeout-ms deadline including queue time. Returns a dereferenceable Task or {:status :busy :kind kind} when admission is full. Timed deref does not cancel a task; cancel! or its deadline interrupts owned work. Effects that wait require :wait. Exceptions retain dispatch certainty and partial results.

(task-kind task)

Returns the declared :ordinary or :wait lane without waiting for the task. Declared by submit!; task-state reports execution and cleanup progress.

(task-state task)

Reads task progress: :queued, :running, :cancelling, :cleanup-pending, or :terminal. A cancellation request is not proof cleanup has finished. cancel! requests interruption; completion-stage settles after cleanup.

(then! runtime task f)

Returns a read-only CompletionStage applying f after successful task cleanup. Runs on the runtime's bounded callback lane with the caller's dynamic bindings. Full callback admission throws ex-info with :tmux/error :busy. Closing the runtime cancels queued callbacks and interrupts active ones. After close-runtime!, callbacks cannot issue later tmux calls. completion-stage exposes ordinary Java stage scheduling instead.

Explicit control replies through attach! and send!. subscribe!, next!, and terminal expose owned bounded output streams. Control needs tmux 3.7 or newer; an older daemon is refused before any client is attached, with :tmux/error :tmux/unsupported-feature.

(attach! session)

(attach! session timeout)

Attaches an owned control client to an explicit captured Session reference. Close releases this client, never its server. Use a dedicated connection when cancellation must not affect other requests and subscriptions. send! sends protocol argv; subscribe! observes output on this connection.

(close! resource)

Closes a connection or subscription. Closing a subscription leaves its borrowed connection open; closing a connection affects all its subscribers. Local closure remains available after libtmux.async/cancel!. terminal inspects a drained subscription; attach! opens another connection.

(next! stream)

(next! stream timeout)

Reads one event, gap, timeout, or terminal map; never uses nil for termination. A :gap names the events dropped since the previous read and precedes the events that remain. The optional nonnegative Duration includes waiting for another reader. Sequence numbers order the events of this stream. Close wakes a reader. Termination drains queued deliveries before the final outcome; intentionally closing this subscription discards its pending deliveries. subscribe! sets bounds; close! wakes a blocked reader.

(send! connection argv)

(send! connection argv timeout)

Sends argv and returns protocol status, lines, and unverified completion. A complete reply does not prove deferred work finished. Cancelling an active send can end this connection and its other requests and subscriptions. libtmux.core/raw! uses process execution; subscribe! observes unsolicited output.

(subscribe! connection)

(subscribe! connection options)

Creates a closeable output subscription borrowing its connection. :encoding is :bytes (caller-owned byte arrays) or :utf-8 (incremental text per pane, reset after this subscription's gaps; malformed bytes use \xHH). :decoder-capacity bounds partial-pane state (default 1024); an eviction is reported with :decoder/reset :capacity and a cumulative :decoder/resets. :capacity bounds queued events; :max-bytes bounds their unescaped payload (default 16 MiB). Oldest events are dropped until both bounds fit; an oversized event drops the queued prefix and itself. The next read is a :gap with byte/event loss. Readers compete; create separate subscriptions for independent fan-out. next! reads deliveries; terminal reports the drained end; close! stops locally.

(terminal stream)

Returns the single recorded stream outcome, or nil until a reader drains it. :reason is :closed, :completed, :control-exit, :transport-failure, :protocol-failure, or :unknown. A control exit does not prove daemon death; :cause preserves the original exception and may contain sensitive content. Text streams include :trailing-text keyed by pane ID for incomplete final bytes rendered as \xHH. next! records this outcome after buffered deliveries have drained.