diff options
author | Paul LeoNerd Evans <leonerd@leonerd.org.uk> | 2011-08-18 11:20:41 +0100 |
---|---|---|
committer | Paul LeoNerd Evans <leonerd@leonerd.org.uk> | 2011-08-18 11:20:41 +0100 |
commit | 7a2b79a6402979b4895e78657d59a770d5b082b3 (patch) | |
tree | 06105525116545218b02d5b995d80f451f8e3536 /demo.c | |
parent | 01e5795098bea0fecb29e69e702225cb236dd6f8 (diff) | |
download | termo-7a2b79a6402979b4895e78657d59a770d5b082b3.tar.gz termo-7a2b79a6402979b4895e78657d59a770d5b082b3.tar.xz termo-7a2b79a6402979b4895e78657d59a770d5b082b3.zip |
Provide a new result value, TERMKEY_RES_ERROR to indicate an IO error - preserve errno
Diffstat (limited to 'demo.c')
-rw-r--r-- | demo.c | 22 |
1 files changed, 16 insertions, 6 deletions
@@ -1,5 +1,6 @@ #include <stdio.h> #include <getopt.h> +#include <errno.h> #include "termkey.h" @@ -44,13 +45,22 @@ int main(int argc, char *argv[]) printf("\e[?%dhMouse mode active\n", mouse); while((ret = termkey_waitkey(tk, &key)) != TERMKEY_RES_EOF) { - termkey_strfkey(tk, buffer, sizeof buffer, &key, format); - printf("%s\n", buffer); + if(ret == TERMKEY_RES_KEY) { + termkey_strfkey(tk, buffer, sizeof buffer, &key, format); + printf("%s\n", buffer); - if(key.type == TERMKEY_TYPE_UNICODE && - key.modifiers & TERMKEY_KEYMOD_CTRL && - (key.code.codepoint == 'C' || key.code.codepoint == 'c')) - break; + if(key.type == TERMKEY_TYPE_UNICODE && + key.modifiers & TERMKEY_KEYMOD_CTRL && + (key.code.codepoint == 'C' || key.code.codepoint == 'c')) + break; + } + else if(ret == TERMKEY_RES_ERROR) { + if(errno != EINTR) { + perror("termkey_waitkey"); + break; + } + printf("Interrupted by signal\n"); + } } if(mouse) |