Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

add uv_tty_reset_mode()

  • Loading branch information...
ry committed Sep 30, 2011
1 parent 153d3c7 commit fe184384161ae5dd32e973529187a486358882c8
Showing with 29 additions and 0 deletions.
  1. +6 −0 include/uv.h
  2. +17 −0 src/unix/tty.c
  3. +6 −0 src/win/tty.c
@@ -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.
*/
@@ -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);
@@ -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);
}
}
@@ -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.
You can’t perform that action at this time.