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

Pane.CaptureAsync

Reads the pane's contents.

Source and package
Qualified name
LibTmux.Pane.CaptureAsync
Namespace
LibTmux
Declared in
Pane
Package
LibTmux
Source
src/LibTmux/Pane.Capture.cs
Parameters
Returns

The captured lines.

Examples

Send literal text and a named Enter key, wait for the line the command prints, then require it in the captured pane. All scopes are disposed after errors or cancellation. 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.Text.RegularExpressions;
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);
await using OwnedSessionScope session = await owned.Value.CreateOwnedSessionAsync(
new NewSessionRequest
{
Name = "demo",
Command = "env PS1='ready> ' /bin/sh",
},
token);
Server server = await Server.ConnectAsync(options, token);
Pane pane = (await server.GetPanesAsync(token)).Single();
// The shell has to be reading before anything is typed, or its prompt lands in front of the output.
// PS1 rides on the command because a non-interactive bash default-shell drops it from the environment.
PaneWaitResult prompt = await pane.WaitForTextAsync(
PaneWaitRequest.FromTextPatterns(["ready>"], simpleMatch: true)
with
{ Timeout = TimeSpan.FromSeconds(5) },
token);
if (prompt.Outcome is not (PaneWaitOutcome.Matched or PaneWaitOutcome.PresentAtEntry))
{
throw new InvalidOperationException($"The shell never showed its prompt: {prompt.Outcome}.");
}
const string marker = "api capture ready";
await pane.SendKeysAsync(
new SendKeysRequest { Text = $"printf '%s\\n' '{marker}'", Literal = true, Enter = false }, token);
await pane.SendKeysAsync(new SendKeysRequest { Text = "Enter", Enter = false }, token);
// The echoed command contains the marker, so only a whole line counts as the output.
PaneWaitResult printed = await pane.WaitForTextAsync(
new PaneWaitRequest
{
Patterns = [new Regex($"^{Regex.Escape(marker)}$", RegexOptions.CultureInvariant)],
Timeout = TimeSpan.FromSeconds(5),
},
token);
if (printed.Outcome is not (PaneWaitOutcome.Matched or PaneWaitOutcome.PresentAtEntry))
{
throw new InvalidOperationException($"The pane never printed the marker: {printed.Outcome}.");
}
IReadOnlyList<string> lines = await pane.CaptureAsync(
new CapturePaneRequest { JoinWrappedLines = true }, token);
// Joining wrapped lines preserves terminal padding after the output.
if (!lines.Any(line => string.Equals(line.TrimEnd(), marker, StringComparison.Ordinal)))
{
throw new InvalidOperationException("Capture did not contain the complete output line.");
}
Console.WriteLine(marker);
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:

api capture ready

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.Pane.CaptureAsync.

tmux command

task material

The tmux commands behind CaptureAsync.

tmux C API

task material

The C declarations in tmux that implement these commands.

Guides

task material

Pages that discuss CaptureAsync.

In other ports

task equivalence 17 other ports mapped

Source-verified mappings for Read a pane’s visible contents. A mapping says these APIs perform the same task. It does not say they share defaults, errors or completion: check each page.

Read a pane’s visible contents in each port
PortAPIDiffers from C#
C# LibTmux.Pane.CaptureAsync
Reads the pane's contents.
This page
Python libtmux.Pane.capture_pane
Capture text from pane.
3 overloads
Ruby LibTmux::Pane#capture
Behavior: Pane input and capture.
None recorded in the model
Lua libtmux.Pane:capture None recorded in the model
Erlang tmux_pane:capture/2
Capture terminal bytes, preserving final newlines. Options select line range, joined wraps, escapes, alternate screen and padding; defaults follow tmux current-screen capture. Performs I/O and returns an explicit output-limit error instead of silently truncating.
free function
TypeScript pane.Pane.capture
Capture this pane's contents as lines.
None recorded in the model
Rust pane.Pane.capture
Capture the pane's visible contents, one entry per line.
None recorded in the model
Go tmux.Pane.Capture
Capture captures printed content from the receiver's exact linked pane. It returns a caller-owned slice. Completed stderr becomes a CommandError; any stdout tmux still printed is returned alongside it. A nonzero exit with empty stderr is not an error, as for every command (see the package documentation), and its stdout is returned.
None recorded in the model
Java io.github.libtmux.Pane.capture
This pane's visible content, one element per line.
3 overloads
Clojure libtmux.core/capture!
Captures pane lines; :from :history includes scrollback.
free function2 overloads
Kotlin io.github.libtmux.kotlin.Pane.capture
This pane's visible content, one element per line.
2 overloads
Scala io.github.libtmux.scaladsl.Pane.capture
This pane's visible content, one element per line.
3 overloads
F# LibTmux.FSharp.Pane.capture
Captures pane contents using the supplied core request.
free function
C++ libtmux::Pane::capture
The visible contents, as tmux printed them.
2 overloadsreadonly
Swift Server.capture(_:includingHistory:)
The pane's visible contents, one line per row. The source read is capped at 1 MiB; use incremental capture for a large scrollback instead of collecting its entire history.
on Server
OCaml Libtmux_unix.Client.capture_text
Capture ordinary rendered screen rows, inclusively, via an owned paste buffer and private file. Reject applicable capture/save hooks. The scratch directory defaults to /tmp and must be local storage shared with the daemon. Pending and alternate-screen byte modes are unsupported. This observes an interval and establishes no stream continuity barrier.
free function
Perl LibTmux::Server::capture_pane
capture_pane(pane => Pane|pane_id, start => integer?, end => integer?).
on Server
Explicit Server operation. Captured entities remain local observations; use a new snapshot to observe changes.
Raku LibTmux::Model::PaneRef.capture
Acquire screen/history bytes with explicit bounds and whitespace options.
on PaneRef
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 or Common Lisp.

Esc
Search in

Type to search.

Reference previewOpen reference