Skip to content

Text Input Handling #6

Description

@julia-script

Handling textual input is an extremely common requirement in user interfaces—especially in terminal UIs, which are inherently text-based—and getting it right is complex. Because of this, I believe TermUi should include native text input components. Here’s my initial vision for how they might work:


📝 Core Features (MVP)

  • Range selection & actions

    • Copy
    • Paste
    • Replace (typing or pasting over an active selection)
    • Sanitize inputs/outputs (especially stripping or escaping escape sequences so the UI doesn’t break)
  • Standard shortcuts

    • e.g. Cmd+C/Cmd+V (or Ctrl+C/Ctrl+V on other platforms), Cmd+A for select-all, etc.
  • Cursor movement

    • Vertical & horizontal movement that accounts for text layout
  • Quick navigation

    • e.g. Cmd+↑ to jump to the first line, Cmd+← to go to the beginning of the line
  • Overflow handling

    • Scroll when text exceeds the text area (support both mouse wheel and cursor keys)

🔧 Post-MVP (Can Wait)

  • Rich text support (formatting, inline images, etc.)
  • RTL (right-to-left) support
    • Im unfamiliar with the necessities of RTL for text inputs on terminals, and this library as a whole lacks support for it. I imagine it greatly impacts many features like rendering order, text selection, etc. More research is needed

🌟 Nice-to-Haves

  • Native support for multiple cursors would be awesome
  • Text completion/suggestions
  • Code-input extras, like syntax highlighting
    • We may want to investigate some form of Tree-sitter integration for this

📚 Requirements & Dependencies

I’m aiming for a lean subset of the web’s text APIs:

  • Range API
    Based on the WHATWG spec: https://dom.spec.whatwg.org/#ranges

  • Selection APIs

    • Note: browsers support two APIs for text selection:

      • A simple version for plaintext inputs (https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#textFieldSelection)
      • A more complex DOM-based version (https://www.w3.org/TR/selection-api)
    • I’m considering unifying both (plaintext and DOM) to simplify and support rich text editing via contenteditable (https://html.spec.whatwg.org/multipage/interaction.html#attr-contenteditable).

  • String handling

    • Right now, nodes use text: ArrayList(u8) with a NodeKind of text. I want to introduce a String primitive with codepoint-based length (e.g., based on Zig’s Unicode support rather than byte count).

⚠️ Potential Roadblocks

  • Shortcuts
    Terminal clients often capture common clipboard keys (Cmd+C/Cmd+V or Ctrl+C/Ctrl+V) for their own commands, so TermUi may not receive them. We’ll need to pick alternatives or find workarounds, and make it the least confusing possible.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions