mirror of
https://github.com/alrayyes/st.git
synced 2024-11-22 03:16:22 +00:00
add select(2)-based i/o multiplexing
This commit is contained in:
parent
a49919a10c
commit
f9a0524f94
1 changed files with 19 additions and 7 deletions
12
std.c
12
std.c
|
@ -263,13 +263,23 @@ 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(;;) {
|
||||
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':
|
||||
|
@ -278,6 +288,8 @@ main(int argc, char *argv[]) {
|
|||
default:
|
||||
putchar(c);
|
||||
}
|
||||
fflush(stdout);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue