From: Marc Andre Tanner Date: Sat, 29 Dec 2007 18:13:21 +0000 (+0100) Subject: Correctly display vt100 graphics in non UTF-8 locales. X-Git-Url: http://git.madism.org/?p=apps%2Fmadtty.git;a=commitdiff_plain;h=226d6a58d4512b37d3f912f7be227f023b25c04c Correctly display vt100 graphics in non UTF-8 locales. Signed-off-by: Marc Andre Tanner Signed-off-by: Pierre Habouzit --- diff --git a/madtty/madtty.c b/madtty/madtty.c index 251780f..e7f26f8 100644 --- a/madtty/madtty.c +++ b/madtty/madtty.c @@ -677,10 +677,19 @@ static void madtty_process_nonprinting(madtty_t *t, wchar_t wc) } } +bool is_utf8 = true; + +static void is_utf8_locale(void) +{ + const char *l = getenv("LANG"); + if (l) + is_utf8 = (strstr(l, "UTF-8") != NULL); +} + // vt100 special graphics and line drawing // 5f-7e standard vt100 // 40-5e rxvt extension for extra curses acs chars -static uint16_t const vt100_0[62] = { // 41 .. 7e +static uint16_t const vt100_utf8[62] = { // 41 .. 7e 0x2191, 0x2193, 0x2192, 0x2190, 0x2588, 0x259a, 0x2603, // 41-47 hi mr. snowman! 0, 0, 0, 0, 0, 0, 0, 0, // 48-4f 0, 0, 0, 0, 0, 0, 0, 0, // 50-57 @@ -691,6 +700,46 @@ static uint16_t const vt100_0[62] = { // 41 .. 7e 0x2502, 0x2264, 0x2265, 0x03c0, 0x2260, 0x00a3, 0x00b7, // 78-7e }; +static uint32_t vt100[62]; + +void madtty_init_vt100_graphics(void) +{ + vt100['l' - 0x41] = ACS_ULCORNER; + vt100['m' - 0x41] = ACS_LLCORNER; + vt100['k' - 0x41] = ACS_URCORNER; + vt100['j' - 0x41] = ACS_LRCORNER; + vt100['u' - 0x41] = ACS_RTEE; + vt100['t' - 0x41] = ACS_LTEE; + vt100['v' - 0x41] = ACS_TTEE; + vt100['w' - 0x41] = ACS_BTEE; + vt100['q' - 0x41] = ACS_HLINE; + vt100['x' - 0x41] = ACS_VLINE; + vt100['n' - 0x41] = ACS_PLUS; + vt100['o' - 0x41] = ACS_S1; + vt100['s' - 0x41] = ACS_S9; + vt100['`' - 0x41] = ACS_DIAMOND; + vt100['a' - 0x41] = ACS_CKBOARD; + vt100['f' - 0x41] = ACS_DEGREE; + vt100['g' - 0x41] = ACS_PLMINUS; + vt100['~' - 0x41] = ACS_BULLET; + vt100[',' - 0x41] = ACS_LARROW; + vt100['+' - 0x41] = ACS_RARROW; + vt100['.' - 0x41] = ACS_DARROW; + vt100['-' - 0x41] = ACS_UARROW; + vt100['h' - 0x41] = ACS_BOARD; + vt100['i' - 0x41] = ACS_LANTERN; + vt100['0' - 0x41] = ACS_BLOCK; + /* these defaults were invented for ncurses */ + vt100['p' - 0x41] = ACS_S3; + vt100['r' - 0x41] = ACS_S7; + vt100['y' - 0x41] = ACS_LEQUAL; + vt100['z' - 0x41] = ACS_GEQUAL; + vt100['{' - 0x41] = ACS_PI; + vt100['|' - 0x41] = ACS_NEQUAL; + vt100['}' - 0x41] = ACS_STERLING; + is_utf8_locale(); +} + static void madtty_putc(madtty_t *t, wchar_t wc) { int width = 0; @@ -711,8 +760,11 @@ static void madtty_putc(madtty_t *t, wchar_t wc) t_row_t *tmp; if (t->graphmode) { - if (wc >= 0x41 && wc <= 0x7e && vt100_0[wc - 0x41]) { - wc = vt100_0[wc - 0x41]; + if (wc >= 0x41 && wc <= 0x7e) { + if(is_utf8 && vt100_utf8[wc - 0x41]) + wc = vt100_utf8[wc - 0x41]; + else if(!is_utf8 && vt100[wc - 0x41]) + wc = vt100[wc - 0x41]; } width = 1; } else { @@ -906,7 +958,7 @@ void madtty_draw(madtty_t *t, WINDOW *win, int srow, int scol) for (int j = 0; j < t->cols; j++) { if (!j || row->attr[j] != row->attr[j - 1]) wattrset(win, (attr_t)row->attr[j] << NCURSES_ATTR_SHIFT); - if (row->text[j] >= 128) { + if (is_utf8 && row->text[j] >= 128) { char buf[MB_CUR_MAX + 1]; int len; diff --git a/madtty/madtty.h b/madtty/madtty.h index d36ddfb..c790a50 100644 --- a/madtty/madtty.h +++ b/madtty/madtty.h @@ -32,6 +32,7 @@ void madtty_init_colors(void); int madtty_color_pair(int fg, int bg); +void madtty_init_vt100_graphics(void); typedef struct madtty_t madtty_t; @@ -45,5 +46,4 @@ int madtty_process(madtty_t *); void madtty_keypress(madtty_t *, int keycode); void madtty_draw(madtty_t *, WINDOW *win, int startrow, int startcol); - #endif /* MADTTY_MADTTY_H */