helpers to potentially support node <=0.6.0.

This commit is contained in:
Christopher Jeffrey 2015-07-30 23:07:23 -07:00
parent b0d0063b1c
commit 103ce24787

View File

@ -156,3 +156,40 @@ helpers.__defineGetter__('Element', function() {
}
return helpers._element;
});
// NOTE: Leave these here for now if we
// want to potentially support node <=v0.6.0.
helpers.isTTY = function(stream) {
if (stream.setRawMode || stream.isTTY) {
return true;
}
if (stream === process.stdin) {
return true;
}
// if (stream.fd != null) {
// return require('tty').isatty(stream.fd);
// }
return false;
};
helpers.setRawMode = function(stream, value) {
if (stream.setRawMode) {
return stream.setRawMode(value);
}
if (stream === process.stdin) {
helpers._isRaw = value;
return require('tty').setRawMode(value);
}
throw new Error('Could not set raw mode.');
};
helpers.isRaw = function(stream) {
if (stream.isRaw != null) {
return stream.isRaw;
}
if (stream === process.stdin) {
return !!helpers._isRaw;
}
throw new Error('Could not check raw mode.');
};