Core Library0.xAPI reference

Choose documentation 3

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

method libtmux-dotnet

Server.GetSessionAsync

Reads one session by identifier, throwing when it is absent.

Source and package
Qualified name
LibTmux.Server.GetSessionAsync
Namespace
LibTmux
Declared in
Server
Package
LibTmux
Source
src/LibTmux/Server.Identity.cs

Description

A handle that has not found a live server yet discovers one first.

Parameters
Returns

A materialized session carrying captured scalar state.

Errors

Examples

Use typed required lookups, nullable absence and explicit errors. Cancellation, invalid input and a stopped server remain exceptions. 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.csproj. It references the 0.1.1 release of LibTmux on NuGet: View source

Example.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net8.0;net10.0</TargetFrameworks>
<LangVersion>12.0</LangVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>disable</ImplicitUsings>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<AnalysisLevel>10-recommended</AnalysisLevel>
</PropertyGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<PackageReference Include="LibTmux" Version="[0.1.1]" />
</ItemGroup>
</Project>

Save this complete program as Program.cs. It creates a private server; await using disposes its owned scopes after success, cancellation or failure. The complete file contains explicit imports, a top-level async entry point and a cancellation deadline. View source

Program.csComplete program
using System;
using System.IO;
using System.Linq;
using System.Threading;
using LibTmux;
if (OperatingSystem.IsWindows())
{
throw new PlatformNotSupportedException("This example requires tmux on Linux or macOS.");
}
using CancellationTokenSource deadline = new(TimeSpan.FromSeconds(10));
CancellationToken token = deadline.Token;
string? testTmux = Environment.GetEnvironmentVariable("LIBTMUX_TEST_TMUX");
string? configured = !string.IsNullOrWhiteSpace(testTmux)
? testTmux
: Environment.GetEnvironmentVariable("LIBTMUX_TMUX");
string binary = string.IsNullOrWhiteSpace(configured) ? "tmux" : configured;
using TemporaryDirectory socketRoot = new();
ServerConnectionOptions options = new()
{
SocketPath = Path.Combine(socketRoot.FullName, "tmux.sock"),
ConfigurationFile = "/dev/null",
TmuxBinaryPath = binary,
};
Server stoppedServer;
await using (OwnedServerScope owned = await Server.CreateOwnedAsync(options, token))
{
await using OwnedSessionScope session = await owned.Value.CreateOwnedSessionAsync(
new NewSessionRequest { Name = "demo", Command = "/bin/cat" }, token);
Server server = await Server.ConnectAsync(options, token);
Session found = await server.GetSessionAsync(session.Value.Id, token);
Window listedWindow = (await found.GetWindowsAsync(token)).Single();
Window window = await server.GetWindowAsync(listedWindow.Id, token);
Pane listedPane = (await window.GetPanesAsync(token)).Single();
Pane pane = await server.GetPaneAsync(listedPane.Id, token);
if (found.Id != session.Value.Id || pane.Id != listedPane.Id)
{
throw new InvalidOperationException("Typed lookup returned an unexpected entity.");
}
SessionId missingId = new(int.MaxValue);
Session? missing = await server.FindSessionAsync(missingId, token);
if (missing is not null)
{
throw new InvalidOperationException("The absent session unexpectedly exists.");
}
Console.WriteLine("A successful lookup can return null.");
try
{
_ = await server.GetSessionAsync(missingId, token);
throw new InvalidOperationException("GetSessionAsync must throw for an absent session.");
}
catch (TmuxObjectNotFoundException)
{
Console.WriteLine("Required lookup reports TmuxObjectNotFoundException.");
}
using CancellationTokenSource cancelled = new();
cancelled.Cancel();
try
{
_ = await server.FindSessionAsync(session.Value.Id, cancelled.Token);
throw new InvalidOperationException("Cancelled lookup must throw.");
}
catch (OperationCanceledException)
{
Console.WriteLine("Cancellation remains OperationCanceledException.");
}
try
{
_ = await window.FindPaneAsync(" ", token);
throw new InvalidOperationException("A blank pane target must be rejected.");
}
catch (ArgumentException)
{
Console.WriteLine("A blank pane target remains ArgumentException.");
}
stoppedServer = server;
}
try
{
_ = await stoppedServer.FindSessionAsync(new SessionId(int.MaxValue), token);
throw new InvalidOperationException("A failed read must not become null.");
}
catch (LibTmuxException)
{
Console.WriteLine("A stopped server remains a LibTmuxException.");
}
internal sealed class TemporaryDirectory : IDisposable
{
private readonly DirectoryInfo _directory = Directory.CreateTempSubdirectory("libtmux-example-");
public string FullName => _directory.FullName;
public void Dispose() => _directory.Delete(recursive: true);
}

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.csproj --configuration Release && \
dotnet bin/Release/net8.0/Example.dll && \
dotnet bin/Release/net10.0/Example.dll

Expected program output from each framework:

A successful lookup can return null.
Required lookup reports TmuxObjectNotFoundException.
Cancellation remains OperationCanceledException.
A blank pane target remains ArgumentException.
A stopped server remains a LibTmuxException.

Recorded calls

source calls
No call edges in the C# model.

The C# reference records declarations, not calls, so this page shows no callers or callees. That is a limit of the extracted data, not a statement that nothing calls LibTmux.Server.GetSessionAsync.

tmux command

task material

The tmux commands behind GetSessionAsync.

tmux C API

task material

The C declarations in tmux that implement these commands.

In other ports

task equivalence 7 other ports mapped

Source-verified mappings for Look one session up by target. A mapping says these APIs perform the same task. It does not say they share defaults, errors or completion: check each page.

Look one session up by target in each port
PortAPIDiffers from C#
C# LibTmux.Server.GetSessionAsync
Reads one session by identifier, throwing when it is absent.
This page
Ruby LibTmux::Server#session
Behavior: Live handles.
None recorded in the model
Erlang tmux_session:get/2
Read fresh session fields through explicit one-shot commands. The session ID is stable within the observed server incarnation. Returns target_gone when tmux no longer has that session; it never refreshes an existing record.
free function
Rust server.Server.session
Find the session with this exact name.
None recorded in the model
Go tmux.Server.Session
Session performs a canonical live lookup of id and returns a newly materialized record. Use Session.Refresh when beginning from a record.
None recorded in the model
C++ libtmux::Server::session
One object by target, for a caller holding an id or a session:window path that came from somewhere else.
readonly
OCaml Libtmux.Snapshot.find_session free function
Exact opaque-ID lookup in an existing snapshot, without I/O or tmux target expansion.
Perl LibTmux::Snapshot::session_by_id
session_by_id('$1') returns a LibTmux::Session or undef. Single quotes preserve the dollar-prefixed ID instead of interpolating a regex capture.
on Snapshot
Captured stable-ID lookup returns an entity or undef. Use Selection::one for strict criteria/name lookup.
No Python equivalent.

no equivalent on Server

No Haskell equivalent.

No public Haskell equivalent is implemented; the current modules expose scalar values and version parsing.

No TypeScript equivalent.

no equivalent on Server

No Java equivalent.

no equivalent on Server

No Swift equivalent.

no equivalent on Server

No Raku equivalent.

No direct Raku mapping is recorded for this operation; consult the native API reference.

No equivalent is recorded in Lua, PowerShell, Julia, Elixir, Common Lisp, Clojure, Kotlin, Scala or F#.

Esc
Search in

Type to search.

Reference previewOpen reference