From 9fa1e4990e655a85025c9d270a1606983e375e47 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Thu, 10 Nov 2016 15:31:27 +0000 Subject: win32: allow ANSI emulation to be disabled If the environment variable BB_SKIP_ANSI_EMULATION is set (the value doesn't matter) escape sequences are passed through to the terminal. --- win32/winansi.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/win32/winansi.c b/win32/winansi.c index 7069b8d80..e95b9c846 100644 --- a/win32/winansi.c +++ b/win32/winansi.c @@ -59,6 +59,19 @@ static void init(void) initialized = 1; } +static int skip_ansi_emulation(void) +{ + static char *var = NULL; + static int got_var = FALSE; + + if (!got_var) { + var = getenv("BB_SKIP_ANSI_EMULATION"); + got_var = TRUE; + } + + return var != NULL; +} + #define FOREGROUND_ALL (FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE) #define BACKGROUND_ALL (BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE) @@ -399,7 +412,7 @@ static int ansi_emulate(const char *s, FILE *stream) while (*pos) { pos = strstr(str, "\033["); - if (pos) { + if (pos && !skip_ansi_emulation()) { size_t len = pos - str; if (len) { @@ -636,7 +649,7 @@ static int ansi_emulate_write(int fd, const void *buf, size_t count) /* we've checked the data doesn't contain any NULs */ while (*pos) { pos = strstr(str, "\033["); - if (pos) { + if (pos && !skip_ansi_emulation()) { len = pos - str; if (len) { -- cgit v1.2.3-55-g6feb