aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul LeoNerd Evans <leonerd@leonerd.org.uk>2008-10-09 20:23:45 +0100
committerPaul LeoNerd Evans <leonerd@leonerd.org.uk>2008-10-09 20:23:45 +0100
commit05639c477367fa436ef33a0a4dc5fc37215acd94 (patch)
tree39397ecf384a611af004b6b393fefbf7492b92a6
parenta61b916c18f6997a76186609e0697bd893865412 (diff)
downloadtermo-05639c477367fa436ef33a0a4dc5fc37215acd94.tar.gz
termo-05639c477367fa436ef33a0a4dc5fc37215acd94.tar.xz
termo-05639c477367fa436ef33a0a4dc5fc37215acd94.zip
Pass 'term' string into new_driver virtual method; have drivers sensitive to it and return NULL if they can't handle. Try CSI driver first; only for xterm-alikes
-rw-r--r--driver-csi.c12
-rw-r--r--driver-ti.c7
-rw-r--r--termkey-internal.h2
-rw-r--r--termkey.c6
4 files changed, 21 insertions, 6 deletions
diff --git a/driver-csi.c b/driver-csi.c
index f8188c8..be709a3 100644
--- a/driver-csi.c
+++ b/driver-csi.c
@@ -24,8 +24,18 @@ static termkey_keysym register_csi_ss3_full(termkey_csi *csi, termkey_type type,
static termkey_keysym register_ss3kpalt_full(termkey_csi *csi, termkey_type type, termkey_keysym sym, int modifier_set, int modifier_mask, unsigned char cmd, const char *name, char kpalt);
static termkey_keysym register_csifunc_full(termkey_csi *csi, termkey_type type, termkey_keysym sym, int modifier_set, int modifier_mask, int number, const char *name);
-static void *new_driver(termkey_t *tk)
+static void *new_driver(termkey_t *tk, const char *term)
{
+ // Only care about term types beginning "xterm"
+ if(strncmp(term, "xterm", 5) != 0)
+ return NULL;
+
+ // We want "xterm" or "xtermc" or "xterm-..."
+ if(term[5] != 0 && term[5] != '-' && term[5] != 'c')
+ return NULL;
+
+ // Excellent - we'll continue
+
termkey_csi *csi = malloc(sizeof *csi);
csi->tk = tk;
diff --git a/driver-ti.c b/driver-ti.c
index 05f39d8..66cdbe7 100644
--- a/driver-ti.c
+++ b/driver-ti.c
@@ -25,9 +25,12 @@ typedef struct {
static int funcname2keysym(const char *funcname, termkey_type *typep, termkey_keysym *symp, int *modmask, int *modsetp);
static void register_seq(termkey_ti *ti, const char *seq, termkey_type type, termkey_keysym sym, int modmask, int modset);
-static void *new_driver(termkey_t *tk)
+static void *new_driver(termkey_t *tk, const char *term)
{
- setupterm((char*)0, 1, (int*)0);
+ int err;
+
+ if(setupterm(term, 1, &err) != OK)
+ return NULL;
termkey_ti *ti = malloc(sizeof *ti);
diff --git a/termkey-internal.h b/termkey-internal.h
index 6cc64f9..fd865cd 100644
--- a/termkey-internal.h
+++ b/termkey-internal.h
@@ -8,7 +8,7 @@
struct termkey_driver
{
- void *(*new_driver)(termkey_t *tk);
+ void *(*new_driver)(termkey_t *tk, const char *term);
void (*free_driver)(void *);
termkey_result (*getkey)(termkey_t *tk, termkey_key *key, int force);
};
diff --git a/termkey.c b/termkey.c
index 7c788c4..47c21f3 100644
--- a/termkey.c
+++ b/termkey.c
@@ -9,8 +9,8 @@
#include <stdio.h>
static struct termkey_driver *drivers[] = {
- &termkey_driver_ti,
&termkey_driver_csi,
+ &termkey_driver_ti,
NULL,
};
@@ -133,8 +133,10 @@ termkey_t *termkey_new_full(int fd, int flags, size_t buffsize, int waittime)
register_c0(tk, TERMKEY_SYM_ENTER, 0x0d, NULL);
register_c0(tk, TERMKEY_SYM_ESCAPE, 0x1b, NULL);
+ const char *term = getenv("TERM");
+
for(i = 0; drivers[i]; i++) {
- void *driver_info = (*drivers[i]->new_driver)(tk);
+ void *driver_info = (*drivers[i]->new_driver)(tk, term);
if(!driver_info)
continue;