add uv_tty_reset_mode()
This commit is contained in:
parent
153d3c7c57
commit
fe18438416
@ -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. */
|
||||
;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user