static void update_size(void) { update_term_size(); cellbuf_resize(&back_buffer, termw, termh); cellbuf_resize(&front_buffer, termw, termh); cellbuf_clear(&front_buffer); send_clear(); }
int tb_init_fd(int inout_) { inout = inout_; if (inout == -1) { return TB_EFAILED_TO_OPEN_TTY; } if (init_term() < 0) { close(inout); return TB_EUNSUPPORTED_TERMINAL; } if (pipe(winch_fds) < 0) { close(inout); return TB_EPIPE_TRAP_ERROR; } struct sigaction sa; memset(&sa, 0, sizeof(sa)); sa.sa_handler = sigwinch_handler; sa.sa_flags = 0; sigaction(SIGWINCH, &sa, 0); tcgetattr(inout, &orig_tios); struct termios tios; memcpy(&tios, &orig_tios, sizeof(tios)); tios.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON); tios.c_oflag &= ~OPOST; tios.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN); tios.c_cflag &= ~(CSIZE | PARENB); tios.c_cflag |= CS8; tios.c_cc[VMIN] = 0; tios.c_cc[VTIME] = 0; tcsetattr(inout, TCSAFLUSH, &tios); bytebuffer_init(&input_buffer, 128); bytebuffer_init(&output_buffer, 32 * 1024); bytebuffer_puts(&output_buffer, funcs[T_ENTER_CA]); bytebuffer_puts(&output_buffer, funcs[T_ENTER_KEYPAD]); bytebuffer_puts(&output_buffer, funcs[T_HIDE_CURSOR]); send_clear(); update_term_size(); cellbuf_init(&back_buffer, termw, termh); cellbuf_init(&front_buffer, termw, termh); cellbuf_clear(&back_buffer); cellbuf_clear(&front_buffer); return 0; }
int tb_init(void) { out = open("/dev/tty", O_WRONLY); in = fopen("/dev/tty", "r"); if (out == -1 || !in) return TB_EFAILED_TO_OPEN_TTY; out_fileno = out; in_fileno = fileno(in); if (init_term() < 0) return TB_EUNSUPPORTED_TERMINAL; if (pipe(winch_fds) < 0) return TB_EPIPE_TRAP_ERROR; struct sigaction sa; sa.sa_handler = sigwinch_handler; sa.sa_flags = 0; sigaction(SIGWINCH, &sa, 0); tcgetattr(out_fileno, &orig_tios); struct termios tios; memcpy(&tios, &orig_tios, sizeof(tios)); tios.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON); tios.c_oflag &= ~OPOST; tios.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN); tios.c_cflag &= ~(CSIZE | PARENB); tios.c_cflag |= CS8; tios.c_cc[VMIN] = 0; tios.c_cc[VTIME] = 0; tcsetattr(out_fileno, TCSAFLUSH, &tios); memstream_init(&write_buffer, out_fileno, write_buffer_data, sizeof(write_buffer_data)); memstream_puts(&write_buffer, funcs[T_ENTER_CA]); memstream_puts(&write_buffer, funcs[T_ENTER_KEYPAD]); memstream_puts(&write_buffer, funcs[T_HIDE_CURSOR]); send_clear(); update_term_size(); cellbuf_init(&back_buffer, termw, termh); cellbuf_init(&front_buffer, termw, termh); cellbuf_clear(&back_buffer); cellbuf_clear(&front_buffer); init_ringbuffer(&inbuf, 4096); return 0; }
static bool flush_ringbuf_client(void) { char buf[1024]; /* 書くデータなし */ if (fresh_queue.next == fresh_queue.tail) return (FALSE); /* まだ書くべき時でない */ if (fresh_queue.time[fresh_queue.next] > get_current_time() - epoch_time) return (FALSE); /* 時間情報(区切り)が得られるまで書く */ while (get_nextbuf(buf)) { char id; int x, y, len, col; int i; unsigned char tmp1, tmp2, tmp3, tmp4; char *mesg; sscanf(buf, "%c%c%c%c%c", &id, &tmp1, &tmp2, &tmp3, &tmp4); x = tmp1-1; y = tmp2-1; len = tmp3; col = tmp4; if (id == 's') { col = tmp3; mesg = &buf[4]; } else mesg = &buf[5]; #ifndef WINDOWS win2unix(col, mesg); #endif switch (id) { case 't': /* 通常 */ #ifdef SJIS euc2sjis(mesg); #endif update_term_size(x, y, len); (void)((*angband_term[0]->text_hook)(x, y, len, (byte)col, mesg)); strncpy(&Term->scr->c[y][x], mesg, len); for (i = x; i < x+len; i++) { Term->scr->a[y][i] = col; } break; case 'n': /* 繰り返し */ for (i = 1; i < len; i++) { mesg[i] = mesg[0]; } mesg[i] = '\0'; update_term_size(x, y, len); (void)((*angband_term[0]->text_hook)(x, y, len, (byte)col, mesg)); strncpy(&Term->scr->c[y][x], mesg, len); for (i = x; i < x+len; i++) { Term->scr->a[y][i] = col; } break; case 's': /* 一文字 */ update_term_size(x, y, 1); (void)((*angband_term[0]->text_hook)(x, y, 1, (byte)col, mesg)); strncpy(&Term->scr->c[y][x], mesg, 1); Term->scr->a[y][x] = col; break; case 'w': update_term_size(x, y, len); (void)((*angband_term[0]->wipe_hook)(x, y, len)); break; case 'x': if (x == TERM_XTRA_CLEAR) Term_clear(); (void)((*angband_term[0]->xtra_hook)(x, 0)); break; case 'c': update_term_size(x, y, 1); (void)((*angband_term[0]->curs_hook)(x, y)); break; case 'C': update_term_size(x, y, 1); (void)((*angband_term[0]->bigcurs_hook)(x, y)); break; } } fresh_queue.next++; if (fresh_queue.next == FRESH_QUEUE_SIZE) fresh_queue.next = 0; return (TRUE); }