summaryrefslogtreecommitdiffstats
path: root/tty-acs.c
diff options
context:
space:
mode:
authornicm <nicm>2020-05-16 16:26:34 +0000
committernicm <nicm>2020-05-16 16:26:34 +0000
commite2a26740b9880d0066c8a04ca2d7202e7f99bd07 (patch)
tree25ac0b2a7174e24b1e9df539b58aa21d98f3d65d /tty-acs.c
parentecbdcc256fd2c69c60c9d900a28922914d6b9896 (diff)
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.
Diffstat (limited to 'tty-acs.c')
-rw-r--r--tty-acs.c85
1 files changed, 78 insertions, 7 deletions
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 <sys/types.h>
#include <stdlib.h>
+#include <string.h>
#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);
+}