summaryrefslogtreecommitdiff
path: root/src/tty_wrap.cc
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2011-09-22 22:00:00 -0700
committerRyan Dahl <ry@tinyclouds.org>2011-09-27 13:03:28 -0700
commit1de156abb10e646c05485d95dfce6d1805514822 (patch)
treeb59efc5c83be08062b5202dd257da4dabbfd9506 /src/tty_wrap.cc
parent74b6426ec657aaa36bd3a6beab3f5723006a7ea0 (diff)
downloadandroid-node-v8-1de156abb10e646c05485d95dfce6d1805514822.tar.gz
android-node-v8-1de156abb10e646c05485d95dfce6d1805514822.tar.bz2
android-node-v8-1de156abb10e646c05485d95dfce6d1805514822.zip
Bind/use uv_guess_handle
Diffstat (limited to 'src/tty_wrap.cc')
-rw-r--r--src/tty_wrap.cc26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/tty_wrap.cc b/src/tty_wrap.cc
index 3c85aaeb07..0d3e037068 100644
--- a/src/tty_wrap.cc
+++ b/src/tty_wrap.cc
@@ -54,11 +54,37 @@ class TTYWrap : StreamWrap {
NODE_SET_PROTOTYPE_METHOD(t, "setRawMode", SetRawMode);
NODE_SET_METHOD(target, "isTTY", IsTTY);
+ NODE_SET_METHOD(target, "guessHandleType", GuessHandleType);
target->Set(String::NewSymbol("TTY"), t->GetFunction());
}
private:
+ static Handle<Value> GuessHandleType(const Arguments& args) {
+ HandleScope scope;
+ int fd = args[0]->Int32Value();
+ assert(fd >= 0);
+
+ uv_handle_type t = uv_guess_handle(fd);
+
+ switch (t) {
+ case UV_TTY:
+ return String::New("TTY");
+
+ case UV_NAMED_PIPE:
+ return String::New("PIPE");
+
+ case UV_FILE:
+ return String::New("FILE");
+
+ default:
+ assert(0);
+ return v8::Undefined();
+ }
+ return uv_is_tty(fd) ? v8::True() : v8::False();
+
+ }
+
static Handle<Value> IsTTY(const Arguments& args) {
HandleScope scope;
int fd = args[0]->Int32Value();