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. capture: cancellationToken : CancellationToken -> request: CapturePane -> pane: LibRequest Tmux -> Task<IRead.Pane Only <string>>List -
- Parameters
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 ofLibTmux.FSharpon NuGet: View sourceExample.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 withLibTmux.Server.CreateOwnedAsync;use!disposes owned scopes after success, cancellation or failure. The F# facade has no separate server constructor. View sourceProgram.fsComplete program open Systemopen System.IOopen System.Text.RegularExpressionsopen System.Threadingopen LibTmuxopen LibTmux.FSharplet runAsync () =task {use deadline = new CancellationTokenSource(TimeSpan.FromSeconds 10.)let token = deadline.Tokenlet socketRoot = Directory.CreateTempSubdirectory "libtmux-example-"use _cleanup ={ new IDisposable withmember _.Dispose() = socketRoot.Delete true}let options =ServerConnectionOptions(SocketPath = Path.Combine(socketRoot.FullName, "tmux.sock"),ConfigurationFile = "/dev/null")use! owned = options |> Server.createOwned tokenuse! _session =owned.Value.CreateOwnedSessionAsync(NewSessionRequest(Name = "demo", Command = "/bin/sh"), token)let server = owned.Valuelet! panes = server |> Server.panes |> Query.list tokenlet pane = panes |> Seq.exactlyOnelet 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 requestprintfn "The pane printed the marker: %b" printed.Foundlet! 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.dllExpected program output from each framework:
The pane printed the marker: trueCaptured line: api capture readyType 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 ofLibTmux.FSharpon NuGet: View sourceExample.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 withLibTmux.Server.CreateOwnedAsync;use!disposes owned scopes after success, cancellation or failure. The F# facade has no separate server constructor. View sourceProgram.fsComplete program // fsharp-snippet: SendWaitReadopen Systemopen System.IOopen System.Threadingopen LibTmuxopen LibTmux.FSharplet runAsync () =task {use deadline = new CancellationTokenSource(TimeSpan.FromSeconds 20.)let token = deadline.Tokenlet socketRoot = Directory.CreateTempSubdirectory "libtmux-example-"use _cleanup ={ new IDisposable withmember _.Dispose() = socketRoot.Delete true}let options =ServerConnectionOptions(SocketPath = Path.Combine(socketRoot.FullName, "tmux.sock"),ConfigurationFile = "/dev/null")use! owned = options |> Server.createOwned tokenlet! 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-snippetBuild 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.dllExpected program output from each framework:
ready: foundcounted: foundrun: exit 4, output ["a"; "b"]screen shows the run: true
Recorded calls
source callsThe 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 materialThe tmux commands behind capture.
tmux C API
task materialThe C declarations in tmux that implement these commands.
Guides
task materialPages that discuss capture.
- Examples
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 F# |
|---|---|---|
| F# | Lib Captures pane contents using the supplied core request. | 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. | None recorded in the model |
| 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. | async |
| 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. | 2 overloads |
| Kotlin | io This pane's visible content, one element per line. | async2 overloads |
| Scala | io This pane's visible content, one element per line. | 3 overloads |
| C# | Lib Reads the pane's contents. | async |
| 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. | async |
| 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. | None recorded in the model |
| Perl | Lib 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 | Lib Acquire screen/history bytes with explicit bounds and whitespace options. | None recorded in the model |
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.