tty.js 758 B

12345678910111213141516171819202122
  1. // workaround for tty output truncation on Node.js
  2. try {
  3. // prevent buffer overflow and other asynchronous bugs
  4. process.stdout._handle.setBlocking(true);
  5. process.stderr._handle.setBlocking(true);
  6. } catch (e) {
  7. // ensure output buffers are flushed before process termination
  8. var exit = process.exit;
  9. process.exit = function() {
  10. var args = [].slice.call(arguments);
  11. process.once("uncaughtException", function() {
  12. (function callback() {
  13. if (process.stdout.bufferSize || process.stderr.bufferSize) {
  14. setTimeout(callback, 1);
  15. } else {
  16. exit.apply(process, args);
  17. }
  18. })();
  19. });
  20. throw exit;
  21. };
  22. }