rvis | Minimal terminal colorizer. |
| download: https://git.y1.nz/archives/rvis.tar.gz | |
| README | Files | Log | Refs |
term.c
1
2 #include <stdio.h>
3 #include <termios.h>
4 #include <unistd.h>
5 #include <ctype.h>
6
7 #define RESPONSE_SIZE 10
8
9 int
10 get_root_size(int *x, int *y)
11 {
12 struct termios termios0, termios1;
13 char response[RESPONSE_SIZE] = "";
14 int index = 0;
15 int ch = 0;
16 int result;
17
18 tcgetattr(STDIN_FILENO, &termios0);
19 termios1 = termios0;
20 termios1.c_lflag &= ~(ICANON | ECHO);
21 termios1.c_cc[VMIN] = 1;
22 termios1.c_cc[VTIME] = 0;
23 tcsetattr(STDIN_FILENO, TCSANOW, &termios1);
24
25 /* move down/right until end of screen */
26 printf("\033[9999B" "\033[9999C");
27 fflush(stdout);
28
29 /* query cursor position */
30 printf("\033[6n");
31 fflush(stdout);
32
33 for (;;) {
34 ch = getchar();
35 if (ch == 'R' || ch == EOF || index >= RESPONSE_SIZE) break;
36 if (!isprint(ch)) continue;
37 response[index++] = ch;
38 }
39 response[index] = '\0';
40
41 result = sscanf(response, "[%d;%d", y, x);
42
43 /* move cursor to top-left of screen */
44 printf("\033[1;1H");
45
46 tcsetattr(STDIN_FILENO, TCSANOW, &termios0);
47
48 return result == 2;
49 }
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.