Skip to content

Instantly share code, notes, and snippets.

@ry
Created September 14, 2011 21:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ry/1217871 to your computer and use it in GitHub Desktop.
Save ry/1217871 to your computer and use it in GitHub Desktop.
diff --git a/include/uv.h b/include/uv.h
index bf7e88a..4741616 100644
--- a/include/uv.h
+++ b/include/uv.h
@@ -600,6 +600,11 @@ 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);
/*
diff --git a/src/unix/tty.c b/src/unix/tty.c
index 3ceeb5f..9de7dd9 100644
--- a/src/unix/tty.c
+++ b/src/unix/tty.c
@@ -67,3 +67,7 @@ fatal:
return -1;
}
+
+int uv_is_tty(uv_file file) {
+ return isatty(file);
+}
diff --git a/src/win/tty.c b/src/win/tty.c
index 5498eec..c451a99 100644
--- a/src/win/tty.c
+++ b/src/win/tty.c
@@ -35,3 +35,10 @@ int uv_tty_set_mode(uv_tty_t* tty, int mode) {
assert(0 && "implement me");
return -1;
}
+
+
+int uv_is_tty(uv_file file) {
+ DWORD result;
+ int r = GetConsoleMode((HANDLE)_get_osfhandle(file), &result);
+ return r ? 1 : 0;
+}
diff --git a/test/test-list.h b/test/test-list.h
index 5f1100c..168a6ef 100644
--- a/test/test-list.h
+++ b/test/test-list.h
@@ -19,6 +19,7 @@
* IN THE SOFTWARE.
*/
+TEST_DECLARE (tty)
TEST_DECLARE (tcp_ping_pong)
TEST_DECLARE (tcp_ping_pong_v6)
TEST_DECLARE (pipe_ping_pong)
@@ -97,6 +98,8 @@ HELPER_DECLARE (pipe_echo_server)
TASK_LIST_START
+ TEST_ENTRY (tty)
+
TEST_ENTRY (tcp_ping_pong)
TEST_HELPER (tcp_ping_pong, tcp4_echo_server)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment