# Server

- **Package:** libtmux-swift
- **Language:** Swift
- **Kind:** struct
- **Source:** https://github.com/libtmux/libtmux-swift/blob/254f8b2be7eb60cacc3ffcb3ea8e456784f582df/Sources/LibTmux/Server.swift#L10
- **Page:** https://libtmux.org/en/swift/latest/reference/server/

A tmux server, addressed by its endpoint.

`Server` is a value: copying one is free, copies compare equal, and passing
one across a task boundary needs no ceremony. The mutable part — the process
boundary and anything cached about the running daemon — lives behind an
actor that every copy shares, so two copies of the same server coordinate
with each other rather than racing.

## Members

- `buffers()` (method): The server's paste buffers, most recent first.
- `setBuffer(_:named:)` (method): Puts text into a named buffer.
- `buffer(named:)` (method): Reads a buffer's contents, or `nil` if no such buffer exists.
- `deleteBuffer(named:)` (method)
- `loadBuffer(from:named:)` (method): Fills a buffer from a file, letting tmux read it.
- `saveBuffer(named:to:)` (method): Writes a buffer to a file, letting tmux do the writing.
- `paste(buffer:into:)` (method): Pastes a buffer into a pane.
- `capture(_:since:limit:)` (method): Reads only what a pane has printed since `cursor`.
- `run(_:)` (method): Runs a list of commands in one tmux invocation.
- `connected(attachingTo:_:)` (method): Runs `body` with every command carried by one live connection instead of a new tmux process each time.
- `using(_:_:)` (method): Runs `body` with this server in `mode`.
- `withControlMode(attachingTo:_:)` (method): Opens a control-mode connection for the duration of `body`, handing over the connection itself.
- `newSession(named:startDirectory:windowName:width:height:)` (method): Creates a detached session.
- `newWindow(in:named:startDirectory:)` (method): Creates a window in a session and returns its exact appearance.
- `newWindow(_:_:named:startDirectory:)` (method): Creates a window next to one that already exists and returns its exact appearance.
- `splitWindow(_:direction:size:startDirectory:)` (method): Splits a window's active pane, returning the pane that appeared.
- `split(_:direction:size:startDirectory:)` (method): Splits one pane, returning the pane that appeared.
- `environment(_:)` (method): Every variable in an environment, in the order tmux printed them.
- `environmentValue(_:in:)` (method): What one variable is set to, or `nil` when it is unset or marked for removal.
- `setEnvironment(_:to:in:)` (method): Sets a variable, replacing whatever was there.
- `unsetEnvironment(_:in:)` (method): Unsets a variable, leaving no trace of it.
- `removeEnvironment(_:in:)` (method): Marks a variable so new processes start without it, even when it is set in the environment tmux itself was started from.
- `sessions(where:)` (method): Sessions matching `expression`.
- `windows(where:)` (method): Windows matching `expression`.
- `panes(where:)` (method): Panes matching `expression`.
- `clients(where:)` (method): Clients matching `expression`.
- `format(_:for:)` (method): Evaluates a tmux format and hands back what it printed.
- `format(_:for:through:)` (method): Evaluates a tmux format against a pane through one of its window links. See ``format(_:for:)-(String,Session)``.
- `format(_:addressing:)` (method): Evaluates a tmux format against a target named by id.
- `format(_:)` (method): Evaluates a tmux format against the server rather than any one object.
- `session(_:)` (method): The session with this id, or `nil` if the server has no such session.
- `window(_:)` (method): The window with this id, or `nil` if the server has no such window.
- `pane(_:)` (method): The pane with this id, or `nil` if the server has no such pane.
- `session(named:)` (method): The session with this name, or `nil` if no session has it.
- `windows(named:)` (method): Every window with this name, in tmux's own order.
- `refresh(_:)` (method): This session as it is now, or `nil` if it has gone away.
- `rename(_:to:)` (method)
- `selectLayout(_:_:)` (method): Applies one of tmux's own layouts — `even-horizontal`, `tiled`, and the rest — to a window.
- `resize(_:width:height:)` (method): Sets a pane's size outright.
- `resize(_:by:toward:)` (method): Nudges a pane's boundary, leaving the rest of the layout to absorb it.
- `toggleZoom(_:)` (method): Toggles whether one pane fills its window.
- `kill(_:)` (method)
- `select(_:)` (method)
- `selectNextWindow(in:)` (method): Moves to the next window of a session, wrapping at the end.
- `selectPreviousWindow(in:)` (method)
- `selectLastWindow(in:)` (method): Returns to the window that was active before the current one.
- `selectLastPane(in:)` (method): Returns to the pane that was active before the current one.
- `swap(_:with:)` (method): Swaps two window appearances. Their underlying window ids do not change, but both links move to new indices.
- `rotate(_:upward:)` (method): Shifts every pane in a window one position around the layout.
- `nextLayout(_:)` (method): Cycles a window through tmux's preset layouts.
- `previousLayout(_:)` (method)
- `breakPane(_:from:named:)` (method): Moves a pane out into a window of its own, and returns its appearance.
- `join(_:into:direction:size:)` (method): Moves a pane into another window, splitting it.
- `enterCopyMode(_:)` (method): Enters copy mode in a pane.
- `cancelModes(in:)` (method): Idempotently clears the entire mode stack of a pane.
- `clearHistory(_:)` (method): Clears a pane's visible screen and its scrollback.
- `setTitle(_:of:)` (method): Sets a pane's title. The title is only shown when tmux is configured to display it, but it is always readable through a format.
- `detach(_:)` (method): Detaches a client from the server it is attached to.
- `detachClients(from:)` (method): Detaches every client attached to a session.
- `startServer()` (method): Starts the server if it is not already running.
- `killServer()` (method)
- `sourceFile(_:)` (method): Loads a tmux configuration file into the running server.
- `requireRunning()` (method): Throws unless a server is listening.
- `respawn(_:running:killingExisting:startDirectory:)` (method): Restarts the command in a pane.
- `respawn(_:running:killingExisting:)` (method)
- `pipe(_:to:)` (method): Copies everything a pane outputs to a shell command, or stops doing so when `command` is omitted.
- `options(_:)` (method): Every option set in one exact table.
- `option(_:scope:)` (method): The value of one option, or `nil` if it is not set in that table.
- `resolvedOption(_:scope:)` (method): The effective value after tmux resolves inherited option tables.
- `setOption(_:to:scope:)` (method): Sets an option.
- `unsetOption(_:scope:)` (method): Puts an option back the way it was before anyone set it.
- `hooks(_:)` (method): Hooks tmux has a command for.
- `setHook(_:to:at:in:)` (method): Binds a command to a hook.
- `unsetHook(_:in:)` (method): Unbinds every command from a hook.
- `runHook(_:in:)` (method): Runs a hook's commands now, without waiting for what would trigger it.
- `sendKeys(_:to:literally:)` (method): Sends keys to a pane.
- `run(_:in:)` (method): Runs a shell command line in a pane, as if typed.
- `shellInvocation` (property): How a command running *inside* a pane spells a tmux that reaches this server.
- `capture(_:includingHistory:)` (method): The pane's visible contents, one line per row. The source read is capped at 1 MiB; use incremental capture for a large scrollback instead of collecting its entire history.
- `capture(_:includingHistory:maximumLines:)` (method): Reads the newest rows without collecting older rows that will be discarded.
- `captureRange(_:startingAt:endingAt:joiningWrappedLines:maximumLines:)` (method): Reads a bounded tmux capture range using tmux's relative row numbering.
- `!=(_:_:)` (function): Returns a Boolean value indicating whether two values are not equal.
- `endpoint` (property): Where this server listens. Every command carries it, so no call can reach the ambient server by accident.
- `tmuxExecutable` (property): The tmux this server runs, resolved to a path.
- `mode` (property): How work from this server reaches tmux.
- `init(socketPath:tmuxExecutable:configurationFile:)` (method)
- `init(socketName:tmuxExecutable:configurationFile:)` (method)
- `sessions()` (method): Every session on this server, in tmux's own order.
- `windows()` (method): Every window on this server, in tmux's own order.
- `windowLinks()` (method): Every session-local link to a window, in tmux's own order.
- `panes()` (method): Every pane on this server, in tmux's own order. A pane whose window has several session links appears once.
- `clients()` (method): Every client attached to this server.
- `snapshot()` (method): Reads every object from one daemon incarnation.
- `serverProcessID()` (method): The running server's process id.
- `incarnation()` (method): The running daemon at this endpoint.
- `hasSession(_:)` (method): Whether a session by this name or id exists.
- `isRunning()` (method): Whether a server is listening on this endpoint.
- `==(_:_:)` (function): Returns a Boolean value indicating whether two values are equal.
- `hash(into:)` (method): Hashes the essential components of this value by feeding them into the given hasher.
- `version()` (method): Which tmux this server runs.
- `wait(for:)` (method): Blocks until something signals `channel`.
- `signal(_:)` (method): Releases one waiter on `channel`.
- `waitForOutput(in:matching:stoppingAt:requiringFreshOutput:startingAt:timeout:tailLimit:)` (method): Waits until a pane prints something, driven by tmux output events.
- `move(_:to:at:)` (method): Moves one window appearance into another session.
- `link(_:into:)` (method): Links a window into another session. The same window then appears in both, sharing one id — which is tmux's model, not a copy. The source is global because no existing session-local appearance is involved.
- `unlink(_:)` (method): Removes one of a linked window's appearances. The window survives while any session still holds it.
