Skip to content

Replace null bytes with spaces in session read output#45

Open
d3dave wants to merge 1 commit into
mkusaka:mainfrom
d3dave:main
Open

Replace null bytes with spaces in session read output#45
d3dave wants to merge 1 commit into
mkusaka:mainfrom
d3dave:main

Conversation

@d3dave
Copy link
Copy Markdown

@d3dave d3dave commented Apr 21, 2026

Terminal cells that have never been written to are represented as \0 in the string returned by async_get_screen_contents() (see [ScreenChar.h](https://github.com/gnachman/iTerm2/blob/9d71745f738f0e44b14160ae2ad08ea3fc441889/sources/ScreenChar.h#L254)). iTerm2 paints them as blank, but consumers that strip or normalize control characters collapse words together.

Before:
image

After:
image

Replace null bytes in screen contents with spaces.
@mkusaka
Copy link
Copy Markdown
Owner

mkusaka commented Apr 21, 2026

@d3dave Thanks for the contribution and for the clear reproduction.

After digging into this a bit more, I think this is probably an iTerm2-side issue rather than an it2 issue.

From the iTerm2 side:

Because of that, I’m hesitant to merge a blanket replace('\0', ' ') in it2.

My main concern is that this changes the raw output semantics in a way that could become a regression. If there are cases where a caller actually wants to observe the current \0 representation, or where \0 is intentional data, replacing it unconditionally here would silently erase that distinction.

I’m going to spend a bit more time looking into the iTerm2 side when I get a chance before deciding what the right fix is here.

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