Make demo enable mouse mode if given on commandline

This commit is contained in:
Paul LeoNerd Evans 2009-11-24 01:30:52 +00:00
parent ceeaf717bd
commit 7459a038fb
1 changed files with 27 additions and 1 deletions

28
demo.c
View File

@ -1,4 +1,5 @@
#include <stdio.h> #include <stdio.h>
#include <getopt.h>
#include "termkey.h" #include "termkey.h"
@ -6,8 +7,27 @@ int main(int argc, char *argv[])
{ {
TERMKEY_CHECK_VERSION; TERMKEY_CHECK_VERSION;
int mouse = 0;
char buffer[50]; 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) { if(!tk) {
fprintf(stderr, "Cannot allocate termkey instance\n"); fprintf(stderr, "Cannot allocate termkey instance\n");
@ -17,6 +37,9 @@ int main(int argc, char *argv[])
TermKeyResult ret; TermKeyResult ret;
TermKeyKey key; TermKeyKey key;
if(mouse)
printf("\e[?%dhMouse mode active\n", mouse);
while((ret = termkey_waitkey(tk, &key)) != TERMKEY_RES_EOF) { while((ret = termkey_waitkey(tk, &key)) != TERMKEY_RES_EOF) {
termkey_snprint_key(tk, buffer, sizeof buffer, &key, TERMKEY_FORMAT_VIM); termkey_snprint_key(tk, buffer, sizeof buffer, &key, TERMKEY_FORMAT_VIM);
printf("%s\n", buffer); printf("%s\n", buffer);
@ -27,5 +50,8 @@ int main(int argc, char *argv[])
break; break;
} }
if(mouse)
printf("\e[?%dlMouse mode deactivated\n", mouse);
termkey_destroy(tk); termkey_destroy(tk);
} }