From c7dabf041a24f5c3e48c774c87b64a832310c837 Mon Sep 17 00:00:00 2001 From: Richard Lau Date: Wed, 22 May 2019 21:24:24 +0100 Subject: [PATCH] lib: use console.log for TTY on Windows ANSI sequences are emulated on Windows, so use `console.log()` for TTY's on Windows instead of directly writing to the filedescriptor. Fixes: https://github.com/nodejs/node/issues/27819 --- lib/internal/util/print.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/internal/util/print.js b/lib/internal/util/print.js index 4c9327502ebad2..d3f9f7c0cc9f7f 100644 --- a/lib/internal/util/print.js +++ b/lib/internal/util/print.js @@ -41,7 +41,12 @@ function getColors() { function print(fd, obj, ignoreErrors = true) { switch (getFdType(fd)) { case 'TTY': - formatAndWrite(fd, obj, ignoreErrors, getColors()); + // Fallback to console.log to handle ANSI codes on Windows. + if (process.platform === 'win32') { + log(obj); + } else { + formatAndWrite(fd, obj, ignoreErrors, getColors()); + } break; case 'FILE': formatAndWrite(fd, obj, ignoreErrors);