Skip to content

[feature] Public API for registering/removing key event callbacks #102

@kzhrv

Description

@kzhrv

Hi, I’m integrating reeflective/readline into a shell that exposes programmable keypress events to users.

At the moment I can approximate this by rebinding key sequences through inputrc/keymaps and replaying the original bind, but that is adapter-heavy and not as trustworthy as a native hook.

Current issue

What I need is a frontend-level way to:

  • observe a specific key sequence
  • inspect a small editor state snapshot
  • optionally modify the line/cursor/hint state
  • optionally continue with the original key binding

Requested API

Something like:

type KeyEventState struct {
    Line        string
    CursorPos   int
    KeyPress    string
    InputMode   string
    PreviewMode string
}

type KeyEventResult struct {
    SetLine   []rune
    SetPos    int
    HintText  []rune
    Continue  bool
}

func (rl *Shell) AddKeyEvent(seq string, cb func(int, *KeyEventState) *KeyEventResult) error
func (rl *Shell) RemoveKeyEvent(seq string) error

Again, this is just an example shape.

Why this matters

This would allow integrations to support:

  • programmable key bindings
  • shell-defined key events
  • editor-state-aware scripting/hooks

without having to patch keymaps indirectly.

Important point

I am not asking for your internals to mirror another library’s exact event model.
A small, stable, public key event hook would already remove a lot of adapter complexity.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions