diff options
-rw-r--r-- | demo.c | 28 |
1 files changed, 27 insertions, 1 deletions
@@ -1,4 +1,5 @@ #include <stdio.h> +#include <getopt.h> #include "termkey.h" @@ -6,8 +7,27 @@ int main(int argc, char *argv[]) { TERMKEY_CHECK_VERSION; + int mouse = 0; + char buffer[50]; - TermKey *tk = termkey_new(0, 0); + TermKey *tk; + + int opt; + while((opt = getopt(argc, argv, "m::")) != -1) { + switch(opt) { + case 'm': + if(optarg) + mouse = atoi(optarg); + else + mouse = 1000; + break; + default: + fprintf(stderr, "Usage: %s [-m]\n", argv[0]); + return 1; + } + } + + tk = termkey_new(0, 0); if(!tk) { fprintf(stderr, "Cannot allocate termkey instance\n"); @@ -17,6 +37,9 @@ int main(int argc, char *argv[]) TermKeyResult ret; TermKeyKey key; + if(mouse) + printf("\e[?%dhMouse mode active\n", mouse); + while((ret = termkey_waitkey(tk, &key)) != TERMKEY_RES_EOF) { termkey_snprint_key(tk, buffer, sizeof buffer, &key, TERMKEY_FORMAT_VIM); printf("%s\n", buffer); @@ -27,5 +50,8 @@ int main(int argc, char *argv[]) break; } + if(mouse) + printf("\e[?%dlMouse mode deactivated\n", mouse); + termkey_destroy(tk); } |