Sessions and backends
Every interaction in tui-test runs inside a terminal session backed by a real PTY and a terminal emulator grid. Creating a client or Session object does not spawn a child process on its own; call open or run to start one.
Shell sessions vs. direct launches
Section titled “Shell sessions vs. direct launches”Choose open when you want an interactive shell, prompt detection, and command tracking (submit, waitCommand, getOutput, getExitCode, getCwd). Choose run when testing an application directly without shell quoting or profile startup scripts.
// Shell sessionawait terminal.open({ shell: "bash", cols: 100, rows: 30, cwd: "." });await terminal.submit("echo ready");await terminal.waitCommand();await terminal.close();
// Direct application launchawait terminal.run("my-app", ["--port", "8080"], { env: { NO_COLOR: "0" },});await terminal.waitExit();# Shell sessionawait terminal.open(shell="bash", cols=100, rows=30, cwd=".")await terminal.submit("echo ready")await terminal.wait_command()await terminal.close()
# Direct application launchawait terminal.run("my-app", "--port", "8080", env={"NO_COLOR": "0"})await terminal.wait_exit()use tui_test::shell::Shell;use tui_test::{Backend, OpenOptions, Operation, RunOptions};
terminal.open(OpenOptions { shell: Some(Shell::Bash), cols: 100, rows: 30, cwd: Some(".".into()), ..Default::default()})?;terminal.execute(Operation::Submit { data: Some("echo ready".into()),})?;terminal.execute(Operation::WaitCommand { timeout_ms: None })?;terminal.close()?;
terminal.run(RunOptions { program: "my-app".into(), args: vec!["--port".into(), "8080".into()], backend: Backend::Alacritty, profile: Default::default(), cols: 80, rows: 30, cwd: None, env: vec![("NO_COLOR".into(), "0".into())], wait_ready: None, restart: false, timeouts: Default::default(), recording: Default::default(), style: Default::default(),})?;terminal.execute(Operation::WaitExit { timeout_ms: None })?;_, err := terminal.Open(tuitest.OpenOptions{ Shell: tuitest.Bash, SpawnOptions: tuitest.SpawnOptions{ Cols: tuitest.Ptr(uint16(100)), Rows: tuitest.Ptr(uint16(30)), Cwd: ".", },})if err != nil { t.Fatal(err)}if err := terminal.Submit(tuitest.Ptr("echo ready")); err != nil { t.Fatal(err)}if err := terminal.WaitCommand(tuitest.WaitOptions{}); err != nil { t.Fatal(err)}if err := terminal.Close(); err != nil { t.Fatal(err)}
_, err = terminal.Run("my-app", []string{"--port", "8080"}, tuitest.SpawnOptions{ Env: map[string]string{"NO_COLOR": "0"},})if err != nil { t.Fatal(err)}if err := terminal.WaitExit(tuitest.WaitOptions{}); err != nil { t.Fatal(err)}tui-test --session shell open --shell bash --cols 100 --rows 30 --cwd .tui-test --session shell submit "echo ready"tui-test --session shell wait commandtui-test --session shell close
tui-test --session app run --env NO_COLOR=0 my-app --port 8080tui-test --session app wait exittui-test --session app closeThe default terminal size is 80 columns by 30 rows. Supported shells for open are bash, zsh, fish, powershell, pwsh, cmd, xonsh, elvish, and nushell. Shell integration injects prompt and command markers so wait ready and wait command observe real shell boundaries; pass waitReady: false (--no-wait-ready) to skip initial prompt waiting.
Session names and isolation
Section titled “Session names and isolation”CLI commands resolve the target session from --session NAME, then TUI_TEST_SESSION, and finally default. Each named CLI session runs in a per-session background daemon so separate shell invocations can drive the same terminal.
JavaScript, Python, and Go clients use the same fallback order when a session name is omitted, but keep sessions inside the current process rather than sharing them with CLI daemons. Multiple client instances with the same name in one process share the underlying session. For isolated tests, generate a unique name with TuiTest.ephemeral(), tuitest.Ephemeral(), or the language test helpers.
Reuse, restart, and interrupt
Section titled “Reuse, restart, and interrupt”Calling open or run on an already active session reuses it unless restart: true (--restart) is passed.
restart replays the last successful open or run with its original working directory, launch options, resolved render style, and current grid dimensions. It sends Ctrl+C first and waits up to the graceful timeout (5000 ms by default; pass 0 to force immediate replacement) before starting a fresh terminal and automatic recording.
interrupt cancels in-flight waits immediately without waiting in the operation queue and terminates the child process while keeping the session and last terminal screen available for inspection. Unlike key press Ctrl+C or signal INT, interrupt stops the child at the process level; call restart afterward to spawn again or close to release the session. Use sessions (tui-test sessions, sessions(), Sessions()) to list open sessions.
await terminal.restart({ gracefulTimeout: 1000 });await terminal.interrupt();await terminal.close();await terminal.restart(graceful_timeout=1000)await terminal.interrupt()await terminal.close()use tui_test::Operation;
terminal.execute(Operation::Restart { graceful_timeout_ms: Some(1000),})?;terminal.interrupt();terminal.close()?;timeout := time.Secondif _, err := terminal.Restart(tuitest.RestartOptions{GracefulTimeout: &timeout}); err != nil { t.Fatal(err)}if err := terminal.Interrupt(); err != nil { t.Fatal(err)}if err := terminal.Close(); err != nil { t.Fatal(err)}tui-test restart --graceful-timeout 1000tui-test interrupttui-test closeTerminal backends and PTY host
Section titled “Terminal backends and PTY host”tui-test supports four terminal emulator backends behind the same session, locator, and capture APIs:
| Backend | Option value | Notes |
|---|---|---|
| Alacritty | "alacritty" |
Default backend on all surfaces; always compiled into tui-test-rs. |
| Ghostty | "ghostty" |
Native Ghostty VT engine (ghostty Cargo feature in Rust). |
| Rio | "rio" |
Rio Sugarloaf/Copa terminal parser (rio Cargo feature in Rust). |
| xterm.js | "xtermjs" |
Embedded headless xterm.js + Unicode 11 width tables (xtermjs Cargo feature in Rust); requires no external Node.js install. |
Prebuilt CLI binaries and Go, Python, and JavaScript packages include all four backends. In Rust, enable optional backends on tui-test-rs:
cargo add tui-test-rs --features ghostty,rio,xtermjsOn Windows, tui-test bundles Microsoft’s ConPTY (OpenConsole.exe and conpty.dll) and initializes it lazily when the first PTY opens, giving consistent terminal behavior across Windows hosts without depending on the OS console build. Run tui-test --version to inspect the active backend and ConPTY versions.
Terminal emulators can still differ on edge cases: for example, xterm.js records a cell’s underline color only when the cell also carries an underline style, and Alacritty and Rio require CSI ?1049h rather than legacy CSI ?47h to enter the alternate screen. Run your suite against each backend your users rely on when escape-sequence fidelity matters.