Skip to content

Commit 35c4bb3

Browse files
committed
Activate ANSI processing on older terminals on Windows
1 parent 00fdedd commit 35c4bb3

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

src/boxes.c

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,31 @@ static void activateSystemEncoding()
469469

470470

471471

472+
/**
473+
* On some (presumably older) Windows (like Windows 10), we must enable ANSI code support in the terminal.
474+
*/
475+
void enable_ansi_mode() {
476+
#if defined(_WIN32) || defined(__MINGW32__)
477+
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
478+
if (hOut == INVALID_HANDLE_VALUE) {
479+
return;
480+
}
481+
482+
DWORD dwMode = 0;
483+
if (!GetConsoleMode(hOut, &dwMode)) {
484+
return;
485+
}
486+
487+
#ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING
488+
#define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004
489+
#endif
490+
dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING | ENABLE_PROCESSED_OUTPUT;
491+
SetConsoleMode(hOut, dwMode);
492+
#endif
493+
}
494+
495+
496+
472497
/* _\|/_
473498
(o o)
474499
+----oOO-{_}-OOo------------------------------------------------------------+
@@ -481,8 +506,6 @@ int main(int argc, char *argv[])
481506
int saved_designwidth; /* opt.design->minwith backup, used for mending */
482507
int saved_designheight; /* opt.design->minheight backup, used for mending */
483508

484-
log_debug(__FILE__, MAIN, "BOXES STARTING ...\n"); /* TODO This line will never execute, because debug not on yet */
485-
486509
/* Temporarily set the system encoding, for proper output of --help text etc. */
487510
activateSystemEncoding();
488511
encoding = locale_charset();
@@ -494,6 +517,7 @@ int main(int argc, char *argv[])
494517
log_debug(__FILE__, MAIN, "Character Encoding = %s\n", encoding);
495518

496519
color_output_enabled = check_color_support(opt.color);
520+
enable_ansi_mode();
497521

498522
handle_config_parsing();
499523

0 commit comments

Comments
 (0)