Server
Manages sessions, windows, and panes on a tmux server.
Source and package
- Qualified name
-
io.github .libtmux .scaladsl. Server - Package
- io.github.libtmux.scaladsl
- Distribution
- io.github.libtmux:libtmux-scala_3
- Source
- libtmux-scala/src/main/scala/io/github/libtmux/scaladsl/Server.scala
- opaque type Server <: Auto
Closeable = JavaServer object Server -
Description
Use
Server.openwith aServerConfigto select a server by socket name or path. From this object, create sessions or query the server's existing sessions, windows, and panes. EachSessioncontains windows, and eachWindowcontains panes.The Java client, opaque: every member beyond
java.lang.AutoCloseable#closeis an extension, generated from the operation catalog or handwritten where the catalog marks itWAIT,STREAMorLIFECYCLE. Closing an owned client releases its transport, not tmux;close()comes from theAutoCloseablebound with no forwarding of its own, soUsing.resource(server) { ... }works.What is on here
A tmux server does a great many things, so this type has a great many members. They fall into a few groups:
- Connecting
Server.openmakes a server over a transport it owns, andServer.fromJavawraps a server opened in Java.configsays how it was configured,Server.identitywhich server it is, andversionwhich tmux.isAliveandrequireAliveanswer whether anything is listening.Server.withinbounds every command by a deadline,admissionBoundsays how many commands run at once, andServer.controlattaches a control client.toBuilderstarts a Java builder from this server's choices, andServer.asJavareaches the underlying Java server.- Finding one thing
sessiontakes a name, an id, or an expression;panetakes an id or an expression;windowtakes an expression or aWindowContext. Each returns anOptionthat is empty when tmux does not have it, and an expression that matches several throwsCardinalityException.MultipleMatches.hasSessionanswers by name without returning the session.- Listing everything
sessions,windows,panes,clients, andattachedSessionseach return aVectorcaptured now. A failed read throws, so an outage does not read as an empty server.windowsalso takes aWindowIdand answers every link to that window.snapshotcaptures the whole tree with one listing per kind of object rather than one command per object, andio.github.libtmux.scaladsl.live.LiveViewkeeps that tree current as tmux announces changes.- Querying things and getting around
- Build an
Exprfrom the fields on theSession,Window, andPanecompanions, such asPane.command.startsWith("nvim"), and hand it tosessions,windows,panes,session,window, orpane; tmux does the filtering when it can. To move between levels, go down withSession.windowsandWindow.panes, up withPane.windowandWindow.session, and across to the focused child withSession.activeWindowandWindow.activePane. Each is a pure read of the capture, so none asks tmux again. - Changing things
newSessioncreates a detached session from a name, a callback on a builder, or aSessionSpec, and returns the session tmux made.killSessionends a session by name,killServerends the tmux server and every session on it, whichclose()deliberately does not, andlocklocks every attached client.- Options and hooks
optionsholds the server-wide options,globalOptionsthe session options every session inherits unless it sets its own,hooksthe global hooks, andenvironmentthe variables every new process is given.- Everything else tmux keeps
- Paste buffers (
buffers), key bindings (keys), a file of tmux commands to run (sourceFile), shell commands (shell), the command list (commands), the message log (messageLog), prompt history (prompt), and wait-for channels (channel).expandexpands a format against the server,variablesreads named variables in one expansion, andpaneFieldsreads chosen fields of every pane from one listing.
Examples
Connect to a private tmux server. Use JDK 25, Gradle 9 or newer, and tmux 3.3a or newer on Linux, with
/bin/catand/bin/shavailable. In an empty directory, save this consumer setup assettings.gradle.kts:rootProject.name = "api-example"Save this consumer setup as
build.gradle.kts. It depends on the 0.1.2 release from Maven Central:plugins {scalaapplication}repositories { mavenCentral() }dependencies {implementation("io.github.libtmux:libtmux-scala_3:0.1.2")implementation("org.scala-lang:scala3-library_3:3.9.0")}java { toolchain { languageVersion.set(JavaLanguageVersion.of(25)) } }application { mainClass.set(providers.gradleProperty("exampleMain")) }Save this consumer setup as
gradle.properties: View sourcegradle.properties org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=768m -Dfile.encoding=UTF-8kotlin.daemon.jvmargs=-Xmx2gorg.gradle.workers.max=2Save this complete program as
src/main/scala/Connect.scala. It starts a private tmux server of its own and stops it when the program closes it. View sourcesrc/main/scala/Connect.scalaComplete program package io.github.libtmux.examples.api.scaladirectimport io.github.libtmux.scaladsl.*import scala.util.Usingimport scala.util.control.NonFatal/** Connect to a private tmux server. */object Connect {def main(args: Array[String]): Unit = {try {Using.resource(Server.start()) { server =>println(s"connected=${server.isAlive()}")}} catch {case NonFatal(error) =>System.err.println("Example failed: " + error.getMessage)sys.exit(1)}}}Build the minimal consumer with Gradle and run the saved program. An operation or cleanup error makes the command exit unsuccessfully:
Terminal window $ gradle --console=plain --quiet installDist -PexampleMain=io.github.libtmux.examples.api.scaladirect.Connect && \build/install/api-example/bin/api-exampleExpected output:
connected=true
Members51 members
Collections and queries6
- sessions method The sessions this expression matches, captured now.
- windows method Captures every winlink, preserving each session and index placement.
- panes method Captures every pane on the server.
- clients method Captures every attached client.
- buffers method The server's paste buffers, which every session shares.
- snapshot method Captures the whole hierarchy in at most four listings, retrying once if the server is replaced.
Common operations10
- newSession method Creates a detached session and returns that exact session.
- killServer method Ends the tmux server and every session on it.
- fromJava method Borrows a Java client this facade did not open; closing it closes that client too.
- open method Opens an owned client for
config. - cmd method Runs one tmux command against this server.
- control method A control-mode client on
session, refused by a tmux other than the one that captured it.LIFECYCLE, handwritten: resource scoping, not a per-operation forward. - hooks method The global hooks every session inherits.
- shell method Shell commands run by tmux, and tmux commands chosen by a shell exit status.
- start method Starts a private tmux server that the result owns. Unlike any other server, closing it ends tmux, removes its directory and throws if the server still answers, so
Using.resource(Server.start()) { ... }leaves nothing behind. - within method This server with every command given
timeoutrather than the default, sharing this one's transport and scope.LIFECYCLE, handwritten: not a per-operation forward, a derived scope.
Other members35
- admissionBound method How many tmux commands this server's transport runs at once, from
ServerConfig#maxConcurrentCommands()for a server#opened here. - asJava method The underlying Java client. Opaque wrapping is free, so this never copies scope or state.
- attachedSessions method Captures every session a client is attached to.
- batch method Collects several commands to run in one tmux invocation.
- batchReservingCapacity method Collects a group that may wait for a release through this server's transport.
- captureServer method Captures metadata and entity handles from one observed hierarchy.
- chain method Starts a chain of commands where each one acts on what the last one made.
- chainReservingCapacity method Starts an implicit-target chain while reserving transport capacity for its release.
- channel method One of this server's wait-for channels, which is where a signal is sent and waited for.
- commands method The commands this tmux knows.
- config method How this server was configured.
- environment method The server's environment, which every session inherits and every new process is given.
- expand method Expands a tmux format against the server, and answers with what it came to.
- given_CanEqual_Server_Server constant
- globalOptions method The global session options every session inherits unless it sets its own.
- hasSession method Whether a session with this name exists.
- identity method Which server this is.
- isAlive method Whether the server is running and answering.
- keys method The server's key bindings:
prefixwhen binding, every table when listing. - killSession method Ends the session with this name, and everything in it.
- lock method Locks every client attached to this server.
- messageLog method The server's message log.
- options method The server-wide options, the ones tmux keeps once per server.
- pane method The one pane this expression matches, captured now, or empty when none does.
- paneFields method Chosen fields for every pane on the server, from one listing.
- prompt method The command prompt's history.
- requireAlive method Requires a running tmux daemon that answers the liveness probe.
- requireCompatibleTmux method Requires a compatible daemon, or a compatible executable when this endpoint is unused.
- run method Runs a command that is expected to work, and raises when it did not.
- session method The one session this expression matches, captured now, or empty when none does.
- sourceFile method Runs a file of tmux commands, as a configuration file would be run.
- toBuilder method A builder holding every configuration and ownership choice this server made.
- variables method Reads only validated tmux variable names, never caller-authored format syntax.
- version method Which tmux this server is running.
- window method The one window link this expression matches, captured now, or empty when none does.
No members of Server match . The filter searches only this type. Search the whole API.
Order: the accessors that walk the hierarchy, the operations the ports share, then the rest.
Guides
task materialPages that discuss Server.
In other ports
task equivalence 22 other ports mappedSource-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.
| Port | API | Differs from Scala |
|---|---|---|
| Scala | io Manages sessions, windows, and panes on a tmux server. | This page |
| Python | libtmux tmux(1) Server [server_manual]. | None recorded in the model |
| Ruby | Lib Connects to an existing endpoint. Closing retires clients, never the daemon. | None recorded in the model |
| Lua | libtmux | None recorded in the model |
| PowerShell | Lib Construct a tmux endpoint handle without contacting it. | This cmdlet constructs a shared .NET LibTmux.Server handle without contacting tmux. |
| Julia | Lib 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. | |
| Erlang | tmux Open tmux endpoints and execute explicit command values. | open/1 observes an existing daemon and starts an endpoint owner. Domain rows remain immutable values. |
| Elixir | Lib An explicit local tmux server descriptor. | Server describes an existing server by executable and socket. It neither connects nor reserves the server’s identity. |
| Haskell | Lib 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: 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. | |
| TypeScript | server One tmux server, addressed by the socket it listens on. | None recorded in the model |
| Rust | server A cloneable handle to one captured tmux server endpoint. | None recorded in the model |
| Go | tmux 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 Manages sessions, windows, and panes on a tmux server. | readonly |
| Clojure | libtmux 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 Manages sessions, windows, and panes on a tmux server. | None recorded in the model |
| C# | Lib Represents an immutable server handle and snapshot. | None recorded in the model |
| F# | Lib 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:: 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 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 | Lib Explicit tmux acquisition and commands | Construction records connection settings without tmux I/O. Optional LibTmux::Async::Server returns standard Future results for operations. |
| Raku | Lib | None recorded in the model |