Pane.wait_for_text
Source and package
- Qualified name
-
libtmux.Pane: wait _for _text - Module
- libtmux
- Declared in
- Pane
- Package
- libtmux
- Source
- lua/libtmux/_internal/entity.lua
- wait_for_text: fun( self: libtmux
.Pane , text: string, options?: libtmux.Wait , ):libtmuxText Options .Request <libtmux.Text >Wait -
Examples#
Wait for a command's output to appear on the visible screen. Use Lua 5.1 or newer with LuaRocks, tmux 3.3a or newer, and a C compiler and CMake for luv on Linux. In a new directory, install the library and its standalone runtime dependency from LuaRocks:
Terminal window $ luarocks --tree ./rocks install luv &&luarocks --tree ./rocks install libtmux &&eval "$(luarocks --tree ./rocks path)"Save this complete launcher as
run.sh. It starts a private tmux daemon and cleans up after success or failure. A failed daemon shutdown reports and retains its socket directory. View source#!/bin/shset -euprogram=${1:?Pass the complete Lua example filename}binary=$(command -v "${TMUX_BIN:-tmux}")case "$binary" in/*) ;;*) printf '%s\n' 'tmux must resolve to an absolute path' >&2; exit 1 ;;esacdirectory=$(mktemp -d "${TMPDIR:-/tmp}/libtmux-lua-api.XXXXXX")socket="$directory/tmux.sock"cleanup() {status=$?trap - 0 HUP INT TERMif [ -S "$socket" ] && ! "$binary" -S "$socket" kill-server; thenprintf 'Cannot stop tmux; kept %s\n' "$directory" >&2exit 1firm -rf "$directory" || exit 1exit "$status"}trap cleanup 0trap 'exit 1' HUP INT TERMunset TMUX TMUX_PANEexport TMUX_BIN="$binary" TMUX_SOCKET="$socket" ENV=/dev/null BASH_ENV=/dev/null"$binary" -S "$socket" -f /dev/null new-session -d -s bootstrap -n bootstrap /bin/cat"${LUA_BIN:-lua}" "$program""$binary" -S "$socket" has-session -t '=bootstrap'Save the complete program as
wait_for_text.lua. Closing the library connection leaves the daemon running; the launcher owns its lifetime. View sourcelocal adapter = require("libtmux.runtime.luv")local function must(value, err)if err ~= nil thenerror(tostring(err), 0)endreturn valueendlocal binary = assert(os.getenv("TMUX_BIN"), "set TMUX_BIN to an absolute tmux executable")local socket = assert(os.getenv("TMUX_SOCKET"), "set TMUX_SOCKET to the private socket")must(adapter.run(function(runtime)local server = must(runtime:connect({ binary = binary, socket_path = socket }):await())local created = must(server:new_session({ name = "demo", argv = { "/bin/sh" } }):await())local pane = created.pane-- The shell echoes what is typed, so print the needle from two pieces.must(pane:send_text("printf '%s%s\\n' 'lua wait ' 'ready'"):await())must(pane:send_keys({ "Enter" }):await())local found = must(pane:wait_for_text("lua wait ready", { timeout = 5000 }):await())assert(found.text:find("lua wait ready", 1, true))print("lua wait ready")must(server:close():await())return trueend))Run the saved files. Assertions and operation errors produce a failing exit status:
Terminal window $ eval "$(luarocks --tree ./rocks path)" &&sh run.sh wait_for_text.lua
Guides#
Pages that discuss wait_for_text.