Core Library0.xAPI reference

Choose documentation 1

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

function libtmux-fsharp

Pane.capture

Captures pane contents using the supplied core request.

Source and package
Qualified name
LibTmux.FSharp.Pane.capture
Namespace
LibTmux.FSharp
Declared in
Pane
Package
LibTmux.FSharp
Source
src/LibTmux.FSharp/Hierarchy.fsi
F# value signaturesDeclares the name and type of a value or function in a signature.Language documentation capture: cancellationToken: CancellationToken -> request: CapturePaneRequest -> pane: LibTmux.Pane -> Task<IReadOnlyList<string>>

Examples

Type a shell command literally, press the named Enter key, and wait for the line it prints before capturing output. Timeout and command failures escape the program after scoped cleanup; cancellation does not undo dispatched input. 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.fsproj. It references the 0.1.1 release of LibTmux.FSharp on NuGet: View source

Example.fsproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net8.0;net10.0</TargetFrameworks>
<LangVersion>10.0</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference>
<DisableImplicitLibraryPacksFolder>true</DisableImplicitLibraryPacksFolder>
</PropertyGroup>
<ItemGroup>
<Compile Include="Program.fs" />
<PackageReference Include="FSharp.Core" Version="[10.1.303]" />
<PackageReference Include="LibTmux.FSharp" Version="[0.1.1]" />
</ItemGroup>
</Project>

Save this complete program as Program.fs. It creates a private server with LibTmux.Server.CreateOwnedAsync; use! disposes owned scopes after success, cancellation or failure. The F# facade has no separate server constructor. View source

Program.fsComplete program
open System
open System.IO
open System.Text.RegularExpressions
open System.Threading
open LibTmux
open LibTmux.FSharp
let runAsync () =
task {
use deadline = new CancellationTokenSource(TimeSpan.FromSeconds 10.)
let token = deadline.Token
let socketRoot = Directory.CreateTempSubdirectory "libtmux-example-"
use _cleanup =
{ new IDisposable with
member _.Dispose() = socketRoot.Delete true
}
let options =
ServerConnectionOptions(
SocketPath = Path.Combine(socketRoot.FullName, "tmux.sock"),
ConfigurationFile = "/dev/null"
)
use! owned = options |> Server.createOwned token
use! _session =
owned.Value.CreateOwnedSessionAsync(NewSessionRequest(Name = "demo", Command = "/bin/sh"), token)
let server = owned.Value
let! panes = server |> Server.panes |> Query.list token
let pane = panes |> Seq.exactlyOne
let marker = "api capture ready"
do! pane |> Pane.sendText token (sprintf "printf '%%s\\n' '%s'" marker)
do! pane |> Pane.pressKey token "Enter"
// The echoed command contains the marker, so only a whole line counts as the output.
let request =
PaneWaitRequest(
Patterns = [ Regex($"^{Regex.Escape marker}$", RegexOptions.CultureInvariant) ],
Timeout = TimeSpan.FromSeconds 5.
)
let! printed = pane |> Pane.waitFor token request
printfn "The pane printed the marker: %b" printed.Found
let! lines = pane |> Pane.capture token (CapturePaneRequest(JoinWrappedLines = true))
// Joining wrapped lines keeps the terminal's padding after the output.
match lines |> Seq.map (fun line -> line.TrimEnd()) |> Seq.tryFind ((=) marker) with
| Some line -> printfn "Captured line: %s" line
| None -> printfn "Captured line: none"
}
runAsync().GetAwaiter().GetResult()

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.fsproj --configuration Release && \
dotnet bin/Release/net8.0/Example.dll && \
dotnet bin/Release/net10.0/Example.dll

Expected program output from each framework:

The pane printed the marker: true
Captured line: api capture ready

Type a line and wait for what it prints, not for its echo. Wait for a condition over the whole screen, then run a command and read its exit status and output. 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.fsproj. It references the 0.1.1 release of LibTmux.FSharp on NuGet: View source

Example.fsproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net8.0;net10.0</TargetFrameworks>
<LangVersion>10.0</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference>
<DisableImplicitLibraryPacksFolder>true</DisableImplicitLibraryPacksFolder>
</PropertyGroup>
<ItemGroup>
<Compile Include="Program.fs" />
<PackageReference Include="FSharp.Core" Version="[10.1.303]" />
<PackageReference Include="LibTmux.FSharp" Version="[0.1.1]" />
</ItemGroup>
</Project>

Save this complete program as Program.fs. It creates a private server with LibTmux.Server.CreateOwnedAsync; use! disposes owned scopes after success, cancellation or failure. The F# facade has no separate server constructor. View source

Program.fsComplete program
// fsharp-snippet: SendWaitRead
open System
open System.IO
open System.Threading
open LibTmux
open LibTmux.FSharp
let runAsync () =
task {
use deadline = new CancellationTokenSource(TimeSpan.FromSeconds 20.)
let token = deadline.Token
let socketRoot = Directory.CreateTempSubdirectory "libtmux-example-"
use _cleanup =
{ new IDisposable with
member _.Dispose() = socketRoot.Delete true
}
let options =
ServerConnectionOptions(
SocketPath = Path.Combine(socketRoot.FullName, "tmux.sock"),
ConfigurationFile = "/dev/null"
)
use! owned = options |> Server.createOwned token
let! session =
owned.Value |> Server.newSession token (SessionSpec.running "work" "/bin/sh")
let! pane = session |> Session.activePane token
// Type a line and wait for what it prints. The screen before it and
// the line's own echo do not count.
let! ready =
pane
|> Pane.sendAndWait token (TimeSpan.FromSeconds 5.) "echo server ready" "server ready"
// A condition sees every visible row each time the pane changes.
do! pane |> Pane.sendLine token "seq 3"
let! counted =
pane
|> Pane.waitUntil token (TimeSpan.FromSeconds 5.) (fun rows -> rows |> Seq.exists ((=) "3"))
// Running a command waits for its exit status and returns its output.
let! listing =
pane |> Pane.run token (TimeSpan.FromSeconds 10.) "printf 'a\\nb\\n'; exit 4"
let! screen = pane |> Pane.capture token (CapturePaneRequest())
// One case for each way a wait can end; leaving one out draws a warning.
let describe wait =
match wait with
| PaneWait.Found -> "found"
| PaneWait.Printed -> "printed"
| PaneWait.Stopped pattern -> "stopped by " + pattern
| PaneWait.TimedOut -> "timed out"
| PaneWait.Ended -> "the pane's program ended"
printfn "ready: %s" (describe ready)
printfn "counted: %s" (describe counted)
match listing with
| PaneRun.Exited status -> printfn "run: exit %d, output %A" status (List.ofSeq listing.Output)
| PaneRun.Ended -> printfn "run: the shell exited first"
| PaneRun.NotStarted -> printfn "run: the shell was not at a prompt"
| PaneRun.TimedOut -> printfn "run: still running"
printfn "screen shows the run: %b" (screen |> Seq.exists (fun row -> row = "a"))
}
runAsync().GetAwaiter().GetResult()
// endfsharp-snippet

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.fsproj --configuration Release && \
dotnet bin/Release/net8.0/Example.dll && \
dotnet bin/Release/net10.0/Example.dll

Expected program output from each framework:

ready: found
counted: found
run: exit 4, output ["a"; "b"]
screen shows the run: true

Recorded calls

source calls
No call edges in the F# model.

The F# 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.FSharp.Pane.capture.

tmux command

task material

The tmux commands behind capture.

tmux C API

task material

The C declarations in tmux that implement these commands.

Guides

task material

Pages that discuss capture.

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 F#
F# LibTmux.FSharp.Pane.capture
Captures pane contents using the supplied core request.
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.
None recorded in the model
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.
async
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.
2 overloads
Kotlin io.github.libtmux.kotlin.Pane.capture
This pane's visible content, one element per line.
async2 overloads
Scala io.github.libtmux.scaladsl.Pane.capture
This pane's visible content, one element per line.
3 overloads
C# LibTmux.Pane.CaptureAsync
Reads the pane's contents.
async
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.
async
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.
None recorded in the model
Perl LibTmux::Server::capture_pane
capture_pane(pane => Pane|pane_id, start => integer?, end => integer?).
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.
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 or Common Lisp.

Esc
Search in

Type to search.

Reference previewOpen reference