[BACK]Return to tty-acs.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tmux

Annotation of src/usr.bin/tmux/tty-acs.c, Revision 1.2

1.2     ! nicm        1: /* $OpenBSD: tty-acs.c,v 1.1 2010/09/11 16:19:22 nicm Exp $ */
1.1       nicm        2:
                      3: /*
                      4:  * Copyright (c) 2010 Nicholas Marriott <nicm@users.sourceforge.net>
                      5:  *
                      6:  * Permission to use, copy, modify, and distribute this software for any
                      7:  * purpose with or without fee is hereby granted, provided that the above
                      8:  * copyright notice and this permission notice appear in all copies.
                      9:  *
                     10:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                     11:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     12:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
                     13:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     14:  * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
                     15:  * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
                     16:  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
                     17:  */
                     18:
                     19: #include <sys/types.h>
                     20:
                     21: #include <stdlib.h>
                     22:
                     23: #include "tmux.h"
                     24:
                     25: int    tty_acs_cmp(const void *, const void *);
                     26:
                     27: /* Table mapping ACS entries to UTF-8. */
                     28: struct tty_acs_entry {
                     29:        u_char           key;
                     30:        const char      *string;
                     31: };
                     32: const struct tty_acs_entry tty_acs_table[] = {
1.2     ! nicm       33:        { '+', "\342\206\222" },        /* arrow pointing right */
        !            34:        { ',', "\342\206\220" },        /* arrow pointing left */
        !            35:        { '-', "\342\206\221" },        /* arrow pointing up */
        !            36:        { '.', "\342\206\223" },        /* arrow pointing down */
        !            37:        { '0', "\342\226\256" },        /* solid square block */
        !            38:        { '`', "\342\227\206" },        /* diamond */
        !            39:        { 'a', "\342\226\222" },        /* checker board (stipple) */
        !            40:        { 'f', "\302\260" },            /* degree symbol */
        !            41:        { 'g', "\302\261" },            /* plus/minus */
        !            42:        { 'h', "\342\226\222" },        /* board of squares */
        !            43:        { 'i', "\342\230\203" },        /* lantern symbol */
        !            44:        { 'j', "\342\224\230" },        /* lower right corner */
        !            45:        { 'k', "\342\224\220" },        /* upper right corner */
        !            46:        { 'l', "\342\224\214" },        /* upper left corner */
        !            47:        { 'm', "\342\224\224" },        /* lower left corner */
        !            48:        { 'n', "\342\224\274" },        /* large plus or crossover */
        !            49:        { 'o', "\342\216\272" },        /* scan line 1 */
        !            50:        { 'p', "\342\216\273" },        /* scan line 3 */
        !            51:        { 'q', "\342\224\200" },        /* horizontal line */
        !            52:        { 'r', "\342\216\274" },        /* scan line 7 */
        !            53:        { 's', "\342\216\275" },        /* scan line 9 */
        !            54:        { 't', "\342\224\234" },        /* tee pointing right */
        !            55:        { 'u', "\342\224\244" },        /* tee pointing left */
        !            56:        { 'v', "\342\224\264" },        /* tee pointing up */
        !            57:        { 'w', "\342\224\254" },        /* tee pointing down */
        !            58:        { 'x', "\342\224\202" },        /* vertical line */
        !            59:        { 'y', "\342\211\244" },        /* less-than-or-equal-to */
        !            60:        { 'z', "\342\211\245" },        /* greater-than-or-equal-to */
        !            61:        { '{', "\317\200" },            /* greek pi */
        !            62:        { '|', "\342\211\240" },        /* not-equal */
        !            63:        { '}', "\302\243" },            /* UK pound sign */
        !            64:        { '~', "\302\267" }             /* bullet */
1.1       nicm       65: };
                     66:
                     67: int
                     68: tty_acs_cmp(const void *key, const void *value)
                     69: {
                     70:        const struct tty_acs_entry      *entry = value;
                     71:        u_char                           ch;
                     72:
                     73:        ch = *(u_char *) key;
                     74:        return (ch - entry->key);
                     75: }
                     76:
                     77: /* Retrieve ACS to output as a string. */
                     78: const char *
                     79: tty_acs_get(struct tty *tty, u_char ch)
                     80: {
                     81:        struct tty_acs_entry *entry;
                     82:
                     83:        /* If not a UTF-8 terminal, use the ACS set. */
                     84:        if (!(tty->flags & TTY_UTF8)) {
                     85:                if (tty->term->acs[ch][0] == '\0')
                     86:                        return (NULL);
                     87:                return (&tty->term->acs[ch][0]);
                     88:        }
                     89:
                     90:        /* Otherwise look up the UTF-8 translation. */
                     91:        entry = bsearch(&ch,
                     92:            tty_acs_table, nitems(tty_acs_table), sizeof tty_acs_table[0],
                     93:            tty_acs_cmp);
                     94:        if (entry == NULL)
                     95:                return (NULL);
                     96:        return (entry->string);
                     97: }