Core Library0.xAPI reference

Choose documentation 1

pr-173

Current version

pr-173
English

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

MoreLess about this notice

struct libtmux-elixir

Server

Describes a local tmux server for capturing state and running commands.

Source and package
Qualified name
LibTmux.Server
Module
LibTmux
Package
libtmux
Source
lib/libtmux/server.ex
struct LibTmux.Server

Description

new/1 takes an absolute :executable path. Use System.find_executable/1 to resolve a name such as "tmux" through PATH before construction. The optional :cwd and :env default to the caller's working directory and environment. Construction validates the path forms without checking that the executable or socket exists. A Server is an immutable value; constructing one with new/1 neither connects to tmux nor starts it. Commands use -N, so a missing daemon is never started implicitly. start/1 and with_owned/2 start a private server and return a Server that stop/2 can retire.

Choosing the server

new/1 picks the socket in this order, and the first rule that applies wins:

  1. :socket, an absolute socket path, passes -S.
  2. :socket_name, a socket name, passes -L. Pass at most one of :socket and :socket_name.
  3. The LIBTMUX_SOCKET_PATH variable passes -S with its path.
  4. The LIBTMUX_SOCKET variable passes -L with its name.
  5. Otherwise no socket is passed, and tmux chooses. It follows the server that TMUX names when :env has one, and otherwise uses its default socket: default in the tmux-UID directory of TMUX_TMPDIR, or of /tmp.

An explicit option ignores both variables, even an invalid one. When both variables are set, the path wins, as -S does over -L in tmux. A variable that is empty counts as unset, each one alone. The variables come from the :env option, which defaults to the caller's environment, so a Server built with its own :env ignores the caller's variables. A set variable with an invalid value raises ArgumentError that names the variable and never repeats its value.

The choice is made once, in new/1, and t:t/0 records it. A Server that chose a socket removes TMUX and TMUX_PANE from the environment it gives tmux, so a surrounding tmux session cannot redirect it. A Server that chose none keeps both, for one-shot execution and for control connections alike, so a program run inside tmux reaches the server it runs in. Leave TMUX out of :env to send a Server with no socket to tmux's default socket instead.

What is on here

Server describes the endpoint. In Elixir, observation, selection and action functions live in their own modules. Start with these groups:

Connecting
Describe the server for one-shot commands, which do not attach a client. Attach a control client to an existing session for the length of a callback; the client closes afterwards. Run a control client under application supervision. See the managed control guide for connection setup and the host's hook and command-alias requirements.
Describe
Attach for a callback
Owning a private server
Start a tmux server in a private directory, with no inherited TMUX or TMUX_PANE, and stop it when you are done. with_owned/2 does both around a function, so a program needs no shell step to start or clean up tmux. The process that starts the server owns it, and the server stops when that process exits. stop/2 refuses a Server that start/1 did not create; kill/2 sends kill-server to any Server.
Start and stop around a function
Start
Stop
Kill any server
Raise on failure
Finding one thing
Capture a snapshot, then require one match or allow no match. Both reject multiple matches. Turn the chosen observation into a reference tied to the daemon that supplied it, ready for an action.
Capture
Listing everything
Capture sessions, physical windows, window links, panes and attached clients as a LibTmux.Snapshot. One accessor per kind returns a selection from that captured graph without contacting tmux again. Capture failures return an error, not an empty server. Capture covers an interval rather than an atomic transaction; take another snapshot when fresh state is needed.
Capture
Querying things and getting around
Select by criteria such as active: true, or by an Elixir function; selections work with Enum and Stream. Navigation functions use the supplied snapshot. Plural helpers return selections for further filtering; a LibTmux.WindowLink preserves a window's membership in one session.
Other relationships
Changing things
Create detached sessions and windows on an existing server using one-shot execution. Each returns the created ID with ref: nil; capture a fresh observation to obtain a reference. Split a pane to create a pane and get its ID in the completed result. A qualified Control connection also supplies a bound reference; one-shot split returns ref: nil. Rename a session or a window. Send literal bytes or named keys such as "Enter" to a pane. Split, rename and input take a Server or Control connection followed by a reference. Domain bang variants return completed values or raise; nonbang variants return {:ok, result} for completed commands and {:error, error} otherwise. See the action guide and recovery guide.
Send literal bytes
Send named keys
Reading screens, options and formats
Capture pane screen bytes through one-shot execution, which requires a Server. On a control connection, execute a request that reads a field or writes a server user option. Submit the request and keep the returned LibTmux.Operation when the result needs to remain available for independent inspection.
Running any other command
Build a command to run any other tmux command. Running executes one command with literal arguments and returns bounded output and exit evidence. Configured server hooks can still run. Targeted one-shot actions check the observed server identity before writing, leaving a race if the daemon is replaced between that check and the command. Use a qualified Control connection for mutations bound to one daemon instance.
Build
Build an identity probe or literal reply
Run

Members24 members

Collections and queries1

  • snapshot/2 function Captures a new graph explicitly, with bounded work and read retries.

Common operations7

  • run/3 function Runs one trusted command without attaching; returns bounded output and exit evidence.
  • new/1 function Constructs a descriptor for an existing server without connecting or creating it.
  • start/1 function Starts a private tmux server and returns a Server for it.
  • new_session!/3 function Returns the created session value when new_session/3 completes; raises the original error otherwise.
  • snapshot_with_diagnostics/2 function Captures a graph and returns work diagnostics on success or failure.
  • snapshot!/2 function Captures a graph or raises the same structured capture error.
  • with_owned/2 function Starts a private server, calls fun with it and stops it afterwards.

Other members16

Order: the accessors that walk the hierarchy, the operations the ports share, then the rest.

Guides

task material

Pages that discuss Server.

In other ports

task equivalence 22 other ports mapped

Source-verified mappings for A tmux server. A mapping says these APIs perform the same task. It does not say they share defaults, errors or completion: check each page.

A tmux server in each port
PortAPIDiffers from Elixir
Elixir LibTmux.Server
Describes a local tmux server for capturing state and running commands.
This page
Python libtmux.Server
tmux(1) Server [server_manual].
None recorded in the model
Ruby LibTmux::Server
Connects to an existing endpoint. Closing retires clients, never the daemon.
None recorded in the model
Lua libtmux.Server None recorded in the model
PowerShell LibTmux\New-TmuxServer
Construct a tmux endpoint handle without contacting it.
2 overloads
This cmdlet constructs a shared .NET LibTmux.Server handle without contacting tmux.
Julia LibTmux.Server
Describe a tmux endpoint without contacting it. Supply exactly one socket selector. A description does not own a daemon or any sessions. Use from_env to opt into the ambient tmux endpoint.
Server describes an endpoint without contacting tmux. Read its hierarchy with snapshot.
Erlang tmux_server
Open tmux endpoints and execute explicit command values.
open/1 observes an existing daemon and starts an endpoint owner. Domain rows remain immutable values.
Haskell LibTmux.Server
Start, observe and change a tmux daemon through a scoped handle.
LibTmux.Server owns the Server handle. withOwnedServer starts and retires a private daemon; withServer borrows an existing endpoint and releases its own resources afterwards. killServer retires the admitted daemon generation explicitly. Operations such as capture and renameSession are functions of this module that take the handle.
Common Lisp libtmux:client
A connection scope with one external-operation lease. Closing cancels owned work and leaves the tmux daemon alive. Captured data may outlive the client. Public operations never expose its mutable storage.
client is a connection scope with one external-operation lease. Closing it cancels owned work and leaves the tmux daemon alive; daemon owns a daemon the library started.
TypeScript server.Server
One tmux server, addressed by the socket it listens on.
None recorded in the model
Rust server.Server
A cloneable handle to one captured tmux server endpoint.
None recorded in the model
Go tmux.Server
Server is an immutable handle to one tmux configuration. Its zero value is invalid. Copying a configured Server preserves its configuration and shares its mutex-guarded version cache and checked daemon identity, so a Server and the values derived from it are safe for concurrent method calls (see the package documentation).
None recorded in the model
Java io.github.libtmux.Server
Manages sessions, windows, and panes on a tmux server.
readonly
Clojure libtmux.core/open!
Opens local resources for an explicit :socket-path or :socket-name endpoint.
Opens a closeable Java server client for an explicit endpoint. Acquisitions return persistent maps with explicit Java references for effects.
Kotlin io.github.libtmux.kotlin.Server
Manages sessions, windows, and panes on a tmux server.
None recorded in the model
Scala io.github.libtmux.scaladsl.Server
The Java client, opaque: every member beyond java.lang.AutoCloseable#close is an extension, generated from the operation catalog or handwritten where the catalog marks it WAIT, STREAM or LIFECYCLE. Closing an owned client releases its transport, not tmux; close() comes from the AutoCloseable bound with no forwarding of its own, so Using.resource(server) { ... } works.
2 overloads
C# LibTmux.Server
Represents an immutable server handle and snapshot.
None recorded in the model
F# LibTmux.FSharp.Server
Starts server reads and queries with the caller's cancellation token.
This F# module provides functions over the shared .NET LibTmux.Server type.
C++ libtmux::Server
One tmux server, addressed by the socket it listens on.
None recorded in the model
Swift Server
A tmux server, addressed by its endpoint.
None recorded in the model
OCaml Libtmux_unix.Client
An explicit generation-bound connection. Applications retain ownership of the endpoint choice and resource lifetime.
A client is a live, generation-bound server connection. Endpoint describes a socket without connecting; closing a client releases its resources.
Perl LibTmux::Server
Explicit tmux acquisition and commands
Construction records connection settings without tmux I/O. Optional LibTmux::Async::Server returns standard Future results for operations.
Raku LibTmux::Server None recorded in the model
Esc
Search in

Type to search.

Reference previewOpen reference