aboutsummaryrefslogtreecommitdiff
path: root/demo.c
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2014-11-19 02:41:36 +0100
committerPřemysl Janouch <p.janouch@gmail.com>2014-11-19 03:19:13 +0100
commit2d777dd67e9be3c5bfd36660ade94710de0f4a0d (patch)
tree046b13365164eb2ac437804a6eca90131183380b /demo.c
parent5a80bceec9c3fcc304d8dde1c10f16a9adde8598 (diff)
downloadtermo-2d777dd67e9be3c5bfd36660ade94710de0f4a0d.tar.gz
termo-2d777dd67e9be3c5bfd36660ade94710de0f4a0d.tar.xz
termo-2d777dd67e9be3c5bfd36660ade94710de0f4a0d.zip
Rewrite the mouse API
I wasn't aware of the fact that 1000, 1002 and 1003 are mutually exclusive and turn each other off. Also now it's not needed to set the protocol, it gets set by default.
Diffstat (limited to 'demo.c')
-rw-r--r--demo.c39
1 files changed, 18 insertions, 21 deletions
diff --git a/demo.c b/demo.c
index d74892c..bc416c0 100644
--- a/demo.c
+++ b/demo.c
@@ -5,6 +5,7 @@
#include <unistd.h>
#include <errno.h>
#include <locale.h>
+#include <strings.h>
#include "termo.h"
@@ -14,31 +15,33 @@ main(int argc, char *argv[])
TERMO_CHECK_VERSION;
setlocale (LC_CTYPE, "");
- int mouse = 0;
- int mouse_proto = 0;
+ termo_mouse_tracking_t mouse = TERMO_MOUSE_TRACKING_OFF;
termo_format_t format = TERMO_FORMAT_VIM;
char buffer[50];
termo_t *tk;
int opt;
- while ((opt = getopt (argc, argv, "m::p:")) != -1)
+ while ((opt = getopt (argc, argv, "m::")) != -1)
{
switch (opt)
{
case 'm':
- if (optarg)
- mouse = atoi (optarg);
- else
- mouse = 1000;
- break;
-
- case 'p':
- mouse_proto = atoi (optarg);
+ if (!optarg)
+ mouse = TERMO_MOUSE_TRACKING_DRAG;
+ else if (!strcasecmp (optarg, "off"))
+ mouse = TERMO_MOUSE_TRACKING_OFF;
+ else if (!strcasecmp (optarg, "click"))
+ mouse = TERMO_MOUSE_TRACKING_CLICK;
+ else if (!strcasecmp (optarg, "drag"))
+ mouse = TERMO_MOUSE_TRACKING_DRAG;
+ else if (!strcasecmp (optarg, "move"))
+ mouse = TERMO_MOUSE_TRACKING_MOVE;
break;
default:
- fprintf (stderr, "Usage: %s [-m]\n", argv[0]);
+ fprintf (stderr,
+ "Usage: %s [ -m [ off | click | drag | move ]]\n", argv[0]);
return 1;
}
}
@@ -59,12 +62,9 @@ main(int argc, char *argv[])
termo_result_t ret;
termo_key_t key;
- if (mouse)
- {
- printf ("\033[?%dhMouse mode active\n", mouse);
- if (mouse_proto)
- printf ("\033[?%dh", mouse_proto);
- }
+ termo_set_mouse_tracking_mode (tk, mouse);
+ if (mouse != TERMO_MOUSE_TRACKING_OFF)
+ printf ("Mouse mode active\n");
while ((ret = termo_waitkey (tk, &key)) != TERMO_RES_EOF)
{
@@ -130,8 +130,5 @@ main(int argc, char *argv[])
}
}
- if (mouse)
- printf ("\033[?%dlMouse mode deactivated\n", mouse);
-
termo_destroy (tk);
}