Skip to content

Comments

feat: Add mode 2027 (grapheme cluster) support with DECRQM probing#1637

Open
gnodet wants to merge 2 commits intomasterfrom
feat/grapheme-cluster-mode-2027
Open

feat: Add mode 2027 (grapheme cluster) support with DECRQM probing#1637
gnodet wants to merge 2 commits intomasterfrom
feat/grapheme-cluster-mode-2027

Conversation

@gnodet
Copy link
Member

@gnodet gnodet commented Feb 19, 2026

Summary

  • Add Terminal.supportsGraphemeClusterMode() and setGraphemeClusterMode(boolean) API methods for terminal mode 2027 ("Unicode Core")
  • Detect support at runtime via DECRQM (CSI ? 2027 $ p) instead of guessing from the terminal type string, since terminals like macOS Terminal.app report xterm-256color without supporting mode 2027
  • Override in AbstractWindowsTerminal to return false since Windows console doesn't support DECRQM probing
  • Add 13 unit tests covering all DECRPM response values, dumb terminals, timeout, caching, enable/disable sequences, and interface defaults
  • Add website documentation with escape sequence reference, terminal compatibility table, and best practices
  • Add CLAUDE.md with project conventions for AI assistants

Context

Mode 2027 tells the terminal to use UAX #29 grapheme cluster segmentation instead of per-codepoint wcwidth() for cursor positioning. This fixes cursor misalignment for multi-codepoint characters like ZWJ emoji sequences (e.g., 👨‍🌾), flag sequences, and combined characters.

Currently supported by Contour, foot, WezTerm, and Ghostty. The DECRQM probing approach ensures JLine correctly detects support regardless of the reported TERM type.

Test plan

  • All 13 new GraphemeClusterModeTest tests pass
  • All 148 terminal module tests pass (./mvx mvn test -pl terminal)
  • Manual test with a mode 2027-capable terminal (WezTerm/Ghostty)

@gnodet gnodet force-pushed the feat/grapheme-cluster-mode-2027 branch 2 times, most recently from 8e6aae5 to 1dfc8ff Compare February 19, 2026 10:28
gnodet and others added 2 commits February 23, 2026 14:40
Add Terminal.supportsGraphemeClusterMode() and setGraphemeClusterMode()
to enable UAX #29 grapheme cluster segmentation for correct cursor
positioning of multi-codepoint characters (ZWJ emoji, flags, etc.).

Support is detected at runtime via DECRQM (CSI ? 2027 $ p) rather than
guessing from the terminal type string, since many terminals report
xterm-256color without supporting mode 2027.
- Track enabled state with graphemeClusterModeEnabled field and add
  getGraphemeClusterMode() accessor
- Automatically disable mode 2027 on terminal close if it was enabled
- Restrict DECRQM probing to xterm-like terminals to avoid printing
  garbage on terminals that don't understand DECRQM
- Drain partial/unexpected DECRPM responses to prevent leaving stale
  bytes in the input buffer
- Add LineReader Option.GRAPHEME_CLUSTER to auto-enable mode 2027
  during readLine() and disable it in doCleanup()

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@gnodet gnodet force-pushed the feat/grapheme-cluster-mode-2027 branch from 7b3082b to f142465 Compare February 23, 2026 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant