10 static struct sbuf
*term_sbuf
;
11 static int rows
, cols
;
12 static struct termios termios
;
17 struct termios newtermios
;
18 tcgetattr(0, &termios
);
20 newtermios
.c_lflag
&= ~(ICANON
| ISIG
);
21 newtermios
.c_lflag
&= ~ECHO
;
22 tcsetattr(0, TCSAFLUSH
, &newtermios
);
24 rows
= atoi(getenv("LINES"));
25 if (getenv("COLUMNS"))
26 cols
= atoi(getenv("COLUMNS"));
27 if (!ioctl(0, TIOCGWINSZ
, &win
)) {
28 cols
= cols
? cols
: win
.ws_col
;
29 rows
= rows
? rows
: win
.ws_row
;
31 cols
= cols
? cols
: 80;
32 rows
= rows
? rows
: 25;
38 tcsetattr(0, 0, &termios
);
41 void term_record(void)
44 term_sbuf
= sbuf_make();
47 void term_commit(void)
50 write(1, sbuf_buf(term_sbuf
), sbuf_len(term_sbuf
));
56 static void term_out(char *s
)
59 sbuf_str(term_sbuf
, s
);
61 write(1, s
, strlen(s
));
64 void term_str(char *s
)
80 void term_pos(int r
, int c
)
88 sprintf(buf
, "\r\33[%d%c", abs(c
), c
> 0 ? 'C' : 'D');
90 sprintf(buf
, "\33[%d;%dH", r
+ 1, c
+ 1);
104 int term_read(int ms
)
106 struct pollfd ufds
[1];
109 ufds
[0].events
= POLLIN
;
110 if (poll(ufds
, 1, ms
* 1000) <= 0)
112 if (read(0, &b
, 1) <= 0)
114 return (unsigned char) b
;