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. send And Wait - 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. sendAndWait: cancellationToken : CancellationToken -> timeout: TimeSpan -> line: string -> text: string -> pane: LibTmux -> Task<Pane.Pane Wait >Result -
Description
The screen before the line is typed never ends the wait, and the shell's echo of the line is discounted: waiting for
doneafter typingecho donewaits for the command's output. Prefer this tosendKeysfollowed bywaitForText, which can match the typed line itself. Running out of time returns the outcomeTimedOut; onlyMirror.waitUntilraises instead.- Parameters
-
-
timeout(TimeSpan)
- Errors
-
-
System
.Argument – The text is empty or spans lines.Exception -
Lib
Tmux – The pane's program had already exited, or the pane changed during every read until the timeout, so nothing was sent..Tmux Pane Exception -
Lib
Tmux – tmux no longer has the pane..Tmux Object Not Found Exception
-
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 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
Same owner
containment 1 of 23 shownOther members of LibTmux.FSharp.Pane whose names share sendAndWait. They sit on the same type; that does not make them behave alike.
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.sendAndWait.
tmux command
task materialThe tmux commands behind sendAndWait.
tmux C API
task materialThe C declarations in tmux that implement these commands.
Guides
task materialPages that discuss sendAndWait.
- Topics