st

Simple Terminal
git clone git://r-36.net/st
Log | Files | Refs | README | LICENSE

commit f9a0524f9430147a3e4a0d200cb3bbd54d1448a4
parent a49919a10c11c141f1bfb8414d5c8d2ca9d4a90e
Author: Matthias-Christian Ott <ott@enolink.de>
Date:   Sat, 14 Jun 2008 23:24:12 +0200

add select(2)-based i/o multiplexing

Diffstat:
std.c | 26+++++++++++++++++++-------
1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/std.c b/std.c @@ -263,20 +263,32 @@ ungetch(int c) { int main(int argc, char *argv[]) { + fd_set rfds; + int r; + if(argc == 2 && !strcmp("-v", argv[1])) eprint("std-"VERSION", © 2008 Matthias-Christian Ott\n"); else if(argc == 1) eprint("usage: st [-v]\n"); getpty(); shell(); + FD_ZERO(&rfds); + FD_SET(STDIN_FILENO, &rfds); + FD_SET(ptm, &rfds); for(;;) { - c = getch(); - switch(c) { - case '\033': - parseesc(); - break; - default: - putchar(c); + r = select(ptm + 1, &rfds, NULL, NULL, NULL); + if(r == -1) + eprintn("error, cannot select"); + if(FD_ISSET(ptm, &rfds)) { + c = getch(); + switch(c) { + case '\033': + parseesc(); + break; + default: + putchar(c); + } + fflush(stdout); } } return 0;