2008-02-07 01:58:41 +01:00
|
|
|
#include <stdio.h>
|
2009-11-24 02:30:52 +01:00
|
|
|
#include <getopt.h>
|
2011-08-18 12:20:41 +02:00
|
|
|
#include <errno.h>
|
2008-02-07 01:58:41 +01:00
|
|
|
|
|
|
|
#include "termkey.h"
|
|
|
|
|
2008-12-08 23:54:14 +01:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2008-11-16 13:40:14 +01:00
|
|
|
TERMKEY_CHECK_VERSION;
|
|
|
|
|
2009-11-24 02:30:52 +01:00
|
|
|
int mouse = 0;
|
2009-11-27 16:07:05 +01:00
|
|
|
TermKeyFormat format = TERMKEY_FORMAT_VIM;
|
2009-11-24 02:30:52 +01:00
|
|
|
|
2008-08-21 21:20:07 +02:00
|
|
|
char buffer[50];
|
2009-11-24 02:30:52 +01:00
|
|
|
TermKey *tk;
|
|
|
|
|
|
|
|
int opt;
|
|
|
|
while((opt = getopt(argc, argv, "m::")) != -1) {
|
|
|
|
switch(opt) {
|
|
|
|
case 'm':
|
|
|
|
if(optarg)
|
|
|
|
mouse = atoi(optarg);
|
|
|
|
else
|
|
|
|
mouse = 1000;
|
2009-11-27 16:07:05 +01:00
|
|
|
format |= TERMKEY_FORMAT_MOUSE_POS;
|
|
|
|
|
2009-11-24 02:30:52 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fprintf(stderr, "Usage: %s [-m]\n", argv[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-26 09:28:26 +02:00
|
|
|
tk = termkey_new(0, TERMKEY_FLAG_SPACESYMBOL|TERMKEY_FLAG_CTRLC);
|
2008-02-07 01:58:41 +01:00
|
|
|
|
2008-10-09 23:41:07 +02:00
|
|
|
if(!tk) {
|
|
|
|
fprintf(stderr, "Cannot allocate termkey instance\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2009-07-15 21:40:44 +02:00
|
|
|
TermKeyResult ret;
|
|
|
|
TermKeyKey key;
|
2008-02-07 01:58:41 +01:00
|
|
|
|
2009-11-24 02:30:52 +01:00
|
|
|
if(mouse)
|
|
|
|
printf("\e[?%dhMouse mode active\n", mouse);
|
|
|
|
|
2008-02-07 02:17:59 +01:00
|
|
|
while((ret = termkey_waitkey(tk, &key)) != TERMKEY_RES_EOF) {
|
2011-08-18 12:20:41 +02:00
|
|
|
if(ret == TERMKEY_RES_KEY) {
|
|
|
|
termkey_strfkey(tk, buffer, sizeof buffer, &key, format);
|
|
|
|
printf("%s\n", buffer);
|
2008-02-07 01:58:41 +01:00
|
|
|
|
2011-08-18 12:20:41 +02:00
|
|
|
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");
|
|
|
|
}
|
2008-02-07 01:58:41 +01:00
|
|
|
}
|
|
|
|
|
2009-11-24 02:30:52 +01:00
|
|
|
if(mouse)
|
|
|
|
printf("\e[?%dlMouse mode deactivated\n", mouse);
|
|
|
|
|
2008-02-23 21:26:04 +01:00
|
|
|
termkey_destroy(tk);
|
2008-02-07 01:58:41 +01:00
|
|
|
}
|