#include "toys.h"
-int xgettty(void)
+int tty_fd(void)
{
int i, j;
for (i = 0; i<3; i++) if (isatty(j = (i+1)%3)) return j;
- return xopen("/dev/tty", O_RDWR);
+ return notstdio(open("/dev/tty", O_RDWR));
}
// Quick and dirty query size of terminal, doesn't do ANSI probe fallback.
int draw_trim(char *str, int padto, int width);
// interestingtimes.c
-int xgettty(void);
+int tty_fd(void);
int terminal_size(unsigned *xx, unsigned *yy);
int terminal_probesize(unsigned *xx, unsigned *yy);
int scan_key_getsize(char *scratch, int miliwait, unsigned *xx, unsigned *yy);
void reset_main(void)
{
- // man 4 console codes: reset terminal is ESC (no left bracket) c
- xwrite(xgettty(), "\033c", 2);
+ int fd = tty_fd();
+
+ // man 4 console_codes: reset terminal is ESC (no left bracket) c
+ xwrite(fd<0 ? 1 : fd, "\033c", 2);
}