From fe184384161ae5dd32e973529187a486358882c8 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Fri, 30 Sep 2011 13:07:14 -0700 Subject: [PATCH] add uv_tty_reset_mode() --- include/uv.h | 6 ++++++ src/unix/tty.c | 17 +++++++++++++++++ src/win/tty.c | 6 ++++++ 3 files changed, 29 insertions(+) diff --git a/include/uv.h b/include/uv.h index b8bdc0930..348abe3f6 100644 --- a/include/uv.h +++ b/include/uv.h @@ -619,6 +619,12 @@ int uv_tty_init(uv_loop_t*, uv_tty_t*, uv_file fd); */ int uv_tty_set_mode(uv_tty_t*, int mode); +/* + * To be called when the program exits. Resets TTY settings to default + * values for the next process to take over. + */ +void uv_tty_reset_mode(); + /* * Gets the current Window size. On success zero is returned. */ diff --git a/src/unix/tty.c b/src/unix/tty.c index 0bc492c14..3d074bf48 100644 --- a/src/unix/tty.c +++ b/src/unix/tty.c @@ -29,6 +29,10 @@ #include +static int orig_termios_fd = -1; +static struct termios orig_termios; + + int uv_tty_init(uv_loop_t* loop, uv_tty_t* tty, int fd) { uv__nonblock(fd, 1); uv__stream_init(loop, (uv_stream_t*)tty, UV_TTY); @@ -50,6 +54,12 @@ int uv_tty_set_mode(uv_tty_t* tty, int mode) { goto fatal; } + /* This is used for uv_tty_reset_mode() */ + if (orig_termios_fd == -1) { + orig_termios = tty->orig_termios; + orig_termios_fd = fd; + } + raw = tty->orig_termios; raw.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON); raw.c_oflag |= (ONLCR); @@ -121,3 +131,10 @@ uv_handle_type uv_guess_handle(uv_file file) { return UV_NAMED_PIPE; } + + +void uv_tty_reset_mode() { + if (orig_termios_fd >= 0) { + tcsetattr(orig_termios_fd, TCSANOW, &orig_termios); + } +} diff --git a/src/win/tty.c b/src/win/tty.c index 1b7056144..b989bebe0 100644 --- a/src/win/tty.c +++ b/src/win/tty.c @@ -1589,3 +1589,9 @@ void uv_process_tty_connect_req(uv_loop_t* loop, uv_tty_t* handle, uv_connect_t* req) { abort(); } + + +void uv_tty_reset_mode() { + /* Not necessary to do anything. */ + ; +}