From 7459a038fbb67922b5143c985b768dc819c1c630 Mon Sep 17 00:00:00 2001 From: Paul LeoNerd Evans Date: Tue, 24 Nov 2009 01:30:52 +0000 Subject: Make demo enable mouse mode if given on commandline --- demo.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/demo.c b/demo.c index 54845ad..fe0176f 100644 --- a/demo.c +++ b/demo.c @@ -1,4 +1,5 @@ #include +#include #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); } -- cgit v1.2.3-70-g09d2