
Security News
AGENTS.md Gains Traction as an Open Format for AI Coding Agents
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.
tty-events
Advanced tools
A package for handling terminal input (mouse, keyboard, clipboard and focus).
tty-events
is a package for handling events from the terminal, made for interactive, terminal-based applications.
node:readline
’s keypress
event;key == "Ctrl+s"
);unknownSequence
event.This script logs all key presses:
if (process.stdin.isTTY)
process.stdin.setRawMode(true);
const term = new (require("tty-events"));
term.on("keypress", (key)=>{
console.log("You pressed %s.", key.toString());
if (key == "Ctrl+c") {
term.pause(); // Exit the program
}
});
tty-events
supports mouse (VT200 and SGR extended). In order to receive mouse events, the enableMouse()
function must be called first.
term.enableMouse();
term.on("mousedown", (ev)=>{
console.log("You clicked at (%i, %i) with the button no. %i.", ev.x, ev.y, ev.button);
});
For a highlight tracking example, see the example highlight tracking script.
tty-events
supports bracketed paste mode. This feature allows to distinguish between real keystrokes and pasted text from the clipboard. This is useful in applications where certain keys trigger some command. In order to receive paste events, the enableBPM()
function must be called first.
term.enableBPM();
term.on("paste", (text)=>{
console.log("You pasted %O.", text);
});
Focus events allow an application to stop updating the screen when it's not necessary. In order to receive focus events, the enableFocus()
function must be called first.
term.enableFocus();
term.on("focusin", ()=>{
console.log("The terminal received focus.");
});
term.on("focusout", ()=>{
console.log("The terminal lost focus.");
});
Because of the way terminals work, there are some aspects that might seem unintuitive.
An uppercase letter emits an event with the uppercase letter and with the shift
property set to false
. This is because there is no way to know if Shift was being pressed (an uppercase letter can be produced with Caps Lock). For example: Shift+Alt+A emits Alt+A
instead of Alt+Shift+a
.
Some key combinations produce the same output to stdin
. Here is a list of the key combinations that may not work as expected:
Ctrl+<letter>
(in lowercase). (The Shift modifier is ignored.)backspace
. (Terminals send \b
when Ctrl+H is pressed.)tab
. (Terminals send \t
when Ctrl+I is pressed.)enter
. (Terminals send \n
when Ctrl+J is pressed.)enter
. (Terminals send \r
when Ctrl+M is pressed.)escape
. (Terminals send \x1B
when Ctrl+[ is pressed.)f11
in some terminals.f12
in some terminals.Listening for Esc (escape
) is discouraged. Terminals send \x1B
when Esc is pressed, which is the first byte of escape sequences, and this makes the detection unreliable.
Also, some features and/or key combinations don't work in some terminal emulators:
The full documentation is available here.
FAQs
A package for handling terminal input (mouse, keyboard, clipboard and focus).
We found that tty-events demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.
Security News
/Research
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.