aboutsummaryrefslogtreecommitdiff
path: root/demo.c
diff options
context:
space:
mode:
authorPaul LeoNerd Evans <leonerd@leonerd.org.uk>2011-08-18 11:20:41 +0100
committerPaul LeoNerd Evans <leonerd@leonerd.org.uk>2011-08-18 11:20:41 +0100
commit7a2b79a6402979b4895e78657d59a770d5b082b3 (patch)
tree06105525116545218b02d5b995d80f451f8e3536 /demo.c
parent01e5795098bea0fecb29e69e702225cb236dd6f8 (diff)
downloadtermo-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.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/demo.c b/demo.c
index de3f511..11d85f2 100644
--- a/demo.c
+++ b/demo.c
@@ -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)