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 readsServer.tryFindSession token id serverorserver |> Server.tryFindSession token id, andawaitTaskturns the task into anAsync. The server is the coreLibTmux.Serverhandle, 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 returnsNoneafter 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
Querymodule and aFilterbuilt fromSessionFields,WindowFields,PaneFields, orClientFields; a raw filter handed to tmux keeps no rows, rather than failing, when it is malformed, and a raw client filter throwsTmuxVersionTooLowExceptionon tmux older than 3.4. Running the query lists its matches; to read a single one,exactlyOnesays why there is not exactly one,tryExactlyOneanswersNonefor none or several, andatMostOneanswersNoneonly 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
SessionSpecincludes its windows and their splits, made one step after another, so a failure part way leaves what was already created. A name already taken throwsTmuxSessionExistsException. 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.
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'sExecuteCommandAsync, which runs one raw command and hands back its result, or throughChain, 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 ofLibTmux.FSharpon NuGet: View sourceExample.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 withLibTmux.Server.CreateOwnedAsync;use!disposes owned scopes after success, cancellation or failure. The F# facade has no separate server constructor. View sourceProgram.fsComplete program open Systemopen System.IOopen System.Threadingopen LibTmuxopen LibTmux.FSharplet runAsync () =task {use deadline = new CancellationTokenSource(TimeSpan.FromSeconds 10.)let token = deadline.Tokenlet socketRoot = Directory.CreateTempSubdirectory "libtmux-example-"use _cleanup ={ new IDisposable withmember _.Dispose() = socketRoot.Delete true}let options =ServerConnectionOptions(SocketPath = Path.Combine(socketRoot.FullName, "tmux.sock"),ConfigurationFile = "/dev/null")use! owned = options |> Server.createOwned tokenuse! 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.exactlyOnelet! 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.Activelet! current = notes |> Window.select tokenlet! focused = original |> Pane.select tokenlet! _ = current |> Window.selectLayout token "even-horizontal"let! titled = focused |> Pane.setTitle token "editor"do! added |> Pane.kill tokenlet server = owned.Valuelet! windows = server |> Server.windows |> Query.list tokenlet! allPanes = server |> Server.panes |> Query.list tokenprintfn "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.Activeprintfn "First pane active again: %b; titled %s" focused.Active titled.Titleprintfn "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.dllExpected program output from each framework:
Created session demo and window editor.The split made a new pane: trueRenamed to notes; current before select: false, after: trueFirst pane active again: true; titled editorWindows: 2; panes after the kill: 2
Members13 members
Collections and queries5
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 materialPages that discuss Server.
- Concepts
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 F# |
|---|---|---|
| F# | Lib Starts server reads and queries with the caller's cancellation token. | 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. | 2 overloads 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 |
| Scala | io 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# | Lib Represents an immutable server handle and snapshot. | None recorded in the model |
| 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 |