From 2f51653a9e08b348c20971b28c82221b653b3e88 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Sun, 4 Apr 2021 10:27:13 -0700 Subject: [PATCH] errlog: try to enable WIN10 terminal escape processing --- modules/libcom/src/error/errlog.c | 33 +++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/modules/libcom/src/error/errlog.c b/modules/libcom/src/error/errlog.c index af6aa2dee..6b4322213 100644 --- a/modules/libcom/src/error/errlog.c +++ b/modules/libcom/src/error/errlog.c @@ -12,6 +12,11 @@ * Date: 07JAN1998 */ +#ifdef _WIN32 +# define VC_EXTRALEAN +# include +#endif + #include #include #include @@ -205,11 +210,11 @@ void errlogSequence(void) epicsEventMustTrigger(pvt.waitForSeq); } +#if !defined(_WIN32) static int isATTY(FILE* fp) { int ret = 0; -#if !defined(_WIN32) const char* term = getenv("TERM"); int fd = fileno(fp); @@ -222,10 +227,34 @@ int isATTY(FILE* fp) /* only attempt to use ANSI escapes if some terminal type is specified */ if(ret && (!term || !term[0])) ret = 0; -#endif return ret; } +#else /* _WIN32 */ +static +int isATTY(FILE* fp) +{ + HANDLE hand = NULL; + DWORD mode = 0; + if(fp==stdout) + hand = GetStdHandle(STD_OUTPUT_HANDLE); + else if(fp==stderr) + hand = GetStdHandle(STD_ERROR_HANDLE); +#ifdef ENABLE_VIRTUAL_TERMINAL_PROCESSING + if(hand && GetConsoleMode(hand, &mode)) { + (void)SetConsoleMode(hand, mode|ENABLE_VIRTUAL_TERMINAL_PROCESSING); + mode = 0u; + if(GetConsoleMode(hand, &mode) && (mode&ENABLE_VIRTUAL_TERMINAL_PROCESSING)) + return 1; + } +#else + (void)hand; + (void)mode; +#endif + return 0; +} +#endif + /* in-place removal of ANSI terminal escape sequences. * exported for use by unit-test only */