Optionally support unibilium for reading terminfo instead of curses

This commit is contained in:
Paul LeoNerd Evans 2011-09-24 00:04:01 +01:00
parent 7d623be041
commit e768f02219
2 changed files with 48 additions and 6 deletions

View File

@ -1,7 +1,13 @@
LIBTOOL=libtool LIBTOOL=libtool
CFLAGS?= CFLAGS?=
LDFLAGS=-lcurses
ifeq ($(shell pkg-config --atleast-version=0.1.0 unibilium && echo 1),1)
CFLAGS +=$(shell pkg-config --cflags unibilium) -DHAVE_UNIBILIUM
LDFLAGS+=$(shell pkg-config --libs unibilium)
else
LDFLAGS+=-lncurses
endif
CFLAGS_DEBUG= CFLAGS_DEBUG=

View File

@ -4,11 +4,15 @@
#include "termkey.h" #include "termkey.h"
#include "termkey-internal.h" #include "termkey-internal.h"
#ifdef HAVE_UNIBILIUM
# include <unibilium.h>
#else
# include <curses.h> # include <curses.h>
# include <term.h> # include <term.h>
/* curses.h has just poluted our namespace. We want this back */ /* curses.h has just poluted our namespace. We want this back */
# undef buttons # undef buttons
#endif
#include <ctype.h> #include <ctype.h>
#include <stdio.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) 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; int err;
/* Have to cast away the const. But it's OK - we know terminfo won't really /* Have to cast away the const. But it's OK - we know terminfo won't really
* modify term */ * modify term */
if(setupterm((char*)term, 1, &err) != OK) if(setupterm((char*)term, 1, &err) != OK)
return 0; return 0;
#endif
int i; #ifdef HAVE_UNIBILIUM
for(i = 0; strfnames[i]; i++) { 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 // Only care about the key_* constants
#ifdef HAVE_UNIBILIUM
const char *name = unibi_name_str(i);
#else
const char *name = strfnames[i]; const char *name = strfnames[i];
#endif
if(strncmp(name, "key_", 4) != 0) if(strncmp(name, "key_", 4) != 0)
continue; continue;
#ifdef HAVE_UNIBILIUM
const char *value = unibi_get_str(unibi, i);
#else
const char *value = tigetstr(strnames[i]); const char *value = tigetstr(strnames[i]);
#endif
if(!value || value == (char*)-1) if(!value || value == (char*)-1)
continue; 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 * instances for multiple different termtypes, and it's different by the
* time we want to use it * time we want to use it
*/ */
#ifdef HAVE_UNIBILIUM
const char *keypad_xmit = unibi_get_str(unibi, unibi_pkey_xmit);
#endif
if(keypad_xmit) if(keypad_xmit)
ti->start_string = strdup(keypad_xmit); ti->start_string = strdup(keypad_xmit);
else else
ti->start_string = NULL; ti->start_string = NULL;
#ifdef HAVE_UNIBILIUM
const char *keypad_local = unibi_get_str(unibi, unibi_pkey_local);
#endif
if(keypad_local) if(keypad_local)
ti->stop_string = strdup(keypad_local); ti->stop_string = strdup(keypad_local);
else else
ti->stop_string = NULL; ti->stop_string = NULL;
#ifdef HAVE_UNIBILIUM
unibi_destroy(unibi);
#endif
return 1; return 1;
} }