xref: /linux/tools/perf/util/term.c (revision 2fe05e1139a555ae91f00a812cb9520e7d3022ab)
1 #include "term.h"
2 #include <stdlib.h>
3 #include <termios.h>
4 #include <unistd.h>
5 #include <sys/ioctl.h>
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 }
40