aboutsummaryrefslogtreecommitdiff
path: root/tty.c
diff options
context:
space:
mode:
authorTiago Cunha <tcunha@gmx.com>2010-09-18 15:43:53 +0000
committerTiago Cunha <tcunha@gmx.com>2010-09-18 15:43:53 +0000
commit5126037ea0bfc8a5245562156a0b5051cb9cdb02 (patch)
treec7a4ecbe65b514ab4ce46fb9e32d9a9702678662 /tty.c
parentd7a3fc3df4779c15bb832ec9b2bd4dbce34e55ff (diff)
downloadrtmux-5126037ea0bfc8a5245562156a0b5051cb9cdb02.tar.gz
rtmux-5126037ea0bfc8a5245562156a0b5051cb9cdb02.tar.bz2
rtmux-5126037ea0bfc8a5245562156a0b5051cb9cdb02.zip
Sync OpenBSD patchset 762:
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 'tty.c')
-rw-r--r--tty.c57
1 files changed, 20 insertions, 37 deletions
diff --git a/tty.c b/tty.c
index 3ce3af36..779aa015 100644
--- a/tty.c
+++ b/tty.c
@@ -1,4 +1,4 @@
-/* $Id: tty.c,v 1.193 2010-08-11 22:16:04 tcunha Exp $ */
+/* $Id: tty.c,v 1.194 2010-09-18 15:43:53 tcunha 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);
}