Turning off the cursor in WSL? #18387

Closed
opened 2026-01-31 06:12:23 +00:00 by claunia · 0 comments
Owner

Originally created by @vefatica on GitHub (Sep 4, 2022).

Microsoft Windows 10 Pro for Workstations
10.0.19044.1889 (2009, 21H2)
WindowsTerminalPreview 1.15.2208.16002

Below is a little program. Run it in any Windows shell (console or WT) and the cursor is OFF during the Sleep(). Run it in any WSL/Ubuntu shell (console or WT) and the cursor is ON during the Sleep(). Note also that in the WSL case, the cursor is at EOL. What's going on? Thanks!

#include <Windows.h>

BOOL Emit (HANDLE h, LPWSTR sz)
{
	return WriteConsoleW(h, sz, lstrlen(sz), nullptr, nullptr);
}

INT wmain (INT argc, WCHAR **argv)
{
	HANDLE hCONOUT = CreateFileW(L"CONOUT$", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);

	// cursor off; up 1 line; to column 1; erase to EOL
	Emit(hCONOUT, L"\x001b[?25l" L"\x001b[1A" L"\x001b[1G" L"\x001b[K");

	Sleep(5000);

	// cursor on;
	Emit(hCONOUT, L"\x001b[?25h");

	return 0;
}
Originally created by @vefatica on GitHub (Sep 4, 2022). Microsoft Windows 10 Pro for Workstations 10.0.19044.1889 (2009, 21H2) WindowsTerminalPreview 1.15.2208.16002 Below is a little program. Run it in any Windows shell (console or WT) and the cursor is OFF during the Sleep(). Run it in any WSL/Ubuntu shell (console or WT) and the cursor is ON during the Sleep(). Note also that in the WSL case, the cursor is at EOL. What's going on? Thanks! ``` #include <Windows.h> BOOL Emit (HANDLE h, LPWSTR sz) { return WriteConsoleW(h, sz, lstrlen(sz), nullptr, nullptr); } INT wmain (INT argc, WCHAR **argv) { HANDLE hCONOUT = CreateFileW(L"CONOUT$", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); // cursor off; up 1 line; to column 1; erase to EOL Emit(hCONOUT, L"\x001b[?25l" L"\x001b[1A" L"\x001b[1G" L"\x001b[K"); Sleep(5000); // cursor on; Emit(hCONOUT, L"\x001b[?25h"); return 0; } ```
claunia added the Needs-TriageNeeds-Tag-Fix labels 2026-01-31 06:12:23 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#18387