From 31621036ad38ef3a2d88da838eb021430ea3c944 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Thu, 14 May 2020 16:49:08 +0100 Subject: Add an option to set the pane border lines style from a choice of single lines (ACS or UTF-8), double or heavy (UTF-8), simple (plain ASCII) or number (the pane numbers). Lines that won't work on a non-UTF-8 terminal are translated back into ACS when they are output. --- tty-acs.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 78 insertions(+), 7 deletions(-) (limited to 'tty-acs.c') diff --git a/tty-acs.c b/tty-acs.c index 3e811103..63eccb93 100644 --- a/tty-acs.c +++ b/tty-acs.c @@ -19,11 +19,10 @@ #include #include +#include #include "tmux.h" -static int tty_acs_cmp(const void *, const void *); - /* Table mapping ACS entries to UTF-8. */ struct tty_acs_entry { u_char key; @@ -68,14 +67,65 @@ static const struct tty_acs_entry tty_acs_table[] = { { '~', "\302\267" } /* bullet */ }; +/* Table mapping UTF-8 to ACS entries. */ +struct tty_acs_reverse_entry { + const char *string; + u_char key; +}; +static const struct tty_acs_reverse_entry tty_acs_reverse2[] = { + { "\302\267", '~' } +}; +static const struct tty_acs_reverse_entry tty_acs_reverse3[] = { + { "\342\224\200", 'q' }, + { "\342\224\201", 'q' }, + { "\342\224\202", 'x' }, + { "\342\224\203", 'x' }, + { "\342\224\214", 'l' }, + { "\342\224\217", 'k' }, + { "\342\224\220", 'k' }, + { "\342\224\223", 'l' }, + { "\342\224\224", 'm' }, + { "\342\224\227", 'm' }, + { "\342\224\230", 'j' }, + { "\342\224\233", 'j' }, + { "\342\224\234", 't' }, + { "\342\224\243", 't' }, + { "\342\224\244", 'u' }, + { "\342\224\253", 'u' }, + { "\342\224\263", 'w' }, + { "\342\224\264", 'v' }, + { "\342\224\273", 'v' }, + { "\342\224\274", 'n' }, + { "\342\225\213", 'n' }, + { "\342\225\220", 'q' }, + { "\342\225\221", 'x' }, + { "\342\225\224", 'l' }, + { "\342\225\227", 'k' }, + { "\342\225\232", 'm' }, + { "\342\225\235", 'j' }, + { "\342\225\240", 't' }, + { "\342\225\243", 'u' }, + { "\342\225\246", 'w' }, + { "\342\225\251", 'v' }, + { "\342\225\254", 'n' }, +}; + static int tty_acs_cmp(const void *key, const void *value) { const struct tty_acs_entry *entry = value; - u_char ch; + int test = *(u_char *)key; - ch = *(u_char *) key; - return (ch - entry->key); + return (test - entry->key); +} + +static int +tty_acs_reverse_cmp(const void *key, const void *value) +{ + const struct tty_acs_reverse_entry *entry = value; + const char *test = key; + + return (strcmp(test, entry->string)); } /* Should this terminal use ACS instead of UTF-8 line drawing? */ @@ -104,11 +154,11 @@ tty_acs_needed(struct tty *tty) return (1); } -/* Retrieve ACS to output as a string. */ +/* Retrieve ACS to output as UTF-8. */ const char * tty_acs_get(struct tty *tty, u_char ch) { - struct tty_acs_entry *entry; + const struct tty_acs_entry *entry; /* Use the ACS set instead of UTF-8 if needed. */ if (tty_acs_needed(tty)) { @@ -124,3 +174,24 @@ tty_acs_get(struct tty *tty, u_char ch) return (NULL); return (entry->string); } + +/* Reverse UTF-8 into ACS. */ +int +tty_acs_reverse_get(__unused struct tty *tty, const char *s, size_t slen) +{ + const struct tty_acs_reverse_entry *table, *entry; + u_int items; + + if (slen == 2) { + table = tty_acs_reverse2; + items = nitems(tty_acs_reverse2); + } else if (slen == 3) { + table = tty_acs_reverse3; + items = nitems(tty_acs_reverse3); + } else + return (-1); + entry = bsearch(s, table, items, sizeof table[0], tty_acs_reverse_cmp); + if (entry == NULL) + return (-1); + return (entry->key); +} -- cgit