Typing
await term.type("hello world");
await term.type("ls -la\n");
await term.type("slowly", { delay: 50 });\n presses Enter. Text is encoded the way the program asked for it: plain bytes normally, or key events when it turned on the kitty keyboard protocol.
Keys
await term.press("Enter");
await term.press("ctrl+c");
await term.press(["Down", "Down", "Enter"]);
await term.press("j", { count: 5 });Names: Enter, Tab, Escape, Backspace, Delete, Insert, Up, Down, Left, Right, Home, End, PageUp, PageDown, F1 to F24, space, and any single character. Modifiers: ctrl, shift, alt (or option), cmd (or super), combined like ctrl+shift+a.
Each key is sent as its own write, a few milliseconds apart, so programs read one key at a time like they would from a person. After a lone Escape the gap is 60ms, so programs don't mistake Escape followed by another key for an alt sequence.
Pasting
await term.paste("multi\nline\ntext");Uses bracketed paste when the program enabled it, so editors and shells treat it as one paste.
Mouse
Mouse positions are pixels in screenshot space: read a point off a screenshot and click it. Or address a cell with { col, row }.
await term.click({ x: 412, y: 230 });
await term.click({ col: 10, row: 4 });
await term.click({ col: 10, row: 4 }, { button: "right", modifiers: ["shift"] });
await term.dblclick({ col: 3, row: 2 });
await term.move({ x: 100, y: 50 });
await term.drag({ col: 2, row: 5 }, { col: 30, row: 5 });
await term.wheel(3);Programs only receive clicks when they turned on mouse reporting. click returns { sent } so you can tell, and screen().mouseTracking says whether reporting is on. When it is off, wheel scrolls the terminal's own history (or sends arrow keys in full screen apps), like a real terminal.
Clicking on text
getByText finds text on the screen and acts on it:
await term.getByText("Save").click();
await term.getByText(/deploy \w+/).hover();
await term.getByText("Delete").nth(1).click();Locators wait for the text to appear, and they're strict: if "Save" is on screen twice, click() fails and lists both places. Pick one with .first(), .last() or .nth(i). Add { exact: true } to match whole words only.
term.find(text) returns every match right now with cell and pixel positions, without waiting.
Other input
await term.resize(120, 40);
await term.signal("SIGINT");
await term.focus(false);
await term.scroll(-10);resize sends the program SIGWINCH. focus reports focus changes to programs that asked for them. scroll moves the terminal's own view into history and only changes what screenshots show.