Skip to content

Parse a modified literal plus in KeyEvent.parse #126

In review

Description

@tony

Summary

The chord helper accepts a bare plus sign but cannot express Ctrl+plus with the same notation. The structured input API can encode the event.

Reproduction

  1. From the tagged libvt checkout, install the locked development dependencies with uv sync --frozen --python 3.14 --all-groups --all-extras. Use the checkout root as the working directory.

  2. Save the following as case.py at the checkout root.

from libvt import Terminal
from libvt.input import KeyEvent, KeyMod

term = Terminal()
term.feed(b"\x1b[>8u")
assert term.encode(KeyEvent.parse("+")) == term.encode(KeyEvent("+"))
direct = term.encode(KeyEvent("+", KeyMod.CTRL))
print("structured Ctrl+plus", direct)
try:
    parsed = KeyEvent.parse("ctrl++")
except ValueError as error:
    print(str(error))
    raise SystemExit(1) from None
assert term.encode(parsed) == direct
  1. Run the case.
$ uv run --no-sync python case.py

Expected

A documented spelling should map to a plus key with the requested modifiers.

Actual

Parsing the chord raises an unknown-modifier error for an empty token.

Environment

Tested versions

CPython 3.14.6 on Linux ARM64 under WSL2. The example produced the reported result against both v0.0.1a4 and the tested trunk revision.

Evidence

Observed output
structured Ctrl+plus b'\x1b[43;5u'
unknown key modifier '' in chord 'ctrl++'

Proposal

Treat a trailing literal plus explicitly or document a named plus-key token. Cover Ctrl, Alt and a combined modifier case.

  • Developer experience — Higher-level send_key calls can express a common zoom shortcut without constructing an event object.
  • Immediate benefit — Users can drive zoom controls with the same syntax as other shortcuts.
  • Longer-term benefit — Recorder playback and hand-written key sequences share an unambiguous chord grammar.
  • End-user experience — A familiar shortcut works the first time it is written.

References

Activity

  1. added
    bug
    p3
    on Nov 30, 2026
  2. tony commented on Dec 3, 2026

    @tony
    MemberAuthor

    KeyEvent.parse('ctrl++') treats the last plus as the key. In Kitty report-all mode it emits ESC [ 43 ; 5 u, matching a directly constructed Ctrl-plus event. PR #187

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugp3

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions