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.sendAndWait

Types a line, presses Enter, and waits for a later line to contain the text.

Source and package
Qualified name
LibTmux.FSharp.Pane.sendAndWait
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 sendAndWait: cancellationToken: CancellationToken -> timeout: TimeSpan -> line: string -> text: string -> pane: LibTmux.Pane -> Task<PaneWaitResult>

Description

The screen before the line is typed never ends the wait, and the shell's echo of the line is discounted: waiting for done after typing echo done waits for the command's output. Prefer this to sendKeys followed by waitForText, which can match the typed line itself. Running out of time returns the outcome TimedOut; only Mirror.waitUntil raises instead.

Parameters
Errors

Examples

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

Same owner

containment 1 of 23 shown

Other members of LibTmux.FSharp.Pane whose names share sendAndWait. They sit on the same type; that does not make them behave alike.

All 23 members of Pane

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.sendAndWait.

tmux command

task material

The tmux commands behind sendAndWait.

tmux C API

task material

The C declarations in tmux that implement these commands.

Guides

task material

Pages that discuss sendAndWait.

Esc
Search in

Type to search.

Reference previewOpen reference