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

Window.FindPaneAsync

Reads one pane in this window.

Source and package
Qualified name
LibTmux.Window.FindPaneAsync
Namespace
LibTmux
Declared in
Window
Package
LibTmux
Source
src/LibTmux/Window.Panes.cs
Parameters
Returns

The pane, or null when this window has no such pane.

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.Window.FindPaneAsync.

tmux command

task material

The tmux commands behind FindPaneAsync.

tmux C API

task material

The C declarations in tmux that implement these commands.

Esc
Search in

Type to search.

Reference previewOpen reference