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

Commit

Permalink
add uv_tty_reset_mode()
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Sep 30, 2011
1 parent 153d3c7 commit fe18438
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
6 changes: 6 additions & 0 deletions include/uv.h
Expand Up @@ -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.
*/
Expand Down
17 changes: 17 additions & 0 deletions src/unix/tty.c
Expand Up @@ -29,6 +29,10 @@
#include <sys/ioctl.h>


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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
}
6 changes: 6 additions & 0 deletions src/win/tty.c
Expand Up @@ -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. */
;
}

0 comments on commit fe18438

Please sign in to comment.