X-Git-Url: http://git.madism.org/?a=blobdiff_plain;f=madtty%2Fmadtty.c;h=251780fa2f3222c1931657dcbd48bf06d7dc1dac;hb=eccf6c1911e647ad25dc932fbaeb0901f60ec023;hp=ce21d3201fc4eaf7e895c42e165924bfdf5ad6c3;hpb=c3f780f9456ff7adde5b8041596e200a9b41c588;p=apps%2Fmadtty.git diff --git a/madtty/madtty.c b/madtty/madtty.c index ce21d32..251780f 100644 --- a/madtty/madtty.c +++ b/madtty/madtty.c @@ -24,8 +24,6 @@ #include #include #include -#include -#include #include #include #include @@ -34,9 +32,19 @@ #include #include #include - +#ifdef __linux__ +# include +#elif defined(__FreeBSD__) +# include +#elif defined(__OpenBSD__) +# include +#endif #include "madtty.h" +#ifndef NCURSES_ATTR_SHIFT +# define NCURSES_ATTR_SHIFT 8 +#endif + #define IS_CONTROL(ch) !((ch) & 0xffffff60UL) static int has_default = 0; @@ -613,6 +621,17 @@ static void try_interpret_escape_seq(madtty_t *t) if (t->elen + 1 >= (int)sizeof(t->ebuf)) { cancel: +#ifndef NDEBUG + fprintf(stderr, "cancelled: \\033"); + for (int i = 0; i < (int)t->elen; i++) { + if (isprint(t->ebuf[i])) { + fputc(t->ebuf[i], stderr); + } else { + fprintf(stderr, "\\%03o", t->ebuf[i]); + } + } + fputc('\n', stderr); +#endif cancel_escape_sequence(t); } } @@ -672,7 +691,7 @@ static uint16_t const vt100_0[62] = { // 41 .. 7e 0x2502, 0x2264, 0x2265, 0x03c0, 0x2260, 0x00a3, 0x00b7, // 78-7e }; -void madtty_putc(madtty_t *t, wchar_t wc) +static void madtty_putc(madtty_t *t, wchar_t wc) { int width = 0; @@ -837,6 +856,8 @@ void madtty_resize(madtty_t *t, int rows, int cols) lines[row].attr = realloc(lines[row].attr, sizeof(uint16_t) * cols); if (t->cols < cols) t_row_set(lines + row, t->cols, cols - t->cols, 0); + else + lines[row].dirty = true; } t->cols = cols; } @@ -844,14 +865,13 @@ void madtty_resize(madtty_t *t, int rows, int cols) while (t->rows < rows) { lines[t->rows].text = (wchar_t *)calloc(sizeof(wchar_t), cols); lines[t->rows].attr = (uint16_t *)calloc(sizeof(uint16_t), cols); + t_row_set(lines + t->rows, 0, t->cols, 0); t->rows++; } t->curs_row += lines - t->lines; - t->scroll_top += lines - t->lines; - t->scroll_bot += lines - t->lines; - if (t->scroll_bot > lines + t->rows) - t->scroll_bot = lines + t->rows; + t->scroll_top = lines; + t->scroll_bot = lines + rows; t->lines = lines; clamp_cursor_to_bounds(t); ioctl(t->pty, TIOCSWINSZ, &ws); @@ -962,19 +982,9 @@ void madtty_keypress(madtty_t *t, int keycode) } } -void madtty_initialize(void) +void madtty_init_colors(void) { - setlocale(LC_ALL, ""); - initscr(); - start_color(); - noecho(); - raw(); - nodelay(stdscr, TRUE); - keypad(stdscr, TRUE); - curs_set(0); - ESCDELAY=50; - - if (COLORS > 8) { + if (COLOR_PAIRS > 64) { use_default_colors(); assume_default_colors(-1, -1); has_default = 1; @@ -992,3 +1002,19 @@ void madtty_initialize(void) } } } + +int madtty_color_pair(int fg, int bg) +{ + if (has_default) { + if (fg < -1) + fg = -1; + if (bg < -1) + bg = -1; + return COLOR_PAIR((fg + 1) * 16 + bg + 1); + } + if (fg < 0) + fg = COLOR_WHITE; + if (bg < 0) + bg = COLOR_BLACK; + return COLOR_PAIR((7 - fg) * 8 + bg); +}