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

module libtmux-fsharp

Server

Starts server reads and queries with the caller's cancellation token.

Source and package
Qualified name
LibTmux.FSharp.Server
Namespace
LibTmux.FSharp
Package
LibTmux.FSharp
Source
src/LibTmux.FSharp/Hierarchy.fsi

Description

Each function takes the value it acts on last. One that runs a tmux command also takes the cancellation token first and returns a Task, so a call reads Server.tryFindSession token id server or server |> Server.tryFindSession token id, and awaitTask turns the task into an Async. The server is the core LibTmux.Server handle, which is immutable and safe to share.

What is on here

A tmux server does a great many things, but this module covers the part an F# caller reaches first. The rest lives in the sibling modules and on the core handle. The members fall into a few groups:

Connecting
Find a server already listening on the socket the options name, which never starts one, or start one there and own it, which stops it when the scope is disposed and refuses a server already listening on the default socket. Bounding the server by a timeout makes a command that outlasts it fail as MayHaveRun. Entering control mode opens a control client that reports what tmux does.
Finding one thing
Look one up by id, or a client by its exact name; a client name that is null, empty or whitespace throws ArgumentException. Each returns None after a successful lookup establishes absence, and connection, command and cancellation errors propagate unchanged.
Listing everything
Describe a listing of sessions, windows, panes, or clients as a Query, which reads nothing until it is run; every run reads tmux again. A linked window appears once for each session it is linked into, and tmux narrows a filtered client listing only from tmux 3.4, so older tmux lists every client. Capturing reads the tree to the depth asked for and returns a new handle whose captured relations answer without another command.
Querying things and getting around
Narrow a listing with the Query module and a Filter built from SessionFields, WindowFields, PaneFields, or ClientFields; a raw filter handed to tmux keeps no rows, rather than failing, when it is malformed, and a raw client filter throws TmuxVersionTooLowException on tmux older than 3.4. Running the query lists its matches; to read a single one, exactlyOne says why there is not exactly one, tryExactlyOne answers None for none or several, and atMostOne answers None only for none and throws for several. Moving between levels starts a query inside a session or window, and the active pane is read from tmux.
Changing things
Creating a session from a SessionSpec includes its windows and their splits, made one step after another, so a failure part way leaves what was already created. A name already taken throws TmuxSessionExistsException. Everything after that is a function on the value it changes, in the Session, Window, and Pane modules, and the Chain module runs several commands in one tmux invocation.
Options and hooks
This module has none. Options reads and writes an option through a typed key, given the options of the scope the option belongs to, such as the core handle's Options for a server option. Its global hooks are the handle's Hooks.

Paste buffers, key bindings, configuration, shell commands, wait-for channels, and the message log are members of the core LibTmux.Server, which F# calls like any .NET type, and so are menus, command prompts, confirmations, and the commands that attach, switch, detach, lock, or suspend a client. All but attach act on an attached client, and tmux refuses them when there is none; attaching makes the client instead, so it needs a terminal of its own. Anything tmux can do that is not here is reachable through the core handle's ExecuteCommandAsync, which runs one raw command and hands back its result, or through Chain, which runs several in one tmux invocation.

Examples

Create owned session and window scopes with the core LibTmux API, split a pane with Pane.split, then rename and select the window, select the first pane again, arrange the window, title the pane and kill the split with the F# helpers. Renaming and selecting return a handle carrying the state afterwards. Disposing the owned window also stops its panes. For F# session descriptions, use Server.newSession with SessionSpec. Use Linux or macOS with tmux 3.3a or newer, the .NET 10 SDK or newer, and the .NET 8 and 10 runtimes. In an empty directory, save this project as Example.fsproj. It references the 0.1.1 release of LibTmux.FSharp on NuGet: View source

Example.fsproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net8.0;net10.0</TargetFrameworks>
<LangVersion>10.0</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference>
<DisableImplicitLibraryPacksFolder>true</DisableImplicitLibraryPacksFolder>
</PropertyGroup>
<ItemGroup>
<Compile Include="Program.fs" />
<PackageReference Include="FSharp.Core" Version="[10.1.303]" />
<PackageReference Include="LibTmux.FSharp" Version="[0.1.1]" />
</ItemGroup>
</Project>

Save this complete program as Program.fs. It creates a private server with LibTmux.Server.CreateOwnedAsync; use! disposes owned scopes after success, cancellation or failure. The F# facade has no separate server constructor. View source

Program.fsComplete program
open System
open System.IO
open System.Threading
open LibTmux
open LibTmux.FSharp
let runAsync () =
task {
use deadline = new CancellationTokenSource(TimeSpan.FromSeconds 10.)
let token = deadline.Token
let socketRoot = Directory.CreateTempSubdirectory "libtmux-example-"
use _cleanup =
{ new IDisposable with
member _.Dispose() = socketRoot.Delete true
}
let options =
ServerConnectionOptions(
SocketPath = Path.Combine(socketRoot.FullName, "tmux.sock"),
ConfigurationFile = "/dev/null"
)
use! owned = options |> Server.createOwned token
use! session =
owned.Value.CreateOwnedSessionAsync(
NewSessionRequest(Name = "demo", WindowName = "shell", Command = "/bin/cat"),
token
)
use! window =
session.Value.CreateOwnedWindowAsync(
NewWindowRequest(Name = "editor", Command = "/bin/cat", Attach = false),
token
)
let! panes = window.Value.GetPanesAsync(token)
let original = panes |> Seq.exactlyOne
let! added =
original
|> Pane.split token (SplitPaneRequest(Direction = PaneDirection.Right, Command = "/bin/cat"))
// Renaming and selecting return a handle carrying the state afterwards.
let! notes = window.Value |> Window.rename token "notes"
let wasCurrent = notes.Active
let! current = notes |> Window.select token
let! focused = original |> Pane.select token
let! _ = current |> Window.selectLayout token "even-horizontal"
let! titled = focused |> Pane.setTitle token "editor"
do! added |> Pane.kill token
let server = owned.Value
let! windows = server |> Server.windows |> Query.list token
let! allPanes = server |> Server.panes |> Query.list token
printfn "Created session demo and window editor."
printfn "The split made a new pane: %b" (added.Id <> original.Id)
printfn "Renamed to %s; current before select: %b, after: %b" current.Name wasCurrent current.Active
printfn "First pane active again: %b; titled %s" focused.Active titled.Title
printfn "Windows: %d; panes after the kill: %d" windows.Count allPanes.Count
}
runAsync().GetAwaiter().GetResult()

Build the project and run both supported frameworks. Each program checks its result and exits unsuccessfully after an unhandled error:

Terminal window
$ dotnet build Example.fsproj --configuration Release && \
dotnet bin/Release/net8.0/Example.dll && \
dotnet bin/Release/net10.0/Example.dll

Expected program output from each framework:

Created session demo and window editor.
The split made a new pane: true
Renamed to notes; current before select: false, after: true
First pane active again: true; titled editor
Windows: 2; panes after the kill: 2

Members13 members

Collections and queries5

  • sessions Queries every session.
  • windows Queries window placements across all sessions.
  • panes Queries every pane.
  • clients Queries attached clients.
  • capture Returns a new server handle captured to the requested depth.

Common operations8

  • newSession Creates a session as described: its windows, and each window's splits.
  • createOwned Starts a server on the socket the options name and owns it; disposing the scope stops it.
  • tryFindPane Returns a pane or None after a successful lookup establishes absence.
  • within Returns the server with every command bounded by a timeout, for it and every handle taken from it.
  • connect Attaches to a server already listening on the socket the options name.
  • tryFindClient Returns the client with an exact name or None after a successful listing finds no match.
  • tryFindSession Returns a session or None after a successful lookup establishes absence.
  • tryFindWindow Returns a window or None after a successful lookup establishes absence.

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 F#
F# LibTmux.FSharp.Server
Starts server reads and queries with the caller's cancellation token.
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.
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
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
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