Unbreak UTF-8.

This commit is contained in:
Nicholas Marriott 2009-01-18 21:46:30 +00:00
parent 7bc8be006e
commit 4cdc228353
6 changed files with 24 additions and 15 deletions

View File

@ -1,5 +1,6 @@
18 January 2009 18 January 2009
* Unbreak UTF-8.
* -a flag to next-window and previous-window to select the next or previous * -a flag to next-window and previous-window to select the next or previous
window with activity or bell. Bound to M-n and M-p. window with activity or bell. Bound to M-n and M-p.
* find-window command to search window names, titles and visible content (but * find-window command to search window names, titles and visible content (but
@ -957,7 +958,7 @@
(including mutt, emacs). No status bar yet and no key remapping or other (including mutt, emacs). No status bar yet and no key remapping or other
customisation. customisation.
$Id: CHANGES,v 1.219 2009-01-18 18:31:45 nicm Exp $ $Id: CHANGES,v 1.220 2009-01-18 21:46:30 nicm Exp $
LocalWords: showw utf UTF fulvio ciriaco joshe OSC APC gettime abc DEF OA clr LocalWords: showw utf UTF fulvio ciriaco joshe OSC APC gettime abc DEF OA clr
LocalWords: rivo nurges lscm Erdely eol smysession mysession ek dstname RB ms LocalWords: rivo nurges lscm Erdely eol smysession mysession ek dstname RB ms

2
TODO
View File

@ -81,4 +81,6 @@
errors better errors better
- document find-window - document find-window
- bring back -l/-p on splitw so i can do "splitw -p 75 elinks" - bring back -l/-p on splitw so i can do "splitw -p 75 elinks"
- UTF-8 combining characters don't work (probably should be width 1 but are
listed as 2)

View File

@ -1,4 +1,4 @@
/* $Id: input.c,v 1.73 2009-01-11 23:31:46 nicm Exp $ */ /* $Id: input.c,v 1.74 2009-01-18 21:46:30 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -542,7 +542,9 @@ input_state_utf8(u_char ch, struct input_ctx *ictx)
value = '_'; value = '_';
ictx->cell.data = value; ictx->cell.data = value;
ictx->cell.flags |= GRID_FLAG_UTF8;
screen_write_cell(&ictx->ctx, &ictx->cell); screen_write_cell(&ictx->ctx, &ictx->cell);
ictx->cell.flags &= ~GRID_FLAG_UTF8;
} }
void void

View File

@ -1,4 +1,4 @@
/* $Id: screen-write.c,v 1.26 2009-01-18 21:21:53 nicm Exp $ */ /* $Id: screen-write.c,v 1.27 2009-01-18 21:46:30 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -514,7 +514,11 @@ screen_write_cell(struct screen_write_ctx *ctx, const struct grid_cell *gc)
const struct grid_cell *hc; const struct grid_cell *hc;
struct grid_cell *ic, tc; struct grid_cell *ic, tc;
width = utf8_width(gc->data); /* Find character width. */
if (gc->flags & GRID_FLAG_UTF8)
width = utf8_width(gc->data);
else
width = 1;
/* If the character is wider than the screen, don't print it. */ /* If the character is wider than the screen, don't print it. */
if (width > screen_size_x(s)) { if (width > screen_size_x(s)) {
@ -570,7 +574,7 @@ screen_write_cell(struct screen_write_ctx *ctx, const struct grid_cell *gc)
break; break;
grid_view_set_cell(gd, xx, s->cy, &grid_default_cell); grid_view_set_cell(gd, xx, s->cy, &grid_default_cell);
} }
} else if (utf8_width(hc->data) > 1) { } else if (hc->flags & GRID_FLAG_UTF8 && utf8_width(hc->data) > 1) {
/* /*
* An UTF-8 wide cell; overwrite following padding cells only. * An UTF-8 wide cell; overwrite following padding cells only.
*/ */
@ -593,6 +597,7 @@ screen_write_cell(struct screen_write_ctx *ctx, const struct grid_cell *gc)
ic->flags |= GRID_FLAG_PADDING; ic->flags |= GRID_FLAG_PADDING;
} }
not_utf8:
/* Write the actual cell. */ /* Write the actual cell. */
grid_view_set_cell(gd, s->cx, s->cy, gc); grid_view_set_cell(gd, s->cx, s->cy, gc);

3
tmux.h
View File

@ -1,4 +1,4 @@
/* $Id: tmux.h,v 1.240 2009-01-18 18:31:45 nicm Exp $ */ /* $Id: tmux.h,v 1.241 2009-01-18 21:46:30 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -426,6 +426,7 @@ struct msg_resize_data {
#define GRID_FLAG_FG256 0x1 #define GRID_FLAG_FG256 0x1
#define GRID_FLAG_BG256 0x2 #define GRID_FLAG_BG256 0x2
#define GRID_FLAG_PADDING 0x4 #define GRID_FLAG_PADDING 0x4
#define GRID_FLAG_UTF8 0x8
/* Grid cell. */ /* Grid cell. */
struct grid_cell { struct grid_cell {

16
tty.c
View File

@ -1,4 +1,4 @@
/* $Id: tty.c,v 1.60 2009-01-18 21:35:09 nicm Exp $ */ /* $Id: tty.c,v 1.61 2009-01-18 21:46:30 nicm Exp $ */
/* /*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -680,20 +680,18 @@ tty_cmd_cell(struct tty *tty, struct screen *s, u_int oy, va_list ap)
if (gc->flags & GRID_FLAG_PADDING) if (gc->flags & GRID_FLAG_PADDING)
return; return;
/* Handle special characters. Should never come into this function.*/
if (gc->data < 0x20 || gc->data == 0x7f)
return;
/* Set the attributes. */ /* Set the attributes. */
tty_attributes(tty, gc); tty_attributes(tty, gc);
/* If not UTF8 multibyte, write directly. */ /* If not UTF-8, write directly. */
if (gc->data <= 0xff) { if (!(gc->flags & GRID_FLAG_UTF8)) {
if (gc->data > 0xff || gc->data < 0x20 || gc->data == 0x7f)
return;
tty_putc(tty, gc->data); tty_putc(tty, gc->data);
return; return;
} }
/* If the terminal doesn't support UTF8, write _s. */ /* If the terminal doesn't support UTF-8, write underscores. */
if (!(tty->flags & TTY_UTF8)) { if (!(tty->flags & TTY_UTF8)) {
width = utf8_width(gc->data); width = utf8_width(gc->data);
while (width-- > 0) while (width-- > 0)
@ -701,7 +699,7 @@ tty_cmd_cell(struct tty *tty, struct screen *s, u_int oy, va_list ap)
return; return;
} }
/* Unpack UTF-8 and write it. */ /* Otherwise, unpack UTF-8 and write it. */
utf8_split(gc->data, out); utf8_split(gc->data, out);
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
if (out[i] == 0xff) if (out[i] == 0xff)