X-Git-Url: http://git.madism.org/?a=blobdiff_plain;f=madtty%2Fmadtty.c;h=83c2a5d7c46aa6ea74009ea0a087f546e4a97aab;hb=61754ad6e0733a15c837d3ba1c8255731df99c9e;hp=44533452a6571bfdd06ac3ddfa24cad635cf7ace;hpb=f5196e6e851c7d1dcf8c7e9c50f4da314c6ac238;p=apps%2Fmadtty.git diff --git a/madtty/madtty.c b/madtty/madtty.c index 4453345..83c2a5d 100644 --- a/madtty/madtty.c +++ b/madtty/madtty.c @@ -19,6 +19,7 @@ Copyright © 2006 Pierre Habouzit */ +#define _GNU_SOURCE #include #include #include @@ -30,6 +31,7 @@ #include #include #include +#include #include "madtty.h" @@ -564,9 +566,9 @@ static void try_interpret_escape_seq(madtty_t *rt) } if (rt->elen + 1 >= (int)sizeof(rt->ebuf)) { - int i; cancel: #if 0 + int i; fprintf(stderr, "cancelled: \\033"); for (i = 0; i < rt->elen; i++) { int c = rt->ebuf[i]; @@ -625,6 +627,8 @@ static void madtty_process_nonprinting(madtty_t *rt, wchar_t wc) void madtty_putc(madtty_t *rt, wchar_t wc) { + int width = 0; + if (!rt->seen_input) { rt->seen_input = 1; kill(-rt->childpid, SIGWINCH); @@ -665,8 +669,18 @@ void madtty_putc(madtty_t *rt, wchar_t wc) if (wc >= 0x41 && wc <= 0x7e && vt100_0[wc - 0x41]) { wc = vt100_0[wc - 0x41]; - // width = 1; // vt100 line drawing characters are always single-width } + width = 1; + } else { + width = wcwidth(wc) ?: 1; + } + + if (width == 2 && rt->curs_col == rt->cols - 1) { + tmp = rt->curs_row; + tmp->dirty = true; + tmp->text[rt->curs_col] = 0; + tmp->attr[rt->curs_col] = build_attrs(rt->curattrs); + rt->curs_col++; } if (rt->curs_col >= rt->cols) { @@ -675,18 +689,23 @@ void madtty_putc(madtty_t *rt, wchar_t wc) } tmp = rt->curs_row; + tmp->dirty = true; if (rt->insert) { - wmemmove(tmp->text + rt->curs_col + 1, tmp->text + rt->curs_col, - (rt->cols - rt->curs_col - 1)); - memmove(tmp->attr + rt->curs_col + 1, tmp->attr + rt->curs_col, - (rt->cols - rt->curs_col - 1) * sizeof(tmp->attr[0])); + wmemmove(tmp->text + rt->curs_col + width, tmp->text + rt->curs_col, + (rt->cols - rt->curs_col - width)); + memmove(tmp->attr + rt->curs_col + width, tmp->attr + rt->curs_col, + (rt->cols - rt->curs_col - width) * sizeof(tmp->attr[0])); } tmp->text[rt->curs_col] = wc; tmp->attr[rt->curs_col] = build_attrs(rt->curattrs); - tmp->dirty = true; rt->curs_col++; + if (width == 2) { + tmp->text[rt->curs_col] = 0; + tmp->attr[rt->curs_col] = build_attrs(rt->curattrs); + rt->curs_col++; + } } } @@ -803,6 +822,8 @@ void madtty_draw(madtty_t *rt, WINDOW *win, int srow, int scol) len = wcrtomb(buf, row->text[j], NULL); waddnstr(win, buf, len); + if (wcwidth(row->text[j]) > 1) + j++; } else { waddch(win, row->text[j] > ' ' ? row->text[j] : ' '); } @@ -846,16 +867,20 @@ void madtty_keypress(madtty_t *rt, int keycode) const char *buf; int len; +#if 0 + if (keycode == KEY_F(1)) { +#define MIN(a, b) ((a < (b)) ? a : (b)) + kill(-rt->childpid, SIGWINCH); + rt->scroll_bot = MIN(rt->scroll_bot, rt->lines + rt->rows); + rt->curs_row = MIN(rt->curs_row, rt->lines + rt->rows); + printf(stderr, "%d\n", rt->rows); + return; + } +#endif if (keycode >= 0 && keycode < KEY_MAX && keytable[keycode]) { buf = keytable[keycode]; len = strlen(keytable[keycode]); } else { -#if 0 - if (keycode == KEY_F(3)) { - kill(-rt->childpid, SIGWINCH); - return; - } -#endif buf = &c; len = 1; } @@ -880,6 +905,7 @@ void madtty_initialize(void) raw(); nodelay(stdscr, TRUE); keypad(stdscr, TRUE); + ESCDELAY=50; for (int i = -1; i < 8; i++) { for (int j = -1; j < 8; j++) {