Bug #9208


Win32 ANSI color no longer works since revision 43331

Added by snaury (Alexey Borzenkov) over 9 years ago. Updated 12 months ago.

Target version:
ruby -v:
ruby 2.1.0dev (2013-12-03 trunk 43983) [i386-mingw32]


In revision 43331 in file win32/win32.c function console_emulator_p was added, which supposedly checked for patched WriteConsoleW. However, since WriteConsoleW points to a stub (which does jmp [import]), the allocation base address is always 0x400000 (i.e. ruby.exe), which is never equal to kernel32.dll. Because of this colors on ruby trunk never work on Windows anymore.

Attached patch fixes the problem and still detects conemu (i.e. whether WriteConsoleW is patched or not).

P.S. I don't understand why ruby needs to detect conemu? Console attributes and colors work in conemu as is, i.e. console_emulator_p could just always return FALSE, and everything seems to work correctly. However when conemu is detected and ruby tries to output ansi codes colors actually don't work on my Win7 x64 for some weird reason. Seems like this emulator detection does more harm than good.


001-win32-console.patch (690 Bytes) 001-win32-console.patch snaury (Alexey Borzenkov), 12/04/2013 05:17 AM

Updated by snaury (Alexey Borzenkov) over 9 years ago

Regarding conemu: it seems that latest conemu builds actually handle colors correctly, so it was some conemu bug. Am I correct that handling colors with conemu is preferred because it has more ansi features than builtin ruby? Then it makes sense.

Updated by luislavena (Luis Lavena) over 9 years ago

  • Status changed from Open to Assigned

Thank you snaury,

That is correct, the addition of the ConEmu presence was something reported early on (#8201) that affected some users using Ruby under ConEmu.

I can say that color performance under ConEmu is considerably slower than native in Ruby itself, even they are using the same functions (I think is due the injection of code).

Assigned to nobu for approval before applying.

Updated by mame (Yusuke Endoh) 12 months ago

  • Status changed from Assigned to Feedback
  • Backport deleted (1.9.3: UNKNOWN, 2.0.0: UNKNOWN)

@nobu (Nobuyoshi Nakada) thinks it should be improved in ConEmu side. We need to check if this issue is still active in ConEmu.


Also available in: Atom PDF