EraseCells should work on multiple rows #22913

Open
opened 2026-01-31 08:27:02 +00:00 by claunia · 0 comments
Owner

Originally created by @carlos-zamora on GitHub (Feb 12, 2025).

Thanks for raising this issue. The reason this occurs is because the color command uses the console FillConsoleOutputAttribute API to update the colors, and these legacy console APIs aren't intended to be mixed with VT operations like Sixel, so this is essentially undefined behavior.

In the current implementation the fill is treated as a destructive operation. When translated to VT it rewrites all the text using the new colors, and that erases any images that are overwritten. I think we did discuss the possibility of translating this API into a VT DECCARA sequence, which would be non-destructive, so it's possible this could be fixed (at least on some terminals).

Either way, there is definitely a bug evident here, because in conhost the color command currently doesn't erase the image, and that wasn't actually the intended behavior. I think the problem is in the call here:

f28f65870a/src/host/_output.cpp (L242-L243)

That EraseCells method is only capable of erasing a single row, but the APIs being dealt with here are designed to fill a range that could wrap over multiple rows. In the case of the color command, it's a single fill call that covers the entire buffer. So if you had a Sixel image at the very top of the buffer, you'd see just the first row of the image erased, but in most cases nothing would be erased.

Originally posted by @j4james in #18556

Originally created by @carlos-zamora on GitHub (Feb 12, 2025). > Thanks for raising this issue. The reason this occurs is because the `color` command uses the console [`FillConsoleOutputAttribute`](https://learn.microsoft.com/en-us/windows/console/fillconsoleoutputattribute) API to update the colors, and these legacy console APIs aren't intended to be mixed with VT operations like Sixel, so this is essentially undefined behavior. > > In the current implementation the fill is treated as a destructive operation. When translated to VT it rewrites all the text using the new colors, and that erases any images that are overwritten. I think we did discuss the possibility of translating this API into a VT [`DECCARA`](https://vt100.net/docs/vt510-rm/DECCARA.html) sequence, which would be non-destructive, so it's possible this could be fixed (at least on some terminals). > > Either way, there is definitely a bug evident here, because in conhost the `color` command currently *doesn't* erase the image, and that wasn't actually the intended behavior. I think the problem is in the call here: > > https://github.com/microsoft/terminal/blob/f28f65870a9caeb629498c83efc4ab6992c93bad/src/host/_output.cpp#L242-L243 > > That `EraseCells` method is only capable of erasing a single row, but the APIs being dealt with here are designed to fill a range that could wrap over multiple rows. In the case of the `color` command, it's a single fill call that covers the entire buffer. So if you had a Sixel image at the very top of the buffer, you'd see just the first row of the image erased, but in most cases nothing would be erased. _Originally posted by @j4james in [#18556](https://github.com/microsoft/terminal/issues/18556#issuecomment-2651331837)_
claunia added the Product-ConhostArea-OutputIssue-BugNeeds-Tag-Fix labels 2026-01-31 08:27:03 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#22913