mirror of https://github.com/status-im/metro.git
packager: verify validity of TTY before using it
Reviewed By: mkonicek Differential Revision: D4689779 fbshipit-source-id: 9bc2c1447bd64ec392adef772b1189a782f83545
This commit is contained in:
parent
da94f5e5af
commit
4e106d45c3
|
@ -41,6 +41,20 @@ function chunkString(str: string, size: number): Array<string> {
|
||||||
return str.match(new RegExp(`.{1,${size}}`, 'g')) || [];
|
return str.match(new RegExp(`.{1,${size}}`, 'g')) || [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the stream as a TTY if it effectively looks like a valid TTY.
|
||||||
|
*/
|
||||||
|
function getTTYStream(stream: net$Socket): ?tty.WriteStream {
|
||||||
|
if (
|
||||||
|
stream instanceof tty.WriteStream &&
|
||||||
|
stream.isTTY &&
|
||||||
|
stream.columns >= 1
|
||||||
|
) {
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* We don't just print things to the console, sometimes we also want to show
|
* 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
|
* and update progress. This utility just ensures the output stays neat: no
|
||||||
|
@ -93,19 +107,20 @@ class Terminal {
|
||||||
*/
|
*/
|
||||||
_update(): void {
|
_update(): void {
|
||||||
const {_statusStr, _stream} = this;
|
const {_statusStr, _stream} = this;
|
||||||
|
const ttyStream = getTTYStream(_stream);
|
||||||
if (_statusStr === this._nextStatusStr && this._logLines.length === 0) {
|
if (_statusStr === this._nextStatusStr && this._logLines.length === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (_stream instanceof tty.WriteStream) {
|
if (ttyStream != null) {
|
||||||
clearStringBackwards(_stream, _statusStr);
|
clearStringBackwards(ttyStream, _statusStr);
|
||||||
}
|
}
|
||||||
this._logLines.forEach(line => {
|
this._logLines.forEach(line => {
|
||||||
_stream.write(line);
|
_stream.write(line);
|
||||||
_stream.write('\n');
|
_stream.write('\n');
|
||||||
});
|
});
|
||||||
this._logLines = [];
|
this._logLines = [];
|
||||||
if (_stream instanceof tty.WriteStream) {
|
if (ttyStream != null) {
|
||||||
this._nextStatusStr = chunkString(this._nextStatusStr, _stream.columns).join('\n');
|
this._nextStatusStr = chunkString(this._nextStatusStr, ttyStream.columns).join('\n');
|
||||||
_stream.write(this._nextStatusStr);
|
_stream.write(this._nextStatusStr);
|
||||||
}
|
}
|
||||||
this._statusStr = this._nextStatusStr;
|
this._statusStr = this._nextStatusStr;
|
||||||
|
|
Loading…
Reference in New Issue