Pane.CaptureAsync
Reads the pane's contents.
Source and package
- Qualified name
-
LibTmux .Pane. Capture Async - Namespace
- LibTmux
- Declared in
Pane- Package
- LibTmux
- Source
- src/LibTmux/Pane.Capture.cs
- async Task<IRead
Only <string>> CaptureAsync( CaptureList Pane ? request = null, CancellationRequest Token cancellationToken = default ) -
- Parameters
-
-
request(CapturePane ?) – What to capture.Request Default
null -
cancellationToken(CancellationToken ) – Cancels the tmux command.Default
default
-
- 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 ofLibTmuxon NuGet: View sourceExample.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 usingdisposes 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 sourceProgram.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.dllExpected program output from each framework:
api capture ready
Recorded calls
source callsThe 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 materialThe tmux commands behind CaptureAsync.
tmux C API
task materialThe C declarations in tmux that implement these commands.
Guides
task materialPages that discuss CaptureAsync.
In other ports
task equivalence 17 other ports mappedSource-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.
| Port | API | Differs from C# |
|---|---|---|
| C# | Lib Reads the pane's contents. | This page |
| Python | libtmux Capture text from pane. | 3 overloads |
| Ruby | Lib Behavior: Pane input and capture. | None recorded in the model |
| Lua | libtmux | None recorded in the model |
| Erlang | tmux 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 Capture this pane's contents as lines. | None recorded in the model |
| Rust | pane Capture the pane's visible contents, one entry per line. | None recorded in the model |
| Go | tmux 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 This pane's visible content, one element per line. | 3 overloads |
| Clojure | libtmux Captures pane lines; :from :history includes scrollback. | free function2 overloads |
| Kotlin | io This pane's visible content, one element per line. | 2 overloads |
| Scala | io This pane's visible content, one element per line. | 3 overloads |
| F# | Lib Captures pane contents using the supplied core request. | free function |
| C++ | libtmux:: The visible contents, as tmux printed them. | 2 overloadsreadonly |
| Swift | Server 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 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 | Lib 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 | Lib Acquire screen/history bytes with explicit bounds and whitespace options. | on PaneRef |
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.