Cursor movements distort wide cells in a different row #14262

Open
opened 2026-01-31 04:05:25 +00:00 by claunia · 0 comments
Owner

Originally created by @alabuzhev on GitHub (Jun 18, 2021).

Windows Terminal version (or Windows build number)

10.0.19041.1055

Other Software

No response

Steps to reproduce

Compile and run the following code using the standard console host:

#include <windows.h>

int main()
{
	const auto Out = GetStdHandle(STD_OUTPUT_HANDLE);

	SetConsoleScreenBufferSize(Out, { 80, 25 });

	const auto JapaneseCP = 932;
	SetConsoleOutputCP(JapaneseCP);

	SetConsoleCursorPosition(Out, { 0, 0 });

	const wchar_t Text[] = L"あいうえおかきくけこさしすせそた";
	const auto Size = ARRAYSIZE(Text) - 1;

	CHAR_INFO Buffer[Size * 2]{};

	for (size_t i = 0; i != Size; ++i)
	{
		const auto BlackOnGrey = 0x70;
		Buffer[i * 2 + 0].Attributes = BlackOnGrey | COMMON_LVB_LEADING_BYTE;
		Buffer[i * 2 + 1].Attributes = BlackOnGrey | COMMON_LVB_TRAILING_BYTE;
		Buffer[i * 2 + 0].Char.UnicodeChar = Text[i];
		Buffer[i * 2 + 1].Char.UnicodeChar = Text[i];
	}

	SMALL_RECT WriteRegion1{ 0, 2, Size * 2 - 1, 2 };
	WriteConsoleOutput(Out, Buffer, { Size * 2, 1 }, {}, &WriteRegion1);

	short CursorX = 0;
	SetConsoleCursorPosition(Out, { CursorX, 1 });

	int Direction = 1;

	for (;;)
	{
		Sleep(20);

		CursorX += Direction;
		if (CursorX == Size * 2 - 1)
			Direction = -1;
		else if (!CursorX)
			Direction = +1;

		// Comment this line to make the bug go away:
		SetConsoleCursorPosition(Out, { CursorX, 0 });

		CHAR_INFO Buffer2{};
		Buffer2.Char.UnicodeChar = L'!';
		Buffer2.Attributes = 0xCF;
		SMALL_RECT WriteRegion2{ 40, 2, 41, 2 };
		WriteConsoleOutput(Out, &Buffer2, { 1, 1 }, {}, &WriteRegion2);
	}
}

Expected Behavior

The program draws two areas:

  • grey, only once
  • red, constantly

It also constantly moves the cursor left and right.

The grey area is expected to stay static and display the characters correctly:
image

Actual Behavior

The simultaneous cursor movements in another row distort the characters in the grey area:
image

Originally created by @alabuzhev on GitHub (Jun 18, 2021). ### Windows Terminal version (or Windows build number) 10.0.19041.1055 ### Other Software _No response_ ### Steps to reproduce Compile and run the following code using the standard console host: ```C++ #include <windows.h> int main() { const auto Out = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleScreenBufferSize(Out, { 80, 25 }); const auto JapaneseCP = 932; SetConsoleOutputCP(JapaneseCP); SetConsoleCursorPosition(Out, { 0, 0 }); const wchar_t Text[] = L"あいうえおかきくけこさしすせそた"; const auto Size = ARRAYSIZE(Text) - 1; CHAR_INFO Buffer[Size * 2]{}; for (size_t i = 0; i != Size; ++i) { const auto BlackOnGrey = 0x70; Buffer[i * 2 + 0].Attributes = BlackOnGrey | COMMON_LVB_LEADING_BYTE; Buffer[i * 2 + 1].Attributes = BlackOnGrey | COMMON_LVB_TRAILING_BYTE; Buffer[i * 2 + 0].Char.UnicodeChar = Text[i]; Buffer[i * 2 + 1].Char.UnicodeChar = Text[i]; } SMALL_RECT WriteRegion1{ 0, 2, Size * 2 - 1, 2 }; WriteConsoleOutput(Out, Buffer, { Size * 2, 1 }, {}, &WriteRegion1); short CursorX = 0; SetConsoleCursorPosition(Out, { CursorX, 1 }); int Direction = 1; for (;;) { Sleep(20); CursorX += Direction; if (CursorX == Size * 2 - 1) Direction = -1; else if (!CursorX) Direction = +1; // Comment this line to make the bug go away: SetConsoleCursorPosition(Out, { CursorX, 0 }); CHAR_INFO Buffer2{}; Buffer2.Char.UnicodeChar = L'!'; Buffer2.Attributes = 0xCF; SMALL_RECT WriteRegion2{ 40, 2, 41, 2 }; WriteConsoleOutput(Out, &Buffer2, { 1, 1 }, {}, &WriteRegion2); } } ``` ### Expected Behavior The program draws two areas: - grey, only once - red, constantly It also constantly moves the cursor left and right. The grey area is expected to stay static and display the characters correctly: ![image](https://user-images.githubusercontent.com/11453922/122611826-e82fd080-d079-11eb-917c-bc81c6d286bd.png) ### Actual Behavior The simultaneous cursor movements in another row distort the characters in the grey area: ![image](https://user-images.githubusercontent.com/11453922/122611951-262cf480-d07a-11eb-95d4-a8fb72239b3e.png)
claunia added the Resolution-Duplicate label 2026-01-31 04:05:25 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#14262