LibTmux.Pane (libtmux v0.1.3)

Copy Markdown View Source

An immutable physical pane with explicit actions. It belongs to a window; text may be empty.

What is on here

A Pane is a value captured in a LibTmux.Snapshot. Actions take a LibTmux.Ref and a Server or Control connection. Start with these groups:

Finding the pane. Select panes from a captured snapshot, or look one up by its exact ID. Neither contacts tmux. An ID that was not captured returns {:error, error} with kind :not_found. Turn the pane into a reference tied to the server incarnation that supplied it, ready for an action.

Splitting. Split the pane and get the new pane's ID in the completed value. A qualified Control connection also returns a bound reference; one-shot execution returns ref: nil. The defaults are a vertical, detached split at half size; options set the axis, size, directory and command.

Sending input. Send literal bytes, up to 995 of them, without interpreting key names, or send named keys such as "Enter" and "C-c". An unknown key name is rejected. Acknowledgement does not prove the program consumed the input.

Reading the screen. Capture the rendered screen through one-shot execution; a Control connection returns unsupported_transport. Output over the byte limit is an error, never a partial screen. This reads screen state, not the program's original output stream.

Killing. Kill the pane through a Server. A Control connection returns unsupported_transport. Killing the last pane of a window removes the window.

Summary

Types

Bounded one-shot screen capture; line numbers are relative to the visible screen, with negative history offsets.

Split geometry and process arguments.

A created pane ID; ref is bound for qualified control and nil for one-shot.

t()

A physical pane; PID and exit status can be known absent, with separate coverage sentinels.

Functions

Captures bounded screen bytes through explicit one-shot execution.

Returns screen bytes when capture/3 completes; raises API errors or LibTmux.Action.CompletionError otherwise.

Kills an exact pane through one-shot execution.

Returns :ok when kill/3 completes; raises API errors or LibTmux.Action.CompletionError otherwise.

Sends 1..128 named keys to an exact pane; unknown names are rejected.

Returns :ok when send_keys/4 completes; raises API errors or LibTmux.Action.CompletionError otherwise.

Sends 0..995 literal bytes to an exact pane, without interpreting key names.

Returns :ok when send_text/4 completes; raises API errors or LibTmux.Action.CompletionError otherwise.

Splits an exact pane and returns its ID and optional bound reference as value.

Returns the created pane value when split/3 completes; raises API errors or LibTmux.Action.CompletionError otherwise.

Types

capture_option()

@type capture_option() ::
  LibTmux.Action.option()
  | {:start_line, -32768..32767}
  | {:end_line, -32768..32767 | :last}
  | {:join_lines, boolean()}
  | {:max_bytes, 0..1_048_576}

Bounded one-shot screen capture; line numbers are relative to the visible screen, with negative history offsets.

split_option()

@type split_option() ::
  LibTmux.Action.option()
  | {:axis, :horizontal | :vertical}
  | {:size, {:cells, 1..32767} | {:percent, 1..99}}
  | {:before | :detached, boolean()}
  | {:cwd, binary()}
  | {:command,
     :default | :empty | {:shell, binary()} | {:argv, [binary(), ...]}}

Split geometry and process arguments.

split_value()

@type split_value() :: %{id: String.t(), ref: LibTmux.Ref.t() | nil}

A created pane ID; ref is bound for qualified control and nil for one-shot.

t()

A physical pane; PID and exit status can be known absent, with separate coverage sentinels.

pid is nil when tmux reports no PID. A reported PID or its absence does not establish process liveness or cleanup.

Functions

capture(connection, ref, options \\ [])

Captures bounded screen bytes through explicit one-shot execution.

Returns {:ok, result} with bytes as value after acknowledged completion and native retirement. Failed commands return {:error, %LibTmux.Action.CompletionError{}} with their original evidence. Defaults: visible lines 0 through :last, no line joining, 65536 stdout bytes, 65536 stderr bytes and 5000ms. :last is accepted only for end_line. Negative line numbers include history; tmux clamps the requested range to available lines. Output overflow is an error, never a successful partial screen. This observes rendered screen state, not the program's original output stream.

A Control argument returns unsupported_transport: arbitrary screen bytes are not qualified for shared control framing. No fallback occurs.

alias LibTmux.Pane

Pane.capture(server, pane_ref, start_line: -100, max_bytes: 131_072)

capture!(connection, ref, options \\ [])

Returns screen bytes when capture/3 completes; raises API errors or LibTmux.Action.CompletionError otherwise.

kill(connection, ref, options \\ [])

Kills an exact pane through one-shot execution.

Returns {:ok, result} on command completion. Optional session: session_ref requires the pane's window to belong to that exact session and timeout defaults to 5000ms. The reference is checked against the answering server before dispatch, with the usual one-shot check/use race. A reference to something that is already gone returns {:error, %LibTmux.Action.CompletionError{}} with the original evidence. Control connections return unsupported_transport before any I/O: a connection cannot kill what it is attached to. Observations you already hold keep describing the pane.

alias LibTmux.Pane

Pane.kill(server, pane_ref)

kill!(connection, ref, options \\ [])

@spec kill!(LibTmux.Server.t(), LibTmux.Ref.t(), [LibTmux.Action.option()]) :: :ok

Returns :ok when kill/3 completes; raises API errors or LibTmux.Action.CompletionError otherwise.

send_keys(connection, ref, keys, options \\ [])

Sends 1..128 named keys to an exact pane; unknown names are rejected.

Supports Enter, Space, Tab, BTab, BSpace, Escape, arrows, Home, End, PageUp, PageDown, Insert, Delete and F1..F12. Distinct C-, M- and S- modifiers may prefix arrows, Home/End, PageUp/PageDown, Insert/Delete and F1..F12. Also accepts C-a..C-z, conventional ASCII control punctuation, and M- plus one printable ASCII character. Unsupported combinations such as S-a and C-Enter fail before admission; tmux could otherwise type their spelling as text. Options and outcomes follow LibTmux.Action.

alias LibTmux.Pane

Pane.send_keys(control, pane_ref, ["Enter", "C-c"])

send_keys!(connection, ref, keys, options \\ [])

@spec send_keys!(LibTmux.Action.connection(), LibTmux.Ref.t(), [String.t()], [
  LibTmux.Action.option()
]) ::
  :ok

Returns :ok when send_keys/4 completes; raises API errors or LibTmux.Action.CompletionError otherwise.

send_text(connection, ref, bytes, options \\ [])

Sends 0..995 literal bytes to an exact pane, without interpreting key names.

Hex-key encoding preserves NUL and invalid UTF-8. Empty input sends nothing. Both transports use the same limit, fitting tmux 3.8's command argument ceiling. Larger inputs fail validation before I/O; calls are never split. The terminal's line discipline, active mode and application still determine how input is handled; acknowledgement does not prove program consumption. Options and outcomes follow LibTmux.Action. For named keys use send_keys/4.

alias LibTmux.Pane

Pane.send_text(control, pane_ref, "printf 'hello'")

send_text!(connection, ref, bytes, options \\ [])

@spec send_text!(LibTmux.Action.connection(), LibTmux.Ref.t(), binary(), [
  LibTmux.Action.option()
]) ::
  :ok

Returns :ok when send_text/4 completes; raises API errors or LibTmux.Action.CompletionError otherwise.

split(connection, ref, options \\ [])

Splits an exact pane and returns its ID and optional bound reference as value.

A completed value contains id and ref. Qualified control binds the reference. Use it for another action without recapturing. It identifies the pane in that server incarnation, contains no fresh fields and does not reserve its lifetime. Closing the connection does not invalidate the reference while the pane and server remain. One-shot execution does not establish this binding and returns ref: nil. Unsuccessful outcomes return {:error, %LibTmux.Action.CompletionError{}} with the original result.

Defaults: vertical split, half size, detached, after the target, and tmux's session default shell/command and directory. axis: :horizontal places panes side by side; size: {:percent, n} uses -l n% on every supported release. Optional cwd is literal format text. Choose command: :default, :empty, {:shell, nonempty_bytes} or {:argv, [program | arguments]}. Shell text uses the session's configured shell; argv uses execvp semantics, including PATH lookup and executable-text fallback. Empty argv/program and empty explicit shell text are rejected. At most 64 argv entries and the existing command byte bounds apply; bytes must be NUL-free.

Singleton argv uses the packaged helper to preserve exactly one argument. It replaces itself with the pane program. tmux retains the helper path in pane_start_command; commandless respawn requires that installation to remain available. See command forms. Split acknowledgement does not prove program startup or completion.

session: session_ref selects exact membership/context, not a WindowLink index. timeout defaults to 5000ms. No snapshot is changed; capture again when a new observation is needed. See LibTmux.Action for outcomes and the one-shot identity check/use limitation.

alias LibTmux.Pane

{:ok, %{value: %{ref: created}}} =
  Pane.split(control, pane_ref, axis: :horizontal, size: {:percent, 30})
Pane.send_text(control, created, "hello")

split!(connection, ref, options \\ [])

Returns the created pane value when split/3 completes; raises API errors or LibTmux.Action.CompletionError otherwise.