From 0b5bf70bff86ce393de1a91d75e547a7a1feb34f Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Mon, 17 Jan 2011 23:28:54 +0100 Subject: [PATCH] Use tty.ReadStream and tty.WriteStream for stdio when appropriate --- lib/readline.js | 2 +- src/node.js | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/readline.js b/lib/readline.js index c85d2410ad6..bb22feb7856 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -27,7 +27,7 @@ function Interface(output, completer) { this.setPrompt('> '); - this.enabled = tty.isatty(output.fd); + this.enabled = output.isTTY; if (parseInt(process.env['NODE_NO_READLINE'], 10)) { this.enabled = false; diff --git a/src/node.js b/src/node.js index 413c4de4641..345bfb494af 100644 --- a/src/node.js +++ b/src/node.js @@ -554,9 +554,12 @@ var binding = process.binding('stdio'), net = NativeModule.require('net'), fs = NativeModule.require('fs'), + tty = NativeModule.require('tty'), fd = binding.stdoutFD; - if (binding.isStdoutBlocking()) { + if (binding.isatty(fd)) { + stdout = new tty.WriteStream(fd); + } else if (binding.isStdoutBlocking()) { stdout = new fs.WriteStream(null, {fd: fd}); } else { stdout = new net.Stream(fd); @@ -577,9 +580,12 @@ var binding = process.binding('stdio'), net = NativeModule.require('net'), fs = NativeModule.require('fs'), + tty = NativeModule.require('tty'), fd = binding.openStdin(); - if (binding.isStdinBlocking()) { + if (binding.isatty(fd)) { + stdin = new tty.ReadStream(fd); + } else if (binding.isStdinBlocking()) { stdin = new fs.ReadStream(null, {fd: fd}); } else { stdin = new net.Stream(fd);