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.CreateSessionAsync

Creates a session.

Source and package
Qualified name
LibTmux.Server.CreateSessionAsync
Namespace
LibTmux
Declared in
Server
Package
LibTmux
Source
src/LibTmux/Server.Lifecycle.cs

Description

Set ExpectedGeneration to require one daemon before creation. Readback always uses the generation reported by creation itself. A daemon change after creation reports a partial failure rather than returning its replacement.

Parameters
Returns

The created session.

Errors

Examples

Create entities directly inside an owned server scope, then read the session and window children. The outer scope stops its daemon and all created entities. 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.Collections.Generic;
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,
};
// The outer server scope owns everything created directly inside this daemon.
await using OwnedServerScope owned = await Server.CreateOwnedAsync(options, token);
Session session = await owned.Value.CreateSessionAsync(
new NewSessionRequest { Name = "demo", WindowName = "shell", Command = "/bin/cat" }, token);
Window window = await session.CreateWindowAsync(
new NewWindowRequest { Name = "editor", Command = "/bin/cat" }, token);
Pane original = (await window.GetPanesAsync(token)).Single();
Pane added = await original.SplitAsync(
new SplitPaneRequest { Direction = PaneDirection.Right, Command = "/bin/cat" }, token);
IReadOnlyList<Window> windows = await session.GetWindowsAsync(token);
IReadOnlyList<Pane> panes = await session.GetPanesAsync(token);
if (windows.Count != 2 || panes.Count != 3 || added.Id == original.Id)
{
throw new InvalidOperationException("Expected two windows and three distinct panes.");
}
Console.WriteLine($"Created session {session.Name} and window {window.Name}.");
Console.WriteLine($"Windows: {windows.Count}; panes: {panes.Count}");
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:

Created session demo and window editor.
Windows: 2; panes: 3

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.CreateSessionAsync.

tmux command

task material

The tmux commands behind CreateSessionAsync.

tmux C API

task material

The C declarations in tmux that implement these commands.

Each path starts at a function a command runs, which is degree 1. The degree counts steps from there along the path, and each step is a call or a reference: degree 2 is reached from that function, degree 3 from the next, and so on.

Create a session and its first pane

  1. 1 cmd_new_session_exec
  2. calls → 2 spawn_window
  3. calls → 3 spawn_pane
  4. calls → 4 window_add_pane
  5. calls → 5 window_pane_create

In other ports

task equivalence 16 other ports mapped

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

Create a session in each port
PortAPIDiffers from C#
C# LibTmux.Server.CreateSessionAsync
Creates a session.
This page
Python libtmux.Server.new_session
Create new session, returns new Session.
None recorded in the model
Ruby LibTmux::Server#new_session
Behavior: Creation.
2 overloads
Lua libtmux.Server:new_session None recorded in the model
Erlang tmux_session:create/2
Create a detached session by default and explicitly observe the returned row. Options include name, window_name, dimensions, cwd, env and launch. Performs I/O; an observation failure after successful creation retains mutation = completed and the original command result. Existing names are not adopted.
free function
TypeScript server.Server.newSession
Create a detached session and resolve it as a handle.
None recorded in the model
Rust server.Server.new_session
Create a detached session and return it.
None recorded in the model
Go tmux.Server.NewSession
NewSession creates a detached session, then returns a newly materialized Session. It never changes client focus. KillExisting is not rolled back; transport and context failures may be delivery-ambiguous.
None recorded in the model
Java io.github.libtmux.Server.newSession
Creates a detached session and returns that exact session.
3 overloads
Clojure libtmux.core/new-session!
Creates a detached session and returns a fresh captured session map.
free function
Kotlin io.github.libtmux.kotlin.Server.newSession
Creates a detached session and returns that exact session.
3 overloads
Scala io.github.libtmux.scaladsl.Server.newSession
Creates a detached session and returns that exact session.
3 overloads
C++ libtmux::Server::new_session
Created detached, and returned, because tmux prints what it made.
2 overloadsreadonly
Swift Server.newSession(named:startDirectory:windowName:width:height:environment:shell:)
Creates a detached session.
None recorded in the model
OCaml Libtmux_unix.Client.create_session
Create a detached session on the bound daemon. Name collisions fail.
free function
Perl LibTmux::Server::new_session
new_session(name => string, command => arrayref?, shell_command => string?, width => integer?, height => integer?, cwd => bytes?, environment => hashref?).
Explicit Server operation. Captured entities remain local observations; use a new snapshot to observe changes.
Raku LibTmux::Server.new-session
Create a detached session and return its value-only, identity-scoped reference.
None recorded in the model
No Haskell equivalent.

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

No equivalent is recorded in PowerShell, Julia, Elixir, Common Lisp or F#.

Esc
Search in

Type to search.

Reference previewOpen reference