aboutsummaryrefslogtreecommitdiff
path: root/driver-ti.c
diff options
context:
space:
mode:
authorPaul LeoNerd Evans <leonerd@leonerd.org.uk>2011-09-24 00:04:01 +0100
committerPaul LeoNerd Evans <leonerd@leonerd.org.uk>2011-09-24 00:04:01 +0100
commite768f022197aaf1265b0afcdf673a0414f1ab9cd (patch)
treee4f36a05f2b1f39def13542f4876fe5120a85945 /driver-ti.c
parent7d623be041f671f3eb6af188d128b7f07642a24a (diff)
downloadtermo-e768f022197aaf1265b0afcdf673a0414f1ab9cd.tar.gz
termo-e768f022197aaf1265b0afcdf673a0414f1ab9cd.tar.xz
termo-e768f022197aaf1265b0afcdf673a0414f1ab9cd.zip
Optionally support unibilium for reading terminfo instead of curses
Diffstat (limited to 'driver-ti.c')
-rw-r--r--driver-ti.c46
1 files changed, 41 insertions, 5 deletions
diff --git a/driver-ti.c b/driver-ti.c
index 297a723..49e8c6d 100644
--- a/driver-ti.c
+++ b/driver-ti.c
@@ -4,11 +4,15 @@
#include "termkey.h"
#include "termkey-internal.h"
-#include <curses.h>
-#include <term.h>
+#ifdef HAVE_UNIBILIUM
+# include <unibilium.h>
+#else
+# include <curses.h>
+# include <term.h>
/* curses.h has just poluted our namespace. We want this back */
-#undef buttons
+# undef buttons
+#endif
#include <ctype.h>
#include <stdio.h>
@@ -159,21 +163,41 @@ static struct trie_node *compress_trie(struct trie_node *n)
static int load_terminfo(TermKeyTI *ti, const char *term)
{
+ int i;
+
+#ifdef HAVE_UNIBILIUM
+ unibi_term *unibi = unibi_from_term(term);
+ if(!unibi)
+ return 0;
+#else
int err;
/* Have to cast away the const. But it's OK - we know terminfo won't really
* modify term */
if(setupterm((char*)term, 1, &err) != OK)
return 0;
+#endif
- int i;
- for(i = 0; strfnames[i]; i++) {
+#ifdef HAVE_UNIBILIUM
+ for(i = unibi_string_begin_+1; i < unibi_string_end_; i++)
+#else
+ for(i = 0; strfnames[i]; i++)
+#endif
+ {
// Only care about the key_* constants
+#ifdef HAVE_UNIBILIUM
+ const char *name = unibi_name_str(i);
+#else
const char *name = strfnames[i];
+#endif
if(strncmp(name, "key_", 4) != 0)
continue;
+#ifdef HAVE_UNIBILIUM
+ const char *value = unibi_get_str(unibi, i);
+#else
const char *value = tigetstr(strnames[i]);
+#endif
if(!value || value == (char*)-1)
continue;
@@ -212,16 +236,28 @@ static int load_terminfo(TermKeyTI *ti, const char *term)
* instances for multiple different termtypes, and it's different by the
* time we want to use it
*/
+#ifdef HAVE_UNIBILIUM
+ const char *keypad_xmit = unibi_get_str(unibi, unibi_pkey_xmit);
+#endif
+
if(keypad_xmit)
ti->start_string = strdup(keypad_xmit);
else
ti->start_string = NULL;
+#ifdef HAVE_UNIBILIUM
+ const char *keypad_local = unibi_get_str(unibi, unibi_pkey_local);
+#endif
+
if(keypad_local)
ti->stop_string = strdup(keypad_local);
else
ti->stop_string = NULL;
+#ifdef HAVE_UNIBILIUM
+ unibi_destroy(unibi);
+#endif
+
return 1;
}