mirror of
https://github.com/tmux/tmux.git
synced 2025-09-02 05:21:10 +00:00
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.
This commit is contained in:
55
tty.c
55
tty.c
@ -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));
|
||||
@ -257,30 +258,6 @@ tty_stop_tty(struct tty *tty)
|
||||
fcntl(tty->fd, F_SETFL, mode & ~O_NONBLOCK);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user