* Attempt to enable VT100 sequence processing for colorization on Windows. * If current environment is not VT100-compatible or if this mode could not * be enabled, return false. */
| 49 | * be enabled, return false. |
| 50 | */ |
| 51 | static bool |
| 52 | enable_vt_processing(void) |
| 53 | { |
| 54 | /* Check stderr */ |
| 55 | HANDLE hOut = GetStdHandle(STD_ERROR_HANDLE); |
| 56 | DWORD dwMode = 0; |
| 57 | |
| 58 | if (hOut == INVALID_HANDLE_VALUE) |
| 59 | return false; |
| 60 | |
| 61 | /* |
| 62 | * Look for the current console settings and check if VT100 is already |
| 63 | * enabled. |
| 64 | */ |
| 65 | if (!GetConsoleMode(hOut, &dwMode)) |
| 66 | return false; |
| 67 | if ((dwMode & ENABLE_VIRTUAL_TERMINAL_PROCESSING) != 0) |
| 68 | return true; |
| 69 | |
| 70 | dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING; |
| 71 | if (!SetConsoleMode(hOut, dwMode)) |
| 72 | return false; |
| 73 | return true; |
| 74 | } |
| 75 | #endif /* WIN32 */ |
| 76 | |
| 77 | /* |