3 This program is free software; you can redistribute it and/or
4 modify it under the terms of the GNU Lesser General Public
5 License (LGPL) as published by the Free Software Foundation.
7 Please refer to the COPYING file for more information.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 Copyright © 2004 Bruno T. C. de Oliveira
19 Copyright © 2006 Pierre Habouzit
33 #include <sys/types.h>
38 #define IS_CONTROL(ch) !((ch) & 0xffffff60UL)
40 static int has_default = 0;
44 C0_SOH, C0_STX, C0_ETX, C0_EOT, C0_ENQ, C0_ACK, C0_BEL,
45 C0_BS , C0_HT , C0_LF , C0_VT , C0_FF , C0_CR , C0_SO , C0_SI ,
46 C0_DLE, C0_DC1, C0_DC2, D0_DC3, C0_DC4, C0_NAK, C0_SYN, C0_ETB,
47 C0_CAN, C0_EM , C0_SUB, C0_ESC, C0_IS4, C0_IS3, C0_IS2, C0_IS1,
52 C1_41 , C1_BPH, C1_NBH, C1_44 , C1_NEL, C1_SSA, C1_ESA,
53 C1_HTS, C1_HTJ, C1_VTS, C1_PLD, C1_PLU, C1_RI , C1_SS2, C1_SS3,
54 C1_DCS, C1_PU1, C1_PU2, C1_STS, C1_CCH, C1_MW , C1_SPA, C1_EPA,
55 C1_SOS, C1_59 , C1_SCI, C1_CSI, CS_ST , C1_OSC, C1_PM , C1_APC,
60 CSI_CUU, CSI_CUD, CSI_CUF, CSI_CUB, CSI_CNL, CSI_CPL, CSI_CHA,
61 CSI_CUP, CSI_CHT, CSI_ED , CSI_EL , CSI_IL , CSI_DL , CSI_EF , CSI_EA ,
62 CSI_DCH, CSI_SEE, CSI_CPR, CSI_SU , CSI_SD , CSI_NP , CSI_PP , CSI_CTC,
63 CSI_ECH, CSI_CVT, CSI_CBT, CSI_SRS, CSI_PTX, CSI_SDS, CSI_SIMD, CSI_5F,
64 CSI_HPA, CSI_HPR, CSI_REP, CSI_DA , CSI_VPA, CSI_VPR, CSI_HVP, CSI_TBC,
65 CSI_SM , CSI_MC , CSI_HPB, CSI_VPB, CSI_RM , CSI_SGR, CSI_DSR, CSI_DAQ,
66 CSI_70 , CSI_71 , CSI_72 , CSI_73 , CSI_74 , CSI_75 , CSI_76 , CSI_77 ,
67 CSI_78 , CSI_79 , CSI_7A , CSI_7B , CSI_7C , CSI_7D , CSI_7E , CSI_7F
76 static char const * const keytable[KEY_MAX+1] = {
82 [KEY_BACKSPACE] = "\177",
87 [KEY_PPAGE] = "\e[5~",
88 [KEY_NPAGE] = "\e[6~",
89 [KEY_SUSPEND] = "\x1A", /* Ctrl+Z gets mapped to this */
95 [KEY_F(6)] = "\e[17~",
96 [KEY_F(7)] = "\e[18~",
97 [KEY_F(8)] = "\e[19~",
98 [KEY_F(9)] = "\e[20~",
99 [KEY_F(10)] = "\e[21~",
102 static void mtty_row_set(mtty_row_t *row, int start, int len, uint16_t attr)
105 wmemset(row->text + start, 0, len);
106 for (int i = start; i < len + start; i++) {
111 static void mtty_row_roll(mtty_row_t *start, mtty_row_t *end, int count)
120 mtty_row_t *buf = alloca(count * sizeof(mtty_row_t));
122 memcpy(buf, start, count * sizeof(mtty_row_t));
123 memmove(start, start + count, (n - count) * sizeof(mtty_row_t));
124 memcpy(end - count, buf, count * sizeof(mtty_row_t));
125 for (mtty_row_t *row = start; row < end; row++) {
131 static void clamp_cursor_to_bounds(madtty_t *rt)
133 if (rt->curs_row < rt->lines) {
134 rt->curs_row = rt->lines;
136 if (rt->curs_row >= rt->lines + rt->rows) {
137 rt->curs_row = rt->lines + rt->rows - 1;
140 if (rt->curs_col < 0) {
143 if (rt->curs_col >= rt->cols) {
144 rt->curs_col = rt->cols - 1;
148 static void cursor_line_down(madtty_t *rt)
151 if (rt->curs_row < rt->scroll_bot)
154 rt->curs_row = rt->scroll_bot - 1;
155 mtty_row_roll(rt->scroll_top, rt->scroll_bot, 1);
156 mtty_row_set(rt->curs_row, 0, rt->cols, 0);
159 __attribute__((const))
160 static uint16_t build_attrs(unsigned curattrs)
162 return ((curattrs & ~A_COLOR) | COLOR_PAIR(curattrs & 0xff))
163 >> NCURSES_ATTR_SHIFT;
166 static void new_escape_sequence(madtty_t *rt)
173 static void cancel_escape_sequence(madtty_t *rt)
180 static bool is_valid_csi_ender(int c)
182 return (c >= 'a' && c <= 'z')
183 || (c >= 'A' && c <= 'Z')
184 || (c == '@' || c == '`');
187 /* interprets a 'set attribute' (SGR) CSI escape sequence */
188 static void interpret_csi_SGR(madtty_t *rt, int param[], int pcount)
193 /* special case: reset attributes */
194 rt->curattrs = A_NORMAL;
198 for (i = 0; i < pcount; i++) {
200 #define CASE(x, op) case x: op; break
201 CASE(0, rt->curattrs = A_NORMAL);
202 CASE(1, rt->curattrs |= A_BOLD);
203 CASE(4, rt->curattrs |= A_UNDERLINE);
204 CASE(5, rt->curattrs |= A_BLINK);
205 CASE(6, rt->curattrs |= A_BLINK);
206 CASE(7, rt->curattrs |= A_REVERSE);
207 CASE(8, rt->curattrs |= A_INVIS);
208 CASE(22, rt->curattrs &= ~A_BOLD);
209 CASE(24, rt->curattrs &= ~A_UNDERLINE);
210 CASE(25, rt->curattrs &= ~A_BLINK);
211 CASE(27, rt->curattrs &= ~A_REVERSE);
212 CASE(28, rt->curattrs &= ~A_INVIS);
214 case 30 ... 37: /* fg */
216 rt->curattrs &= ~0xf0;
217 rt->curattrs |= (param[i] + 1 - 30) << 4;
219 rt->curattrs &= ~070;
220 rt->curattrs |= (7 - (param[i] - 30)) << 3;
225 rt->curattrs &= has_default ? ~0xf0 : ~070;
228 case 40 ... 47: /* bg */
230 rt->curattrs &= ~0x0f;
231 rt->curattrs |= (param[i] + 1 - 40);
233 rt->curattrs &= ~007;
234 rt->curattrs |= (param[i] - 40);
239 rt->curattrs &= has_default ? ~0x0f : ~007;
248 /* interprets an 'erase display' (ED) escape sequence */
249 static void interpret_csi_ED(madtty_t *rt, int param[], int pcount)
251 mtty_row_t *row, *start, *end;
252 attr_t attr = build_attrs(rt->curattrs);
255 if (pcount && param[0] == 2) {
257 end = rt->lines + rt->rows;
259 if (pcount && param[0] == 1) {
262 mtty_row_set(rt->curs_row, 0, rt->curs_col + 1, attr);
264 mtty_row_set(rt->curs_row, rt->curs_col,
265 rt->cols - rt->curs_col, attr);
266 start = rt->curs_row + 1;
267 end = rt->lines + rt->rows;
270 for (row = start; row < end; row++) {
271 mtty_row_set(row, 0, rt->cols, attr);
275 /* interprets a 'move cursor' (CUP) escape sequence */
276 static void interpret_csi_CUP(madtty_t *rt, int param[], int pcount)
280 rt->curs_row = rt->lines;
285 return; /* malformed */
288 rt->curs_row = rt->lines + param[0] - 1; /* convert from 1-based to 0-based */
289 rt->curs_col = param[1] - 1; /* convert from 1-based to 0-based */
291 clamp_cursor_to_bounds(rt);
294 /* Interpret the 'relative mode' sequences: CUU, CUD, CUF, CUB, CNL,
295 * CPL, CHA, HPR, VPA, VPR, HPA */
296 static void interpret_csi_C(madtty_t *rt, char verb, int param[], int pcount)
298 int n = (pcount && param[0] > 0) ? param[0] : 1;
301 case 'A': rt->curs_row -= n; break;
302 case 'B': case 'e': rt->curs_row += n; break;
303 case 'C': case 'a': rt->curs_col += n; break;
304 case 'D': rt->curs_col -= n; break;
305 case 'E': rt->curs_row += n; rt->curs_col = 0; break;
306 case 'F': rt->curs_row -= n; rt->curs_col = 0; break;
307 case 'G': case '`': rt->curs_col = param[0] - 1; break;
308 case 'd': rt->curs_row = rt->lines + param[0] - 1; break;
311 clamp_cursor_to_bounds(rt);
314 /* Interpret the 'erase line' escape sequence */
315 static void interpret_csi_EL(madtty_t *rt, int param[], int pcount)
317 attr_t attr = build_attrs(rt->curattrs);
319 switch (pcount ? param[0] : 0) {
321 mtty_row_set(rt->curs_row, 0, rt->curs_col + 1, attr);
324 mtty_row_set(rt->curs_row, 0, rt->cols, attr);
327 mtty_row_set(rt->curs_row, rt->curs_col, rt->cols - rt->curs_col,
333 /* Interpret the 'insert blanks' sequence (ICH) */
334 static void interpret_csi_ICH(madtty_t *rt, int param[], int pcount)
336 mtty_row_t *row = rt->curs_row;
337 int n = (pcount && param[0] > 0) ? param[0] : 1;
340 if (rt->curs_col + n > rt->cols) {
341 n = rt->cols - rt->curs_col;
344 for (i = rt->cols - 1; i >= rt->curs_col + n; i--) {
345 row->text[i] = row->text[i - n];
346 row->attr[i] = row->attr[i - n];
349 mtty_row_set(row, rt->curs_col, n, build_attrs(rt->curattrs));
352 /* Interpret the 'delete chars' sequence (DCH) */
353 static void interpret_csi_DCH(madtty_t *rt, int param[], int pcount)
355 mtty_row_t *row = rt->curs_row;
356 int n = (pcount && param[0] > 0) ? param[0] : 1;
359 if (rt->curs_col + n > rt->cols) {
360 n = rt->cols - rt->curs_col;
363 for (i = rt->curs_col; i < rt->cols - n; i++) {
364 row->text[i] = row->text[i + n];
365 row->attr[i] = row->attr[i + n];
368 mtty_row_set(row, rt->cols - n, n, build_attrs(rt->curattrs));
371 /* Interpret a 'scroll reverse' (SR) */
372 static void interpret_csi_SR(madtty_t *rt)
374 mtty_row_roll(rt->scroll_top, rt->scroll_bot, -1);
375 mtty_row_set(rt->scroll_top, 0, rt->cols, build_attrs(rt->curattrs));
378 /* Interpret an 'insert line' sequence (IL) */
379 static void interpret_csi_IL(madtty_t *rt, int param[], int pcount)
381 int n = (pcount && param[0] > 0) ? param[0] : 1;
383 if (rt->curs_row + n >= rt->scroll_bot) {
384 for (mtty_row_t *row = rt->curs_row; row < rt->scroll_bot; row++) {
385 mtty_row_set(row, 0, rt->cols, build_attrs(rt->curattrs));
388 mtty_row_roll(rt->curs_row, rt->scroll_bot, -n);
389 for (mtty_row_t *row = rt->curs_row; row < rt->curs_row + n; row++) {
390 mtty_row_set(row, 0, rt->cols, build_attrs(rt->curattrs));
395 /* Interpret a 'delete line' sequence (DL) */
396 static void interpret_csi_DL(madtty_t *rt, int param[], int pcount)
398 int n = (pcount && param[0] > 0) ? param[0] : 1;
400 if (rt->curs_row + n >= rt->scroll_bot) {
401 for (mtty_row_t *row = rt->curs_row; row < rt->scroll_bot; row++) {
402 mtty_row_set(row, 0, rt->cols, build_attrs(rt->curattrs));
405 mtty_row_roll(rt->curs_row, rt->scroll_bot, n);
406 for (mtty_row_t *row = rt->scroll_bot - n; row < rt->scroll_bot; row++) {
407 mtty_row_set(row, 0, rt->cols, build_attrs(rt->curattrs));
412 /* Interpret an 'erase characters' (ECH) sequence */
413 static void interpret_csi_ECH(madtty_t *rt, int param[], int pcount)
415 int n = (pcount && param[0] > 0) ? param[0] : 1;
417 if (rt->curs_col + n < rt->cols) {
418 n = rt->cols - rt->curs_col;
420 mtty_row_set(rt->curs_row, rt->curs_col, n, build_attrs(rt->curattrs));
423 /* Interpret a 'set scrolling region' (DECSTBM) sequence */
424 static void interpret_csi_DECSTBM(madtty_t *rt, int param[], int pcount)
426 int new_top, new_bot;
430 rt->scroll_top = rt->lines;
431 rt->scroll_bot = rt->lines + rt->rows;
434 return; /* malformed */
437 new_top = param[0] - 1;
440 /* clamp to bounds */
443 if (new_top >= rt->rows)
444 new_top = rt->rows - 1;
447 if (new_bot >= rt->rows)
450 /* check for range validity */
451 if (new_top < new_bot) {
452 rt->scroll_top = rt->lines + new_top;
453 rt->scroll_bot = rt->lines + new_bot;
459 static void es_interpret_csi(madtty_t *rt)
461 static int csiparam[MAX_CSI_ES_PARAMS];
463 const char *p = rt->ebuf + 1;
464 char verb = rt->ebuf[rt->elen - 1];
466 p += rt->ebuf[1] == '?'; /* CSI private mode */
468 /* parse numeric parameters */
469 while (isdigit((unsigned char)*p) || *p == ';') {
471 if (param_count >= MAX_CSI_ES_PARAMS) return; /* too long! */
472 csiparam[param_count++] = 0;
474 if (param_count == 0) csiparam[param_count++] = 0;
475 csiparam[param_count - 1] *= 10;
476 csiparam[param_count - 1] += *p - '0';
482 if (rt->ebuf[1] == '?') {
485 if (csiparam[0] == 25)
490 if (csiparam[0] == 25)
496 /* delegate handling depending on command character (verb) */
499 if (param_count == 1 && csiparam[0] == 4) /* insert mode */
503 if (param_count == 1 && csiparam[0] == 4) /* replace mode */
506 case 'm': /* it's a 'set attribute' sequence */
507 interpret_csi_SGR(rt, csiparam, param_count); break;
508 case 'J': /* it's an 'erase display' sequence */
509 interpret_csi_ED(rt, csiparam, param_count); break;
510 case 'H': case 'f': /* it's a 'move cursor' sequence */
511 interpret_csi_CUP(rt, csiparam, param_count); break;
512 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G':
513 case 'e': case 'a': case 'd': case '`':
514 /* it is a 'relative move' */
515 interpret_csi_C(rt, verb, csiparam, param_count); break;
516 case 'K': /* erase line */
517 interpret_csi_EL(rt, csiparam, param_count); break;
518 case '@': /* insert characters */
519 interpret_csi_ICH(rt, csiparam, param_count); break;
520 case 'P': /* delete characters */
521 interpret_csi_DCH(rt, csiparam, param_count); break;
522 case 'L': /* insert lines */
523 interpret_csi_IL(rt, csiparam, param_count); break;
524 case 'M': /* delete lines */
525 interpret_csi_DL(rt, csiparam, param_count); break;
526 case 'X': /* erase chars */
527 interpret_csi_ECH(rt, csiparam, param_count); break;
528 case 'r': /* set scrolling region */
529 interpret_csi_DECSTBM(rt, csiparam, param_count); break;
530 case 's': /* save cursor location */
531 rt->curs_srow = rt->curs_row - rt->lines;
532 rt->curs_scol = rt->curs_col;
534 case 'u': /* restore cursor location */
535 rt->curs_row = rt->lines + rt->curs_srow;
536 rt->curs_col = rt->curs_scol;
537 clamp_cursor_to_bounds(rt);
544 static void try_interpret_escape_seq(madtty_t *rt)
546 char lastchar = rt->ebuf[rt->elen-1];
553 interpret_csi_SR(rt);
554 cancel_escape_sequence(rt);
563 case ']': /* xterm thing */
564 if (lastchar == '\a')
572 if (is_valid_csi_ender(lastchar)) {
573 es_interpret_csi(rt);
574 cancel_escape_sequence(rt);
580 if (rt->elen + 1 >= (int)sizeof(rt->ebuf)) {
584 fprintf(stderr, "cancelled: \\033");
585 for (i = 0; i < rt->elen; i++) {
587 if (isprint(c) && c >= ' ') {
590 fprintf(stderr, "\\%03o", c);
595 cancel_escape_sequence(rt);
599 static void madtty_process_nonprinting(madtty_t *rt, wchar_t wc)
603 new_escape_sequence(rt);
607 /* do nothing for now... maybe a visual bell would be nice? */
611 if (rt->curs_col > 0)
615 case C0_HT: /* tab */
616 rt->curs_col = (rt->curs_col + 8) & ~7;
617 if (rt->curs_col >= rt->cols)
618 rt->curs_col = rt->cols - 1;
628 cursor_line_down(rt);
631 case C0_SO: /* shift out - acs */
632 rt->graphmode = true;
634 case C0_SI: /* shift in - acs */
635 rt->graphmode = false;
640 void madtty_putc(madtty_t *rt, wchar_t wc)
644 if (!rt->seen_input) {
646 kill(-rt->childpid, SIGWINCH);
650 if (wc == '\n' || (wc >= ' ' && isprint(wc))) {
653 fprintf(stderr, "\\%03o", wc);
658 assert (rt->elen + 1 < (int)sizeof(rt->ebuf));
659 rt->ebuf[rt->elen] = wc;
660 rt->ebuf[++rt->elen] = '\0';
661 try_interpret_escape_seq(rt);
662 } else if (IS_CONTROL(wc)) {
663 madtty_process_nonprinting(rt, wc);
668 // vt100 special graphics and line drawing
669 // 5f-7e standard vt100
670 // 40-5e rxvt extension for extra curses acs chars
671 static uint16_t vt100_0[62] = { // 41 .. 7e
672 0x2191, 0x2193, 0x2192, 0x2190, 0x2588, 0x259a, 0x2603, // 41-47 hi mr. snowman!
673 0, 0, 0, 0, 0, 0, 0, 0, // 48-4f
674 0, 0, 0, 0, 0, 0, 0, 0, // 50-57
675 0, 0, 0, 0, 0, 0, 0, 0x0020, // 58-5f
676 0x25c6, 0x2592, 0x2409, 0x240c, 0x240d, 0x240a, 0x00b0, 0x00b1, // 60-67
677 0x2424, 0x240b, 0x2518, 0x2510, 0x250c, 0x2514, 0x253c, 0x23ba, // 68-6f
678 0x23bb, 0x2500, 0x23bc, 0x23bd, 0x251c, 0x2524, 0x2534, 0x252c, // 70-77
679 0x2502, 0x2264, 0x2265, 0x03c0, 0x2260, 0x00a3, 0x00b7, // 78-7e
682 if (wc >= 0x41 && wc <= 0x7e && vt100_0[wc - 0x41]) {
683 wc = vt100_0[wc - 0x41];
687 width = wcwidth(wc) ?: 1;
690 if (width == 2 && rt->curs_col == rt->cols - 1) {
693 tmp->text[rt->curs_col] = 0;
694 tmp->attr[rt->curs_col] = build_attrs(rt->curattrs);
698 if (rt->curs_col >= rt->cols) {
700 cursor_line_down(rt);
707 wmemmove(tmp->text + rt->curs_col + width, tmp->text + rt->curs_col,
708 (rt->cols - rt->curs_col - width));
709 memmove(tmp->attr + rt->curs_col + width, tmp->attr + rt->curs_col,
710 (rt->cols - rt->curs_col - width) * sizeof(tmp->attr[0]));
713 tmp->text[rt->curs_col] = wc;
714 tmp->attr[rt->curs_col] = build_attrs(rt->curattrs);
717 tmp->text[rt->curs_col] = 0;
718 tmp->attr[rt->curs_col] = build_attrs(rt->curattrs);
724 int madtty_process(madtty_t *rt)
733 res = read(rt->pty, rt->rbuf + rt->rlen, sizeof(rt->rbuf) - rt->rlen);
738 while (pos < rt->rlen) {
742 len = (ssize_t)mbrtowc(&wc, rt->rbuf + pos, rt->rlen - pos, &rt->ps);
745 memmove(rt->rbuf, rt->rbuf + pos, rt->rlen);
754 pos += len ? len : 1;
759 memmove(rt->rbuf, rt->rbuf + pos, rt->rlen);
763 madtty_t *madtty_create(int rows, int cols)
768 if (rows <= 0 || cols <= 0)
771 rt = (madtty_t*)calloc(sizeof(madtty_t), 1);
775 /* record dimensions */
779 /* default mode is replace */
782 /* create the cell matrix */
783 rt->lines = (mtty_row_t*)calloc(sizeof(mtty_row_t), rt->rows);
784 for (i = 0; i < rt->rows; i++) {
785 rt->lines[i].text = (wchar_t *)calloc(sizeof(wchar_t), rt->cols);
786 rt->lines[i].attr = (uint16_t *)calloc(sizeof(uint16_t), rt->cols);
789 rt->pty = -1; /* no pty for now */
791 /* initialization of other public fields */
792 rt->curs_row = rt->lines;
794 rt->curattrs = A_NORMAL; /* white text over black background */
796 /* initial scrolling area is the whole window */
797 rt->scroll_top = rt->lines;
798 rt->scroll_bot = rt->lines + rt->rows;
803 void madtty_destroy(madtty_t *rt)
809 for (i = 0; i < rt->rows; i++) {
810 free(rt->lines[i].text);
811 free(rt->lines[i].attr);
817 void madtty_draw(madtty_t *rt, WINDOW *win, int srow, int scol)
820 for (int i = 0; i < rt->rows; i++) {
821 mtty_row_t *row = rt->lines + i;
827 wmove(win, srow + i, scol);
828 for (int j = 0; j < rt->cols; j++) {
829 if (!j || row->attr[j] != row->attr[j - 1])
830 wattrset(win, (attr_t)row->attr[j] << NCURSES_ATTR_SHIFT);
831 if (row->text[j] >= 128) {
832 char buf[MB_CUR_MAX + 1];
835 len = wcrtomb(buf, row->text[j], NULL);
836 waddnstr(win, buf, len);
837 if (wcwidth(row->text[j]) > 1)
840 waddch(win, row->text[j] > ' ' ? row->text[j] : ' ');
846 wmove(win, srow + rt->curs_row - rt->lines, scol + rt->curs_col);
847 curs_set(!rt->curshid);
850 /******************************************************/
852 pid_t madtty_forkpty(madtty_t *rt, const char *path, const char *argv[])
857 ws.ws_row = rt->rows;
858 ws.ws_col = rt->cols;
859 ws.ws_xpixel = ws.ws_ypixel = 0;
861 pid = forkpty(&rt->pty, NULL, NULL, &ws);
867 setenv("TERM", "rxvt", 1);
868 execv(path, (char *const*)argv);
869 fprintf(stderr, "\nexecv() failed.\nCommand: '%s'\n", argv[0]);
873 return rt->childpid = pid;
876 void madtty_keypress(madtty_t *rt, int keycode)
878 char c = (char)keycode;
883 if (keycode == KEY_F(1)) {
884 #define MIN(a, b) ((a < (b)) ? a : (b))
885 kill(-rt->childpid, SIGWINCH);
886 rt->scroll_bot = MIN(rt->scroll_bot, rt->lines + rt->rows);
887 rt->curs_row = MIN(rt->curs_row, rt->lines + rt->rows);
888 printf(stderr, "%d\n", rt->rows);
892 if (keycode >= 0 && keycode < KEY_MAX && keytable[keycode]) {
893 buf = keytable[keycode];
894 len = strlen(keytable[keycode]);
901 int res = write(rt->pty, buf, len);
902 if (res < 0 && errno != EAGAIN && errno != EINTR)
910 void madtty_initialize(void)
912 setlocale(LC_ALL, "");
917 nodelay(stdscr, TRUE);
918 keypad(stdscr, TRUE);
923 use_default_colors();
924 assume_default_colors(-1, -1);
927 for (int bg = -1; bg < 8; bg++) {
928 for (int fg = -1; fg < 8; fg++) {
929 init_pair((fg + 1) * 16 + bg + 1, fg, bg);
933 for (int bg = 0; bg < 8; bg++) {
934 for (int fg = 0; fg < 8; fg++) {
935 init_pair((7 - fg) * 8 + bg, fg, bg);