summaryrefslogtreecommitdiff
path: root/usr.bin/tmux/tty.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2010-09-11 16:19:23 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2010-09-11 16:19:23 +0000
commite5875a1c1c3501082ddf22c6b66edb0dcd48d69e (patch)
treeb5c206d49e6aed0ad5773148d53ead84056fd80f /usr.bin/tmux/tty.c
parent10b6b55a0bfc1b7b776b537288cf3d86f8f2e032 (diff)
Use UTF-8 line drawing characters on UTF-8 terminals. Fixes some stupid
terminals (I'm looking at you, putty) which disable the vt100 ACS mode switching sequences in UTF-8 mode. Also on terminals without ACS at all, use ASCII equivalents where obvious.
Diffstat (limited to 'usr.bin/tmux/tty.c')
-rw-r--r--usr.bin/tmux/tty.c57
1 files changed, 20 insertions, 37 deletions
diff --git a/usr.bin/tmux/tty.c b/usr.bin/tmux/tty.c
index 094be0f99bf..cf208ba4aab 100644
--- a/usr.bin/tmux/tty.c
+++ b/usr.bin/tmux/tty.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tty.c,v 1.89 2010/08/11 07:34:43 nicm Exp $ */
+/* $OpenBSD: tty.c,v 1.90 2010/09/11 16:19:22 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -31,8 +31,6 @@
void tty_read_callback(struct bufferevent *, void *);
void tty_error_callback(struct bufferevent *, short, void *);
-void tty_fill_acs(struct tty *);
-
int tty_try_256(struct tty *, u_char, const char *);
int tty_try_88(struct tty *, u_char, const char *);
@@ -48,6 +46,9 @@ void tty_emulate_repeat(
void tty_cell(struct tty *,
const struct grid_cell *, const struct grid_utf8 *);
+#define tty_use_acs(tty) \
+ (tty_term_has(tty, TTYC_ACSC) && !((tty)->flags & TTY_UTF8))
+
void
tty_init(struct tty *tty, int fd, char *term)
{
@@ -143,8 +144,6 @@ tty_open(struct tty *tty, const char *overrides, char **cause)
tty_keys_init(tty);
- tty_fill_acs(tty);
-
return (0);
}
@@ -201,7 +200,8 @@ tty_start_tty(struct tty *tty)
memcpy(&tty->cell, &grid_default_cell, sizeof tty->cell);
tty_putcode(tty, TTYC_RMKX);
- tty_putcode(tty, TTYC_ENACS);
+ if (tty_use_acs(tty))
+ tty_putcode(tty, TTYC_ENACS);
tty_putcode(tty, TTYC_CLEAR);
tty_putcode(tty, TTYC_CNORM);
@@ -242,7 +242,8 @@ tty_stop_tty(struct tty *tty)
return;
tty_raw(tty, tty_term_string2(tty->term, TTYC_CSR, 0, ws.ws_row - 1));
- tty_raw(tty, tty_term_string(tty->term, TTYC_RMACS));
+ if (tty_use_acs(tty))
+ tty_raw(tty, tty_term_string(tty->term, TTYC_RMACS));
tty_raw(tty, tty_term_string(tty->term, TTYC_SGR0));
tty_raw(tty, tty_term_string(tty->term, TTYC_RMKX));
tty_raw(tty, tty_term_string(tty->term, TTYC_CLEAR));
@@ -258,30 +259,6 @@ tty_stop_tty(struct tty *tty)
}
void
-tty_fill_acs(struct tty *tty)
-{
- const char *ptr;
-
- memset(tty->acs, 0, sizeof tty->acs);
- if (!tty_term_has(tty->term, TTYC_ACSC))
- return;
-
- ptr = tty_term_string(tty->term, TTYC_ACSC);
- if (strlen(ptr) % 2 != 0)
- return;
- for (; *ptr != '\0'; ptr += 2)
- tty->acs[(u_char) ptr[0]] = ptr[1];
-}
-
-u_char
-tty_get_acs(struct tty *tty, u_char ch)
-{
- if (tty->acs[ch] != '\0')
- return (tty->acs[ch]);
- return (ch);
-}
-
-void
tty_close(struct tty *tty)
{
if (tty->log_fd != -1) {
@@ -360,11 +337,17 @@ tty_puts(struct tty *tty, const char *s)
void
tty_putc(struct tty *tty, u_char ch)
{
- u_int sx;
+ const char *acs;
+ u_int sx;
- if (tty->cell.attr & GRID_ATTR_CHARSET)
- ch = tty_get_acs(tty, ch);
- bufferevent_write(tty->event, &ch, 1);
+ if (tty->cell.attr & GRID_ATTR_CHARSET) {
+ acs = tty_acs_get(tty, ch);
+ if (acs != NULL)
+ bufferevent_write(tty->event, acs, strlen(acs));
+ else
+ bufferevent_write(tty->event, &ch, 1);
+ } else
+ bufferevent_write(tty->event, &ch, 1);
if (ch >= 0x20 && ch != 0x7f) {
sx = tty->sx;
@@ -997,7 +980,7 @@ tty_reset(struct tty *tty)
if (memcmp(gc, &grid_default_cell, sizeof *gc) == 0)
return;
- if (tty_term_has(tty->term, TTYC_RMACS) && gc->attr & GRID_ATTR_CHARSET)
+ if ((gc->attr & GRID_ATTR_CHARSET) && tty_use_acs(tty))
tty_putcode(tty, TTYC_RMACS);
tty_putcode(tty, TTYC_SGR0);
memcpy(gc, &grid_default_cell, sizeof *gc);
@@ -1234,7 +1217,7 @@ tty_attributes(struct tty *tty, const struct grid_cell *gc)
}
if (changed & GRID_ATTR_HIDDEN)
tty_putcode(tty, TTYC_INVIS);
- if (changed & GRID_ATTR_CHARSET)
+ if ((changed & GRID_ATTR_CHARSET) && tty_use_acs(tty))
tty_putcode(tty, TTYC_SMACS);
}