blob: 8f254a74d97deed4abc357d2d527ff1453a7c4f1 [file] [log] [blame]
Arnaldo Carvalho de Melob0742e92017-04-18 11:08:10 -03001#include "term.h"
2#include <stdlib.h>
3#include <termios.h>
4#include <unistd.h>
5#include <sys/ioctl.h>
Josh Poimboeuf1fe143c2015-12-07 22:21:42 -06006
7void 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
29void 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}