aboutsummaryrefslogtreecommitdiff
path: root/demo.c
diff options
context:
space:
mode:
authorPaul LeoNerd Evans <leonerd@leonerd.org.uk>2012-04-25 18:32:18 +0100
committerPaul LeoNerd Evans <leonerd@leonerd.org.uk>2012-04-25 18:32:18 +0100
commitca4d98b0f7d1a096e1d52fe8509e576ed8ab6faf (patch)
treef09eebb6273c20b203955b6fe488b44147f2bdf4 /demo.c
parentaf3c0bf378a74408de83dc37b17420ff5cdb37a1 (diff)
downloadtermo-ca4d98b0f7d1a096e1d52fe8509e576ed8ab6faf.tar.gz
termo-ca4d98b0f7d1a096e1d52fe8509e576ed8ab6faf.tar.xz
termo-ca4d98b0f7d1a096e1d52fe8509e576ed8ab6faf.zip
Have demo.c request cursor position on '?'; print position reports and mouse nicer
Diffstat (limited to 'demo.c')
-rw-r--r--demo.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/demo.c b/demo.c
index dcd3970..646fe9a 100644
--- a/demo.c
+++ b/demo.c
@@ -26,7 +26,6 @@ int main(int argc, char *argv[])
mouse = atoi(optarg);
else
mouse = 1000;
- format |= TERMKEY_FORMAT_MOUSE_POS;
break;
@@ -59,12 +58,31 @@ int main(int argc, char *argv[])
while((ret = termkey_waitkey(tk, &key)) != TERMKEY_RES_EOF) {
if(ret == TERMKEY_RES_KEY) {
termkey_strfkey(tk, buffer, sizeof buffer, &key, format);
- printf("%s\n", buffer);
+ if(key.type == TERMKEY_TYPE_MOUSE) {
+ int line, col;
+ termkey_interpret_mouse(tk, &key, NULL, NULL, &line, &col);
+ printf("%s at line=%d, col=%d)\n", buffer, line, col);
+ }
+ else if(key.type == TERMKEY_TYPE_POSITION) {
+ int line, col;
+ termkey_interpret_position(tk, &key, &line, &col);
+ printf("Cursor position report at line=%d, col=%d)\n", line, col);
+ }
+ else {
+ printf("%s\n", buffer);
+ }
- if(key.type == TERMKEY_TYPE_UNICODE &&
+ if(key.type == TERMKEY_TYPE_UNICODE &&
key.modifiers & TERMKEY_KEYMOD_CTRL &&
(key.code.codepoint == 'C' || key.code.codepoint == 'c'))
break;
+
+ if(key.type == TERMKEY_TYPE_UNICODE &&
+ key.modifiers == 0 &&
+ key.code.codepoint == '?') {
+ printf("\033[6n");
+ fflush(stdout);
+ }
}
else if(ret == TERMKEY_RES_ERROR) {
if(errno != EINTR) {