Fix NO-BREAK SPACE (U+00A0) column width calculation#448
Merged
migueldeicaza merged 2 commits intomigueldeicaza:mainfrom Jan 16, 2026
Merged
Fix NO-BREAK SPACE (U+00A0) column width calculation#448migueldeicaza merged 2 commits intomigueldeicaza:mainfrom
migueldeicaza merged 2 commits intomigueldeicaza:mainfrom
Conversation
The condition `irune <= 0xA0` incorrectly treated U+00A0 (NO-BREAK SPACE) as non-printable, returning width -1. This caused cursor positioning issues in applications that use NBSP in their output. Changed to `irune < 0xA0` so that NO-BREAK SPACE correctly returns width 1 (handled by the default case at end of function), matching the behavior of regular space (U+0020).
Verifies that NBSP has width 1 and cursor positioning works correctly when NBSP is used (e.g., after prompt characters like in Claude Code).
9749c9d to
c254010
Compare
Owner
|
Let me first validate with ucs-detect |
Owner
|
Good news, that passed. |
yejune
pushed a commit
to yejune/SwiftTerm
that referenced
this pull request
Jan 18, 2026
* Fix NO-BREAK SPACE (U+00A0) column width calculation The condition `irune <= 0xA0` incorrectly treated U+00A0 (NO-BREAK SPACE) as non-printable, returning width -1. This caused cursor positioning issues in applications that use NBSP in their output. Changed to `irune < 0xA0` so that NO-BREAK SPACE correctly returns width 1 (handled by the default case at end of function), matching the behavior of regular space (U+0020). * Add test for NO-BREAK SPACE (U+00A0) width Verifies that NBSP has width 1 and cursor positioning works correctly when NBSP is used (e.g., after prompt characters like in Claude Code).
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
NO-BREAK SPACE (U+00A0) was incorrectly treated as non-printable (width -1) because the condition
irune <= 0xA0included it in the C1 control character range. This caused cursor positioning issues when applications use NBSP in their output.Changes
Changed the condition from
irune <= 0xA0toirune < 0xA0incolumnWidth()so that U+00A0 falls through to the default return value of 1, matching the expected behavior of a space character.Use Case
Claude Code (Anthropic's terminal-based AI coding assistant) uses NO-BREAK SPACE after its prompt character (
❯). With the incorrect width calculation, typing the first character after the prompt would cause cursor misalignment and visual glitches (duplicate/ghost characters).Testing