aboutsummaryrefslogtreecommitdiff
path: root/demo.c
diff options
context:
space:
mode:
authorPaul LeoNerd Evans <leonerd@leonerd.org.uk>2009-11-24 01:30:52 +0000
committerPaul LeoNerd Evans <leonerd@leonerd.org.uk>2009-11-24 01:30:52 +0000
commit7459a038fbb67922b5143c985b768dc819c1c630 (patch)
treecaa571faefd0fdf7dfff3c4973fd576d13143adf /demo.c
parentceeaf717bdbb57caa9d4e8d34c8cd1e0fe818c67 (diff)
downloadtermo-7459a038fbb67922b5143c985b768dc819c1c630.tar.gz
termo-7459a038fbb67922b5143c985b768dc819c1c630.tar.xz
termo-7459a038fbb67922b5143c985b768dc819c1c630.zip
Make demo enable mouse mode if given on commandline
Diffstat (limited to 'demo.c')
-rw-r--r--demo.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/demo.c b/demo.c
index 54845ad..fe0176f 100644
--- a/demo.c
+++ b/demo.c
@@ -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);
}