Skip to content

Fix NO-BREAK SPACE (U+00A0) column width calculation#448

Merged
migueldeicaza merged 2 commits intomigueldeicaza:mainfrom
kuzmeech:fix/nbsp-width
Jan 16, 2026
Merged

Fix NO-BREAK SPACE (U+00A0) column width calculation#448
migueldeicaza merged 2 commits intomigueldeicaza:mainfrom
kuzmeech:fix/nbsp-width

Conversation

@kuzmeech
Copy link
Contributor

Summary

NO-BREAK SPACE (U+00A0) was incorrectly treated as non-printable (width -1) because the condition irune <= 0xA0 included 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 <= 0xA0 to irune < 0xA0 in columnWidth() 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

  • All 155 existing tests pass
  • Manual testing with Claude Code - first character no longer duplicates
  • Verified U+00A0 now returns width 1 instead of -1

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).
@migueldeicaza
Copy link
Owner

Let me first validate with ucs-detect

@migueldeicaza
Copy link
Owner

Good news, that passed.

@migueldeicaza migueldeicaza merged commit 992504e into migueldeicaza:main Jan 16, 2026
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).
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.

2 participants

Comments