diff options
author | Tom Smeding <tom.smeding@gmail.com> | 2018-02-08 22:22:17 +0100 |
---|---|---|
committer | Tom Smeding <tom.smeding@gmail.com> | 2018-02-08 22:22:17 +0100 |
commit | 9307136fb81cde270f5c1e192a3aa5dc307c8dfe (patch) | |
tree | 869faa3026fa2f23e1d193e136639cdfa340fcce | |
parent | 1237adca87e5bbd97ce50a53eafd64baad2ea686 (diff) |
Be resistant against terminal resize
-rw-r--r-- | main.c | 36 |
1 files changed, 22 insertions, 14 deletions
@@ -7,6 +7,7 @@ #include <sys/select.h> #include <sys/time.h> #include <unistd.h> +#include <errno.h> #include <assert.h> #include "termio.h" @@ -181,7 +182,6 @@ int main(void){ atexit(endkeyboard); initscreen(); atexit(endscreen); - installCLhandler(true); cursorvisible(false); struct board bd; @@ -208,7 +208,15 @@ int main(void){ memcpy(&timeout,&timeleft,sizeof timeout); int ret=select(1,&inset,NULL,NULL,&timeout); - assert(ret>=0); + if(ret<0){ + if(errno!=EINTR){ + endscreen(); + perror("select"); + exit(1); + } else { + FD_ZERO(&inset); + } + } struct timeval end; gettimeofday(&end,NULL); @@ -237,18 +245,18 @@ int main(void){ } } - assert(FD_ISSET(0,&inset)); - - int key=tgetkey(); - if(key=='Q'||key=='q')break; - else if(key=='S'||key=='s'||key==KEY_DOWN){ - if(!advance(&bd))break; - timeleft.tv_sec=bd.delay/1000; - timeleft.tv_usec=bd.delay%1000*1000; - } else if(key=='A'||key=='a'||key==KEY_LEFT)move(&bd,-1); - else if(key=='D'||key=='d'||key==KEY_RIGHT)move(&bd,1); - else if(key=='W'||key=='w'||key==KEY_UP)rotR(&bd); - else bel(); + if(FD_ISSET(0,&inset)){ + int key=tgetkey(); + if(key=='Q'||key=='q')break; + else if(key=='S'||key=='s'||key==KEY_DOWN){ + if(!advance(&bd))break; + timeleft.tv_sec=bd.delay/1000; + timeleft.tv_usec=bd.delay%1000*1000; + } else if(key=='A'||key=='a'||key==KEY_LEFT)move(&bd,-1); + else if(key=='D'||key=='d'||key==KEY_RIGHT)move(&bd,1); + else if(key=='W'||key=='w'||key==KEY_UP)rotR(&bd); + else bel(); + } } endscreen(); |