From 4c38ca7771922d5d56dac91f4be6e69a4d8d7885 Mon Sep 17 00:00:00 2001 From: Nick Holloway Date: Thu, 12 Oct 2017 15:54:08 +0100 Subject: [PATCH] Fixes progress display on non-color tty (#4647) (#4697) If the output does not support color, then each render of the progress bar is added to a single line, which wraps over multiple lines. As a fallback, a simple carriage return is used to move to the start of the line, and space characters to clear the line. --- src/reporters/console/util.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/reporters/console/util.js b/src/reporters/console/util.js index 668566aab2..e38a5dc1a1 100644 --- a/src/reporters/console/util.js +++ b/src/reporters/console/util.js @@ -1,5 +1,6 @@ /* @flow */ +import tty from 'tty'; import type {Stdout} from '../types.js'; const readline = require('readline'); @@ -10,6 +11,9 @@ const CLEAR_RIGHT_OF_CURSOR = 1; export function clearLine(stdout: Stdout) { if (!supportsColor) { + if (stdout instanceof tty.WriteStream) { + stdout.write(`\r${' '.repeat(stdout.columns - 1)}\r`); + } return; } @@ -19,6 +23,7 @@ export function clearLine(stdout: Stdout) { export function toStartOfLine(stdout: Stdout) { if (!supportsColor) { + stdout.write('\r'); return; }