0001
0002 #include "term.h"
0003 #include <stdlib.h>
0004 #include <termios.h>
0005 #include <unistd.h>
0006 #include <sys/ioctl.h>
0007
0008 void get_term_dimensions(struct winsize *ws)
0009 {
0010 char *s = getenv("LINES");
0011
0012 if (s != NULL) {
0013 ws->ws_row = atoi(s);
0014 s = getenv("COLUMNS");
0015 if (s != NULL) {
0016 ws->ws_col = atoi(s);
0017 if (ws->ws_row && ws->ws_col)
0018 return;
0019 }
0020 }
0021 #ifdef TIOCGWINSZ
0022 if (ioctl(1, TIOCGWINSZ, ws) == 0 &&
0023 ws->ws_row && ws->ws_col)
0024 return;
0025 #endif
0026 ws->ws_row = 25;
0027 ws->ws_col = 80;
0028 }
0029
0030 void set_term_quiet_input(struct termios *old)
0031 {
0032 struct termios tc;
0033
0034 tcgetattr(0, old);
0035 tc = *old;
0036 tc.c_lflag &= ~(ICANON | ECHO);
0037 tc.c_cc[VMIN] = 0;
0038 tc.c_cc[VTIME] = 0;
0039 tcsetattr(0, TCSANOW, &tc);
0040 }