Update of /cvsroot/tmux/tmux
In directory sfp-cvsdas-2.v30.ch3.sourceforge.com:/tmp/cvs-serv12625
Modified Files:
screen-redraw.c tmux.h tty-term.c tty.c
Added Files:
tty-acs.c
Log Message:
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.
Index: tty.c
===================================================================
RCS file: /cvsroot/tmux/tmux/tty.c,v
retrieving revision 1.193
retrieving revision 1.194
diff -u -d -r1.193 -r1.194
--- tty.c 11 Aug 2010 22:16:04 -0000 1.193
+++ tty.c 18 Sep 2010 15:43:53 -0000 1.194
@@ -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_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_keys_init(tty);
- tty_fill_acs(tty);
-
return (0);
}
@@ -201,7 +200,8 @@
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 @@
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 @@
}
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 @@
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 @@
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 @@
}
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);
}
Index: screen-redraw.c
===================================================================
RCS file: /cvsroot/tmux/tmux/screen-redraw.c,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -d -r1.52 -r1.53
--- screen-redraw.c 5 Feb 2010 01:31:06 -0000 1.52
+++ screen-redraw.c 18 Sep 2010 15:43:53 -0000 1.53
@@ -41,6 +41,8 @@
#define CELL_JOIN 11
#define CELL_OUTSIDE 12
+#define CELL_BORDERS " xqlkmjwvtun~"
+
/* Check if cell is on the border of a particular pane. */
int
screen_redraw_cell_border1(struct window_pane *wp, u_int px, u_int py)
@@ -173,8 +175,6 @@
struct grid_cell active_gc, other_gc;
u_int i, j, type;
int status, fg, bg;
- const u_char *base, *ptr;
- u_char ch, border[20];
/* Get status line, er, status. */
if (c->message_string != NULL || c->prompt_string != NULL)
@@ -193,6 +193,7 @@
memcpy(&other_gc, &grid_default_cell, sizeof other_gc);
memcpy(&active_gc, &grid_default_cell, sizeof active_gc);
active_gc.data = other_gc.data = 'x'; /* not space */
+ active_gc.attr = other_gc.attr = GRID_ATTR_CHARSET;
fg = options_get_number(&c->session->options, "pane-border-fg");
colour_set_fg(&other_gc, fg);
bg = options_get_number(&c->session->options, "pane-border-bg");
@@ -203,16 +204,6 @@
colour_set_bg(&active_gc, bg);
/* Draw background and borders. */
- strlcpy(border, " |-....--||+.", sizeof border);
- if (tty_term_has(tty->term, TTYC_ACSC)) {
- base = " xqlkmjwvtun~";
- for (ptr = base; *ptr != '\0'; ptr++) {
- if ((ch = tty_get_acs(tty, *ptr)) != '\0')
- border[ptr - base] = ch;
- }
- other_gc.attr |= GRID_ATTR_CHARSET;
- active_gc.attr |= GRID_ATTR_CHARSET;
- }
for (j = 0; j < tty->sy - status; j++) {
if (status_only && j != tty->sy - 1)
continue;
@@ -225,7 +216,7 @@
else
tty_attributes(tty, &other_gc);
tty_cursor(tty, i, j);
- tty_putc(tty, border[type]);
+ tty_putc(tty, CELL_BORDERS[type]);
}
}
Index: tty-term.c
===================================================================
RCS file: /cvsroot/tmux/tmux/tty-term.c,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -d -r1.42 -r1.43
--- tty-term.c 18 Sep 2010 15:41:50 -0000 1.42
+++ tty-term.c 18 Sep 2010 15:43:53 -0000 1.43
@@ -305,6 +305,7 @@
u_int i;
int n, error;
char *s;
+ const char *acs;
SLIST_FOREACH(term, &tty_terms, entry) {
if (strcmp(term->name, name) == 0) {
@@ -318,7 +319,7 @@
term->name = xstrdup(name);
term->references = 1;
term->flags = 0;
- memset(&term->codes, 0, sizeof term->codes);
+ memset(term->codes, 0, sizeof term->codes);
SLIST_INSERT_HEAD(&tty_terms, term, entry);
/* Set up curses terminal. */
@@ -416,6 +417,15 @@
if (!tty_term_flag(term, TTYC_XENL))
term->flags |= TERM_EARLYWRAP;
+ /* Generate ACS table. If none is present, use nearest ASCII. */
+ memset(term->acs, 0, sizeof term->acs);
+ if (tty_term_has(term, TTYC_ACSC))
+ acs = tty_term_string(term, TTYC_ACSC);
+ else
+ acs = "a#j+k+l+m+n+o-p-q-r-s-t+u+v+w+x|y<z>~.";
+ for (; acs[0] != '\0' && acs[1] != '\0'; acs += 2)
+ term->acs[(u_char) acs[0]][0] = acs[1];
+
return (term);
error:
Index: tmux.h
===================================================================
RCS file: /cvsroot/tmux/tmux/tmux.h,v
retrieving revision 1.576
retrieving revision 1.577
diff -u -d -r1.576 -r1.577
--- tmux.h 10 Sep 2010 13:36:17 -0000 1.576
+++ tmux.h 18 Sep 2010 15:43:53 -0000 1.577
@@ -970,6 +970,8 @@
char *name;
u_int references;
+ char acs[UCHAR_MAX + 1][2];
+
struct tty_code codes[NTTYCODE];
#define TERM_256COLOURS 0x1
@@ -1007,8 +1009,6 @@
struct grid_cell cell;
- u_char acs[UCHAR_MAX + 1];
-
#define TTY_NOCURSOR 0x1
#define TTY_FREEZE 0x2
#define TTY_ESCAPE 0x4
@@ -1370,7 +1370,6 @@
/* tty.c */
void tty_raw(struct tty *, const char *);
-u_char tty_get_acs(struct tty *, u_char);
void tty_attributes(struct tty *, const struct grid_cell *);
void tty_reset(struct tty *);
void tty_region_pane(struct tty *, const struct tty_ctx *, u_int, u_int);
@@ -1424,6 +1423,9 @@
int tty_term_number(struct tty_term *, enum tty_code_code);
int tty_term_flag(struct tty_term *, enum tty_code_code);
+/* tty-acs.c */
+const char *tty_acs_get(struct tty *, u_char);
+
/* tty-keys.c */
void tty_keys_init(struct tty *);
void tty_keys_free(struct tty *);
--- NEW FILE: tty-acs.c ---
/* $Id: tty-acs.c,v 1.1 2010/09/18 15:43:53 tcunha Exp $ */
/*
* Copyright (c) 2010 Nicholas Marriott <[email protected]>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <sys/types.h>
#include <stdlib.h>
#include "tmux.h"
int tty_acs_cmp(const void *, const void *);
/* Table mapping ACS entries to UTF-8. */
struct tty_acs_entry {
u_char key;
const char *string;
};
const struct tty_acs_entry tty_acs_table[] = {
{ '+', "\342\206\222" },
{ ',', "\342\206\220" },
{ '-', "\342\206\221" },
{ '.', "\342\206\223" },
{ '0', "\342\226\256" },
{ '`', "\342\227\206" },
{ 'a', "\342\226\222" },
{ 'f', "\302\260" },
{ 'g', "\302\261" },
{ 'h', "\342\226\222" },
{ 'i', "\342\230\203" },
{ 'j', "\342\224\230" },
{ 'k', "\342\224\220" },
{ 'l', "\342\224\214" },
{ 'm', "\342\224\224" },
{ 'n', "\342\224\274" },
{ 'o', "\342\216\272" },
{ 'p', "\342\216\273" },
{ 'q', "\342\224\200" },
{ 'r', "\342\216\274" },
{ 's', "\342\216\275" },
{ 't', "\342\224\234" },
{ 'u', "\342\224\244" },
{ 'v', "\342\224\264" },
{ 'w', "\342\224\254" },
{ 'x', "\342\224\202" },
{ 'y', "\342\211\244" },
{ 'z', "\342\211\245" },
{ '{', "\317\200" },
{ '|', "\342\211\240" },
{ '}', "\302\243" },
{ '~', "\302\267" }
};
int
tty_acs_cmp(const void *key, const void *value)
{
const struct tty_acs_entry *entry = value;
u_char ch;
ch = *(u_char *) key;
return (ch - entry->key);
}
/* Retrieve ACS to output as a string. */
const char *
tty_acs_get(struct tty *tty, u_char ch)
{
struct tty_acs_entry *entry;
/* If not a UTF-8 terminal, use the ACS set. */
if (!(tty->flags & TTY_UTF8)) {
if (tty->term->acs[ch][0] == '\0')
return (NULL);
return (&tty->term->acs[ch][0]);
}
/* Otherwise look up the UTF-8 translation. */
entry = bsearch(&ch,
tty_acs_table, nitems(tty_acs_table), sizeof tty_acs_table[0],
tty_acs_cmp);
if (entry == NULL)
return (NULL);
return (entry->string);
}
------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
tmux-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tmux-cvs