feat: Add mode 2027 (grapheme cluster) support with DECRQM probing#1637
Open
feat: Add mode 2027 (grapheme cluster) support with DECRQM probing#1637
Conversation
8e6aae5 to
1dfc8ff
Compare
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>
7b3082b to
f142465
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Terminal.supportsGraphemeClusterMode()andsetGraphemeClusterMode(boolean)API methods for terminal mode 2027 ("Unicode Core")CSI ? 2027 $ p) instead of guessing from the terminal type string, since terminals like macOS Terminal.app reportxterm-256colorwithout supporting mode 2027AbstractWindowsTerminalto returnfalsesince Windows console doesn't support DECRQM probingCLAUDE.mdwith project conventions for AI assistantsContext
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
TERMtype.Test plan
GraphemeClusterModeTesttests pass./mvx mvn test -pl terminal)