Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
Add uv_is_tty()
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Sep 20, 2011
1 parent 6beeb5f commit c1374ba
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 0 deletions.
5 changes: 5 additions & 0 deletions include/uv.h
Expand Up @@ -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);

/*
Expand Down
4 changes: 4 additions & 0 deletions src/unix/tty.c
Expand Up @@ -67,3 +67,7 @@ int uv_tty_set_mode(uv_tty_t* tty, int mode) {
return -1;
}


int uv_is_tty(uv_file file) {
return isatty(file);
}
7 changes: 7 additions & 0 deletions src/win/tty.c
Expand Up @@ -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;
}
3 changes: 3 additions & 0 deletions test/test-list.h
Expand Up @@ -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)
Expand Down Expand Up @@ -98,6 +99,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)

Expand Down
33 changes: 33 additions & 0 deletions test/test-tty.c
@@ -0,0 +1,33 @@
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/

#include "uv.h"
#include "task.h"

TEST_IMPL(tty) {
uv_loop_t* loop = uv_default_loop();

ASSERT(uv_is_tty(0) == 1);

uv_run(loop);

return 0;
}

0 comments on commit c1374ba

Please sign in to comment.