Core Library0.xAPI reference

Choose documentation 1

latest

Current version

latest
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

typealias libtmux-scala

Server

Manages sessions, windows, and panes on a tmux server.

Base types AutoCloseable
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 <: AutoCloseable = JavaServerobject Server

Description

Use Server.open with a ServerConfig to select a server by socket name or path. From this object, create sessions or query the server's existing sessions, windows, and panes. Each Session contains windows, and each Window contains panes.

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.

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.open makes a server over a transport it owns, and Server.fromJava wraps a server opened in Java. config says how it was configured, Server.identity which server it is, and version which tmux. isAlive and requireAlive answer whether anything is listening. Server.within bounds every command by a deadline, admissionBound says how many commands run at once, and Server.control attaches a control client. toBuilder starts a Java builder from this server's choices, and Server.asJava reaches the underlying Java server.
Finding one thing
session takes a name, an id, or an expression; pane takes an id or an expression; window takes an expression or a WindowContext. Each returns an Option that is empty when tmux does not have it, and an expression that matches several throws CardinalityException.MultipleMatches. hasSession answers by name without returning the session.
Listing everything
sessions, windows, panes, clients, and attachedSessions each return a Vector captured now. A failed read throws, so an outage does not read as an empty server. windows also takes a WindowId and answers every link to that window. snapshot captures the whole tree with one listing per kind of object rather than one command per object, and io.github.libtmux.scaladsl.live.LiveView keeps that tree current as tmux announces changes.
Querying things and getting around
Build an Expr from the fields on the Session, Window, and Pane companions, such as Pane.command.startsWith("nvim"), and hand it to sessions, windows, panes, session, window, or pane; tmux does the filtering when it can. To move between levels, go down with Session.windows and Window.panes, up with Pane.window and Window.session, and across to the focused child with Session.activeWindow and Window.activePane. Each is a pure read of the capture, so none asks tmux again.
Changing things
newSession creates a detached session from a name, a callback on a builder, or a SessionSpec, and returns the session tmux made. killSession ends a session by name, killServer ends the tmux server and every session on it, which close() deliberately does not, and lock locks every attached client.
Options and hooks
options holds the server-wide options, globalOptions the session options every session inherits unless it sets its own, hooks the global hooks, and environment the 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). expand expands a format against the server, variables reads named variables in one expansion, and paneFields reads chosen fields of every pane from one listing.
Running a command
Anything tmux can do that is not here is reachable through cmd, which runs one command and hands back its result, run, which throws when tmux reports a nonzero exit, or batch and chain, which run several in one invocation.

Examples

Connect to a private tmux server. Use JDK 25, Gradle 9 or newer, and tmux 3.3a or newer on Linux, with /bin/cat and /bin/sh available. In an empty directory, save this consumer setup as settings.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 {
scala
application
}
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 source

gradle.properties
org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=768m -Dfile.encoding=UTF-8
kotlin.daemon.jvmargs=-Xmx2g
org.gradle.workers.max=2

Save 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 source

src/main/scala/Connect.scalaComplete program
package io.github.libtmux.examples.api.scaladirect
import io.github.libtmux.scaladsl.*
import scala.util.Using
import 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-example

Expected 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 timeout rather 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: prefix when 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.

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 Scala
Scala io.github.libtmux.scaladsl.Server
Manages sessions, windows, and panes on a tmux server.
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.
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.
Elixir LibTmux.Server
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 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
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