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

property libtmux-dotnet

CapturedRelation.IsCaptured

Gets whether the snapshot read this relation.

Source and package
Qualified name
LibTmux.CapturedRelation.IsCaptured
Namespace
LibTmux
Declared in
CapturedRelation
Package
LibTmux
Source
src/LibTmux/Snapshots/CapturedRelation.cs
IsCaptured : bool

Examples

Capture a new immutable hierarchy, check optional pane state, and distinguish an empty captured relation from one that has not been read. 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,
};
await using OwnedServerScope owned = await Server.CreateOwnedAsync(options, token);
Server server;
await using (OwnedSessionScope session = await owned.Value.CreateOwnedSessionAsync(
new NewSessionRequest { Name = "demo", Command = "/bin/cat" }, token))
{
server = await Server.ConnectAsync(options, token);
if (server.Sessions.IsCaptured)
{
throw new InvalidOperationException("Connecting must not capture the hierarchy.");
}
Console.WriteLine("Sessions have not been captured.");
Server captured = await server.CaptureSnapshotAsync(SnapshotDepth.Panes, token);
if (!captured.Sessions.IsCaptured)
{
throw new InvalidOperationException("The requested sessions were not captured.");
}
Session capturedSession = captured.Sessions.Single();
if (!capturedSession.ActivePane.IsCaptured)
{
throw new InvalidOperationException("The active pane was not captured.");
}
Pane pane = capturedSession.ActivePane.Value;
if (pane.CurrentPath is null || pane.CurrentCommand is null)
{
throw new InvalidOperationException("The running pane should report its path and command.");
}
Console.WriteLine("The captured active pane has a path and command.");
if (server.Sessions.IsCaptured)
{
throw new InvalidOperationException("Capturing must return a new immutable handle.");
}
Console.WriteLine("The original handle is still uncaptured.");
// Keep this private daemon alive after its only owned session is disposed.
TmuxCommandResult result = await server.ExecuteCommandAsync(
["set-option", "-s", "exit-empty", "off"], token);
if (result.ExitCode != 0)
{
throw new InvalidOperationException("Could not keep the empty server alive.");
}
}
Server empty = await server.CaptureSnapshotAsync(SnapshotDepth.Sessions, token);
if (!empty.Sessions.IsCaptured || empty.Sessions.Count != 0)
{
throw new InvalidOperationException("An empty captured relation differs from an uncaptured relation.");
}
Console.WriteLine("Captured sessions can be empty.");
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:

Sessions have not been captured.
The captured active pane has a path and command.
The original handle is still uncaptured.
Captured sessions can be empty.

Guides

task material

Pages that discuss IsCaptured.

Esc
Search in

Type to search.

Reference previewOpen reference