Skip to content

Keyboard, mouse, and signals

tui-test encodes keyboard, paste, and mouse events according to the terminal modes negotiated by the running application, including bracketed paste, SGR mouse reporting, and the Kitty keyboard protocol.

  • type sends printable text without pressing Enter.
  • write writes raw bytes directly to the PTY input stream (including escape sequences).
  • submit types optional text and presses Enter. In a shell session opened with open, pair submit with waitCommand so command output and exit status are captured cleanly.
await terminal.type("search query");
await terminal.write("\x1b");
await terminal.submit("ls -la");
await terminal.waitCommand();

Named keys, modifiers, and key transitions

Section titled “Named keys, modifiers, and key transitions”

Named keys include Up, Down, Left, Right, Home, End, PageUp, PageDown, Insert, Delete, Backspace, Tab, Enter, Space, Escape, and F1 through F12. Combine modifiers (Ctrl, Alt, Shift, Super, Meta, Hyper) with +, such as Ctrl+Shift+P or Alt+Enter.

Use press for standard keystrokes, or down, repeat, and up when testing apps that enable Kitty key-event transitions.

await terminal.press("Ctrl+P");
await terminal.keyboard.press("Down", "Down", "Enter");
await terminal.keyboard.down("Shift");
await terminal.keyboard.press("Tab");
await terminal.keyboard.up("Shift");

Prefer locator.click() (tui-test click text) when clicking UI controls so the target resolves dynamically. When testing canvas regions, splitters, or hover states directly, use zero-based cell coordinates (x, y) on mouse:

  • Button actions (click, down, up, drag) accept button ("left", "middle", "right"), modifier flags (alt, ctrl, shift), and clicks (for double or triple clicks on click).
  • mouse.scroll("up" | "down") sends mouse wheel events to the running application. It does not move tui-test’s own scrollback viewport; see terminal state and scrollback for native history scrolling.
  • Mouse input requires the viewport to be at the live screen (offset == 0). If you scrolled into history, return to live output with scrollToBottom() first.
await terminal.getByText("Confirm").click({ button: "left", clicks: 2 });
await terminal.mouse.move(12, 4);
await terminal.mouse.drag(10, 5, 30, 5);
await terminal.mouse.scroll("down", { amount: 5 });

resize(cols, rows) resizes both the PTY (delivering SIGWINCH on Unix or ConPTY resize notifications on Windows) and the terminal emulator grid.

signal accepts "INT", "TERM", "KILL", or "QUIT". "INT" writes the terminal interrupt character (equivalent to Ctrl+C), while "TERM", "KILL", and "QUIT" terminate the child process through the platform process API (kill is an alias for signal KILL).

await terminal.resize(120, 40);
await terminal.signal("INT");
await terminal.kill();