npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

term-keymap

v0.2.5

Published

Parse stdin buffers into readable data and assign keymaps.

Downloads

973

Readme

term-keymap

Parses raw keyboard and mouse stdin buffers in Node and returns structured data. Provides a flexible keymap API with support for dynamically assigning and removing keymaps at runtime.

Supports a wide range of key combinations, mouse actions, and full compatibility with the Kitty Keyboard Protocol

Key features:

  • Comprehensive Key Combination: Parses ctrl and alt combinations by default.
  • Kitty Keyboard Protocol Support: Enables extended combinations if supported by the terminal (e.g. ctrl + uppercase characters, super, meta, volume keys).
  • Dynamic Keymap API: Subscribe/unsubscribe individual keymaps at runtime. Supports sequences, leader/prefix keys, optional callbacks and names.
  • Mouse Support: movement, buttons, scroll, drag, release.
  • Vim-style Keymap Strings: "<C-a><Tab>foo" notation or structured token objects.
  • Raw Stdin Buffer Parser: Bypass the keymap API and directly use the parsed buffer data if desired.

Documentation & Resources

Example Setups

Quickstart

Matching stateful stdin with keymaps

import { configureStdin, key, KeyMapState } from "term-keymap";

configureStdin({
    enableMouse: true,
    enableKittyProtocol: true,
})

const state = new KeyMapState({
    // Initialize with optional Actions
    actions: [
        {
            keymap: [{ input: "foo" }, { key: "ctrl", input: "d" }],
            // can also write as:
            //
            // // string form
            // keymap: "foo<C-d>",
            //
            // // builder form
            // keymap: key.input("foo").ctrl.input("d"),
            //
            // // expanded token form
            // keymap: [{ input: "f" }, { input: "o" }, { input: "o" }, { key: "ctrl", input: "d" }]
            callback: () => {
                // handler
            }
        },

        // If InputState.process matches <C-c> it will return the Action's name if
        // it exists. This provides a different way of handling matched keymaps
        {
            keymap: "<C-c>",
            // keymap: key.ctrl.input("c"),
            // keymap: { key: "ctrl", input: "c" },
            name: "quit",
        },
    ],

    leader: key.input(" "),
});

// Or add an Action directly.  KeyMapState.addAction returns a callback to remove it
// (or you can use KeyMapState.removeAction if you have a reference to the Action)
//
// KeyMapState.clearActions() removes all Actions at once

const removeEscAction = state.addAction({
    keymap: "<Esc>",
    // keymap: { key: "esc" },
    // keymap: key.esc,
    callback: () => {
        // handler
    }
});

state.addAction({
    keymap: key.leader.input("foo"),
    // keymap: "<leader>foo",
    // keymap: { leader: true, input: "foo" },
    callback: () => {
        // handler
    }
})

process.stdin.on("data", (buf: Buffer) => {
    const { data, name } = inputState.process(buf, actions);

    // data provides parsed key/input sets (including ambiguities if any)

    // If there is a match, and you chose not to assign a callback, you handle
    // the `name` manually here.
    if (name === "quit") {
        process.exit();
    }

    if (data.mouse) {
        // Handle mouse data here
    }
})

Handling raw data

parseBuffer provides direct stdin parsing when stateful matching provided by InputState and ActionStore isn't needed. It returns a Data object which contains the parsed info. Data.key and Data.input are extended Set objects with an only(...values) method for easier matching.

configureStdin({
    enableMouse: false,
    enableKittyProtocol: true,
});

process.stdin.on("data", (buf: Buffer) => {
    console.clear();

    const data = parseBuffer(buf);

    print(data);

    if (data.key.only("backspace")) {
        // handler
    }
    if (!data.key.size && data.input.only("a")) {
        // handler
    }
    if (data.key.only("ctrl") && data.input.only("a")) {
        // handler
    }
    if (data.key.only("ctrl", "alt", "super") && data.input.only("U")) {
        // handler
    }

    if (data.key.only("ctrl") && data.input.only("c")) {
        process.exit();
    }
});

Mouse Data

| Property | Type | Description | |----------|------|-------------| | x | number | 0 based x index of cursor within term window | | y | number | 0 based y index of cursor within term window | | leftBtnDown | boolean | true when left mouse button pressed | | rightBtnDown | boolean | true when right mouse button pressed | | scrollBtnDown | boolean | true when scroll button is down (not the same as scrolling with the scroll wheel) | releaseBtn | boolean | true immediately after releasing any of the trackable mouse button | | scrollUp | boolean | true when scrolling up on the scroll wheel | | scrollDown | boolean | true when scroll down on the scroll wheel | | mousemove | boolean | true when mouse is moving within term window |