Skip to content

Commit

Permalink
Fixes progress display on non-color tty (#4647) (#4697)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nwholloway authored and arcanis committed Oct 12, 2017
1 parent f5e78eb commit 4c38ca7
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/reporters/console/util.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* @flow */

import tty from 'tty';
import type {Stdout} from '../types.js';

const readline = require('readline');
Expand All @@ -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;
}

Expand All @@ -19,6 +23,7 @@ export function clearLine(stdout: Stdout) {

export function toStartOfLine(stdout: Stdout) {
if (!supportsColor) {
stdout.write('\r');
return;
}

Expand Down

0 comments on commit 4c38ca7

Please sign in to comment.