fix(input): support CJK editing over SSH (width-aware backspace + cursor movement)#637
Open
FrostMiKu wants to merge 1 commit into
Open
fix(input): support CJK editing over SSH (width-aware backspace + cursor movement)#637FrostMiKu wants to merge 1 commit into
FrostMiKu wants to merge 1 commit into
Conversation
…ent) Over SSH/telnet, backspacing a wide (CJK) character left a half-glyph on screen because the erase only cleared one column, and there was no cursor model at all, so left/right/Home/End/Delete did nothing. - Add a Cursor offset to ClientInput. CleanserInputHandler now inserts at the cursor (instead of always appending) and deletes the rune before it; AnsiHandler handles left/right/Home/End/Delete. - Make echo and erase width-aware via runewidth so CJK characters occupy 2 columns. Backspace emits the correct number of backspaces + clear-to-EOL instead of the old single-column "\b \b". - Fix up/down history recall to erase by display width, not byte count. - Keep local-echo clients (Mudlet, web) and masked (password) fields on their existing behavior; they manage their own input line. Verified end-to-end over a real SSH connection (with pty): typing, backspace and left/right/Home movement all emit correct width-aware sequences. Added unit + integration tests that assert on the actual terminal bytes emitted. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Problem
When connecting over SSH, editing input containing CJK (Chinese/Japanese/Korean) characters was broken:
\b \b), so deleting a Chinese character left the left half of the glyph stuck on the line.Fix
Cursorbyte-offset toClientInput.CleanserInputHandlernow inserts at the cursor (instead of always appending) and deletes the rune before it;AnsiHandlermoves it with the left/right/Home/End/Delete keys.runewidthso wide characters occupy the correct number of columns. Backspace now emits the right number of backspaces + clear-to-EOL instead of the single-column\b \b. Cursor moves (left/right/Home/End) move by the display width of the character they cross.main.go) now keepsCursorvalid.Scope / unchanged behavior
Verification
End-to-end over a real SSH connection (with a pty), capturing exactly what the server sends back to the terminal:
你好ESC[2D ESC[0K\b \b= 1 col)ESC[2DESC[2CESC[4D你世) → startTests added:
TestCleanserInputHandler_UTF8Backspace/_NoBackspaceupdated to setCursor(required by the new model).make validate,go build ./..., and theinputhandlers/connections/termtest suites pass. (internal/templates/TestRenderPanel_MaxWidth_AnsiTagsHandledfails onmasterindependently of this change.)🤖 Generated with Claude Code