Skip navigation
OpenTUI Keymap is a host agnostic key/cmd engine for DOM like apps.
0:00 / 1:27

OpenTUI Keymap is a host agnostic key/cmd engine for DOM like apps.

kmdr

@kmdrfx7.6K followers

Visit on X
736 likesDownloadOriginal post

91,661 views

OpenTUI Keymap is a host agnostic key/cmd engine for DOM like apps. It allows extreme customisation of a generic core, from key stroke syntax parsing to to command resolution and dispatch behaviour. It composes layers of bindings and commands into a single adaptive dispatch model. Demo link in the replies. There are many such systems, most of which stop at the key binding part. Apps often are expected to implement their own command layer on top of these. This disconnects the bindings from the actual command registry. Looking for a proper solution usable in OpenCode I couldn't find anything that fulfilled the need of being extremely extensible to allow plugins to fully control key mapping and command behaviour. I wanted it to always be able to know exactly which keys and commands are reachable at any point in time, no matter from where and how the mappings are manipulated. The main driver was enabling a which-key like plugin and vim like bindings in a mostly declarative way. While any other plugin could extend the keymap even further with a custom config syntax for key strokes for example. So addons for it are mostly composable and it comes with a variety of addons providing common behaviour. It can also power other discovery features directly from live state. Help views, command palettes and graph/debug UIs can all ask the engine what is active, reachable, shadowed, pending, or dispatchable instead of rebuilding that knowledge separately. The core is intentionally very much generic: hosts adapt focus, hierarchy, input events, and lifecycle, while addons extend parsing, tokens, sequence patterns, command metadata, resolvers, interceptors, and event matching. The result is a keymap that plugins can compose with rather than work around. This could all be built directly into OpenCode and just be app specific. Working on OpenTUI though I want applications to have an out-of-the-box solution to build keyboard-first apps easily. Well, at least agents can. It is extremely over-engineered. And I love it. I hope some of you will too.

35 Comments

Comments from the original post on X (Twitter)

  • kmdr's profile picture

    @kmdrfx

    Here is the HTML adapter demo, which is also in the OpenTUI repository along with demos for core/react/solid. Full docs are on the opentui website.

    27 likes

  • Igor bedesqui's profile picture

    @bedesqui

    what the fuck why are you guys casually building some of the coolest primitives??? like, stop making me want to build for the terminal wtfff

    12 likes

  • kmdr's profile picture

    @kmdrfx

    Come to the terminal side harhar!

    10 likes

  • Ola's profile picture

    @tyrellshawn_ai

    Attention to detail on another level! This is sick!

    2 likes

  • Roman's profile picture

    @naumenko_roman

    Art!

    2 likes

  • Ben Vinegar's profile picture

    @bentlegen

    this ever get released? would love to use it

    2 likes

  • kmdr's profile picture

    @kmdrfx

    yep it's here and maintained, used by opencode as well

    1 like

  • Anthony Shew's profile picture

    @anthonysheww

    wen rust bindings for opentui Hint: The right answer is “wen u make them nerd”

    2 likes

  • kmdr's profile picture

    @kmdrfx

    We'll just rewrite the native core in rust anyway.

    11 likes

  • Anthony Shew's profile picture

    @anthonysheww

    Like actually orrrrrr…? I’m trying to rewrite the Turborepo TUI, what’s a young man to do?

    1 like

  • kmdr's profile picture

    @kmdrfx

    Eventually. Opentui has a proper CLI mode now, courtesy of @simonklee. Many other improvements on the way over the coming weeks.

    5 likes

  • Tanay Karnik's profile picture

    @tanayvk

    this looks amazing. can we implement app-level modes with this too? like insert/normal? or do we have keep that state separately and manually update the keymapper state? im on my phone, will take a look at the source in a bit.

    1 like

  • Shivaraj's profile picture

    @shivaraj_does

    Will this work on opentui/core ?

    1 like

  • kmdr's profile picture

    @kmdrfx

    The demo in the video is core only. Works with opentui core, solid, and react.

    2 likes

  • Shivaraj's profile picture

    @shivaraj_does

    Lfg I was looking for exactly this tbh. Been building this from weeks and was running outta keybinds... seems like this is a perfect fit!!

  • Alan North's profile picture

    @alanscodelog

    Not exactly the same but I've been working on this issue for a while. Interesting to see a different approach though.

    1 like

  • kmdr's profile picture

    @kmdrfx

    Cool stuff, I like that it can also bind mouse events.

    1 like

  • Berend de Boer's profile picture

    @berenddeboer

    We'll know if it is really extensible if I can make Emacs keystrokes work 🙂

    1 like

  • kmdr's profile picture

    @kmdrfx

    I have experimented with that, there is a sample addon to for emacs chords. It's far from complete, but should be possible to do everything needed to make it complete as addon.

    4 likes

  • Rafael Mendiola's profile picture

    @GroundControl

    As someone who's also coming from Vim and has implemented keyboard shortcuts in my apps, this is lovely.

    1 like