ANSI/VT \e[7m and \e[27m (reverse/negative) do not work correctly after 24-bit color has been used #94

Open
opened 2026-01-30 21:42:13 +00:00 by claunia · 0 comments
Owner

Originally created by @bitcrazed on GitHub (Feb 16, 2018).

Originally assigned to: @zadjii-msft on GitHub.

From @PhMajerus on October 20, 2017 18:23

Concerns Redstone 3 RTW / Windows 10 ver. 1709, tested on build 16299.19. Affects all WSL distros and more broadly, all Win32 CUI apps using VT.

VT escape control sequences "\x1B[7m" and "\x1B[27m" are used to turn reverse video ("negative", but not technically negative) on and off.
They work fine until the console processed a 24-bit color "\x1B[38;2;r;g;bm" or "\x1B[48;2;r;g;bm". At that point, negative off (27) has no effect or even acts erratically, even if the color has been reset ("\x1B[39m", set back to a base 16 color (\x1B[3(0-9)m"), or if SGR has been reset ("\x1B[m") in the meantime.

echo -e "\e[7m Reversed \e[27m Normal \e[38;2;250;20;40m 24-bit \e[36m 16-colors \e[7m Reversed \e[27m Normal \e[39m Default \e[7m Reversed \e[27m Normal \e[m Reset \e[7m Reversed \e[27m Normal"

vt reverse bug ubuntu rtw

This is a bug in conhost that affects all Windows CUI apps that uses VT, as the following repro code shows:

#include <windows.h>

#ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING
#define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004
#endif

int main()
{
	HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
	
	DWORD dwMode = 0;
	GetConsoleMode(hOutput, &dwMode);
	dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
	SetConsoleMode(hOutput, dwMode);
	
	LPTSTR pszTestString = TEXT("\x1B[7m Reversed \x1B[27m Normal \x1B[38;2;128;5;255m Set 24-bit foreColor \x1B[7m Reversed \x1B[27m Normal \r\n");
	WriteConsole(hOutput, pszTestString, _tcslen(pszTestString), NULL, NULL);
	
	getchar();
	return 0;
}

reversevideo app

Calling SetConsoleScreenBufferInfoEx or showing and OK'ing the console's properties dialog seems to reset the issue until next time 24-bit color is used.

Copied from original issue: Microsoft/WSL#2583

Originally created by @bitcrazed on GitHub (Feb 16, 2018). Originally assigned to: @zadjii-msft on GitHub. _From @PhMajerus on October 20, 2017 18:23_ Concerns Redstone 3 RTW / Windows 10 ver. 1709, tested on build 16299.19. Affects all WSL distros and more broadly, all Win32 CUI apps using VT. VT escape control sequences "\x1B[7m" and "\x1B[27m" are used to turn reverse video ("negative", but not technically negative) on and off. They work fine until the console processed a 24-bit color "\x1B[38;2;r;g;bm" or "\x1B[48;2;r;g;bm". At that point, negative off (27) has no effect or even acts erratically, even if the color has been reset ("\x1B[39m", set back to a base 16 color (\x1B[3(0-9)m"), or if SGR has been reset ("\x1B[m") in the meantime. `echo -e "\e[7m Reversed \e[27m Normal \e[38;2;250;20;40m 24-bit \e[36m 16-colors \e[7m Reversed \e[27m Normal \e[39m Default \e[7m Reversed \e[27m Normal \e[m Reset \e[7m Reversed \e[27m Normal"` ![vt reverse bug ubuntu rtw](https://user-images.githubusercontent.com/25664275/31836014-1e87339a-b5d4-11e7-880b-e185be2d9aa8.png) This is a bug in conhost that affects all Windows CUI apps that uses VT, as the following repro code shows: ``` #include <windows.h> #ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING #define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004 #endif int main() { HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE); DWORD dwMode = 0; GetConsoleMode(hOutput, &dwMode); dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING; SetConsoleMode(hOutput, dwMode); LPTSTR pszTestString = TEXT("\x1B[7m Reversed \x1B[27m Normal \x1B[38;2;128;5;255m Set 24-bit foreColor \x1B[7m Reversed \x1B[27m Normal \r\n"); WriteConsole(hOutput, pszTestString, _tcslen(pszTestString), NULL, NULL); getchar(); return 0; } ``` ![reversevideo app](https://user-images.githubusercontent.com/25664275/31836497-cfd50ea0-b5d5-11e7-92da-f84a47d9c77d.png) Calling SetConsoleScreenBufferInfoEx or showing and OK'ing the console's properties dialog seems to reset the issue until next time 24-bit color is used. _Copied from original issue: Microsoft/WSL#2583_
claunia added the Product-ConhostResolution-Fix-Available labels 2026-01-30 21:42:13 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#94