Skip to content

Commit

Permalink
packager: terminal: split status too big to fit in screen
Browse files Browse the repository at this point in the history
Reviewed By: cpojer

Differential Revision: D4627512

fbshipit-source-id: 6e7b5f3a6e2d012a44373014f93ab17ef4f290a2
  • Loading branch information
Jean Lauliac authored and facebook-github-bot committed Feb 28, 2017
1 parent 1744639 commit 2030b6b
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packager/src/lib/terminal.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ function clearStringBackwards(stream: tty.WriteStream, str: string): void {
}
}

/**
* Cut a string into an array of string of the specific maximum size. A newline
* ends a chunk immediately (it's not included in the "." RexExp operator), and
* is not included in the result.
*/
function chunkString(str: string, size: number): Array<string> {
return str.match(new RegExp(`.{1,${size}}`, 'g')) || [];
}

/**
* We don't just print things to the console, sometimes we also want to show
* and update progress. This utility just ensures the output stays neat: no
Expand Down Expand Up @@ -78,6 +87,7 @@ class Terminal {
const {_statusStr, _stream} = this;
if (_statusStr !== str && _stream instanceof tty.WriteStream) {
clearStringBackwards(_stream, _statusStr);
str = chunkString(str, _stream.columns).join('\n');
_stream.write(str);
}
this._statusStr = str;
Expand Down

0 comments on commit 2030b6b

Please sign in to comment.