Arnaldo Carvalho de Melo | b0742e9 | 2017-04-18 11:08:10 -0300 | [diff] [blame] | 1 | #include "term.h" |
| 2 | #include <stdlib.h> |
| 3 | #include <termios.h> |
| 4 | #include <unistd.h> |
| 5 | #include <sys/ioctl.h> |
Josh Poimboeuf | 1fe143c | 2015-12-07 22:21:42 -0600 | [diff] [blame] | 6 | |
| 7 | void get_term_dimensions(struct winsize *ws) |
| 8 | { |
| 9 | char *s = getenv("LINES"); |
| 10 | |
| 11 | if (s != NULL) { |
| 12 | ws->ws_row = atoi(s); |
| 13 | s = getenv("COLUMNS"); |
| 14 | if (s != NULL) { |
| 15 | ws->ws_col = atoi(s); |
| 16 | if (ws->ws_row && ws->ws_col) |
| 17 | return; |
| 18 | } |
| 19 | } |
| 20 | #ifdef TIOCGWINSZ |
| 21 | if (ioctl(1, TIOCGWINSZ, ws) == 0 && |
| 22 | ws->ws_row && ws->ws_col) |
| 23 | return; |
| 24 | #endif |
| 25 | ws->ws_row = 25; |
| 26 | ws->ws_col = 80; |
| 27 | } |
| 28 | |
| 29 | void set_term_quiet_input(struct termios *old) |
| 30 | { |
| 31 | struct termios tc; |
| 32 | |
| 33 | tcgetattr(0, old); |
| 34 | tc = *old; |
| 35 | tc.c_lflag &= ~(ICANON | ECHO); |
| 36 | tc.c_cc[VMIN] = 0; |
| 37 | tc.c_cc[VTIME] = 0; |
| 38 | tcsetattr(0, TCSANOW, &tc); |
| 39 | } |