From 03d0c57ea216abd611286ff1e58d4e344a459f76 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Fri, 23 Sep 2011 10:01:45 -0700 Subject: [PATCH] Remove uv_is_tty. Use uv_guess_handle instead. --- include/uv.h | 6 +----- src/unix/tty.c | 5 ----- src/win/tty.c | 11 ++++++++--- test/test-tty.c | 4 +--- 4 files changed, 10 insertions(+), 16 deletions(-) diff --git a/include/uv.h b/include/uv.h index 014ea96e5..b8bdc0930 100644 --- a/include/uv.h +++ b/include/uv.h @@ -612,11 +612,6 @@ struct uv_tty_s { UV_TTY_PRIVATE_FIELDS }; -/* - * Returns 1 if file is associated with a Console/TTY 0 otherwise. - */ -int uv_is_tty(uv_file file); - int uv_tty_init(uv_loop_t*, uv_tty_t*, uv_file fd); /* @@ -633,6 +628,7 @@ int uv_tty_get_winsize(uv_tty_t*, int* width, int* height); * Used to detect what type of stream should be used with a given file * descriptor. Usually this will be used during initialization to guess the * type of the stdio streams. + * For isatty() functionality use this function and test for UV_TTY. */ uv_handle_type uv_guess_handle(uv_file file); diff --git a/src/unix/tty.c b/src/unix/tty.c index 8e2bee6c7..989c09d1b 100644 --- a/src/unix/tty.c +++ b/src/unix/tty.c @@ -70,11 +70,6 @@ fatal: } -int uv_is_tty(uv_file file) { - return isatty(file); -} - - int uv_tty_get_winsize(uv_tty_t* tty, int* width, int* height) { struct winsize ws; diff --git a/src/win/tty.c b/src/win/tty.c index dc477c76c..a4a468296 100644 --- a/src/win/tty.c +++ b/src/win/tty.c @@ -38,9 +38,6 @@ int uv_tty_set_mode(uv_tty_t* tty, int mode) { int uv_is_tty(uv_file file) { - DWORD result; - int r = GetConsoleMode((HANDLE)_get_osfhandle(file), &result); - return r ? 1 : 0; } @@ -51,6 +48,14 @@ int uv_tty_get_winsize(uv_tty_t* tty, int* width, int* height) { uv_handle_type uv_guess_handle(uv_file file) { + DWORD result; + int r = GetConsoleMode((HANDLE)_get_osfhandle(file), &result); + + if (r) { + return UV_TTY; + } + assert(0 && "implement me"); + return UV_UNKNOWN_HANDLE; } diff --git a/test/test-tty.c b/test/test-tty.c index f41c5e543..11816156f 100644 --- a/test/test-tty.c +++ b/test/test-tty.c @@ -31,13 +31,11 @@ TEST_IMPL(tty) { * Not necessarally a problem if this assert goes off. E.G you are piping * this test to a file. 0 == stdin. */ - ASSERT(uv_is_tty(0) == 1); + ASSERT(UV_TTY == uv_guess_handle(0)); r = uv_tty_init(uv_default_loop(), &tty, 0); ASSERT(r == 0); - ASSERT(UV_TTY == uv_guess_handle(0)); - r = uv_tty_get_winsize(&tty, &width, &height); ASSERT(r == 0);