From 5b2644cafc8a619b617ba0fbb5473667dbd634ba Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Thu, 14 May 2015 13:43:01 -0500 Subject: Promote reset (actually write a new one using the simple man 4 console_codes terminal reset escape sequence) and add gettty() function to lib so terminal gets reset even when we redirect stdout/stderr. (This is apparently the expected behavior.) --- lib/interestingtimes.c | 9 +++++++++ lib/lib.h | 1 + 2 files changed, 10 insertions(+) (limited to 'lib') diff --git a/lib/interestingtimes.c b/lib/interestingtimes.c index cea5039f..85b8eb4c 100644 --- a/lib/interestingtimes.c +++ b/lib/interestingtimes.c @@ -5,6 +5,15 @@ #include "toys.h" +int xgettty(void) +{ + int i, j; + + for (i = 0; i<3; i++) if (isatty(j = (i+1)%3)) return j; + + return xopen("/dev/tty", O_RDWR); +} + // Quick and dirty query size of terminal, doesn't do ANSI probe fallback. // set x=80 y=25 before calling to provide defaults. Returns 0 if couldn't // determine size. diff --git a/lib/lib.h b/lib/lib.h index 03a05703..54876b6a 100644 --- a/lib/lib.h +++ b/lib/lib.h @@ -181,6 +181,7 @@ int qstrcmp(const void *a, const void *b); int xpoll(struct pollfd *fds, int nfds, int timeout); // interestingtimes.c +int xgettty(void); int terminal_size(unsigned *xx, unsigned *yy); int set_terminal(int fd, int raw, struct termios *old); int scan_key(char *scratch, char **seqs, int block); -- cgit v1.2.3