diff options
author | Nicholas Marriott <nicm@openbsd.org> | 2009-11-04 21:47:42 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@openbsd.org> | 2009-11-04 21:47:42 +0000 |
commit | 7342615c7ddd9b99820bd9c03fda2afe7bc868d3 (patch) | |
tree | 4b5ac210a0af55bb3ea1f5d9aebcd91456d397d7 /tty.c | |
parent | abb728684b00c82460ea439c8df16d3f1018c826 (diff) |
Switch tty fds over to a bufferevent.
Diffstat (limited to 'tty.c')
-rw-r--r-- | tty.c | 30 |
1 files changed, 21 insertions, 9 deletions
@@ -28,6 +28,8 @@ #include "tmux.h" +void tty_error_callback(struct bufferevent *, short, void *); + void tty_fill_acs(struct tty *); int tty_try_256(struct tty *, u_char, const char *); @@ -108,11 +110,11 @@ tty_open(struct tty *tty, const char *overrides, char **cause) } tty->flags |= TTY_OPENED; - tty->in = buffer_create(BUFSIZ); - tty->out = buffer_create(BUFSIZ); - tty->flags &= ~(TTY_NOCURSOR|TTY_FREEZE|TTY_ESCAPE); + tty->event = bufferevent_new( + tty->fd, NULL, NULL, tty_error_callback, tty); + tty_start_tty(tty); tty_keys_init(tty); @@ -123,6 +125,13 @@ tty_open(struct tty *tty, const char *overrides, char **cause) } void +tty_error_callback( + unused struct bufferevent *bufev, unused short what, unused void *data) +{ + fatalx("lost terminal"); +} + +void tty_start_tty(struct tty *tty) { struct termios tio; @@ -136,6 +145,8 @@ tty_start_tty(struct tty *tty) if (fcntl(tty->fd, F_SETFL, mode|O_NONBLOCK) == -1) fatal("fcntl failed"); + bufferevent_enable(tty->event, EV_READ|EV_WRITE); + if (tcgetattr(tty->fd, &tty->tio) != 0) fatal("tcgetattr failed"); memcpy(&tio, &tty->tio, sizeof tio); @@ -187,6 +198,8 @@ tty_stop_tty(struct tty *tty) return; tty->flags &= ~TTY_STARTED; + bufferevent_disable(tty->event, EV_READ|EV_WRITE); + /* * Be flexible about error handling and try not kill the server just * because the fd is invalid. Things like ssh -t can easily leave us @@ -249,12 +262,11 @@ tty_close(struct tty *tty) tty_stop_tty(tty); if (tty->flags & TTY_OPENED) { + bufferevent_free(tty->event); + tty_term_free(tty->term); tty_keys_free(tty); - buffer_destroy(tty->in); - buffer_destroy(tty->out); - tty->flags &= ~TTY_OPENED; } @@ -308,7 +320,7 @@ tty_puts(struct tty *tty, const char *s) { if (*s == '\0') return; - buffer_write(tty->out, s, strlen(s)); + bufferevent_write(tty->event, s, strlen(s)); if (tty->log_fd != -1) write(tty->log_fd, s, strlen(s)); @@ -321,7 +333,7 @@ tty_putc(struct tty *tty, u_char ch) if (tty->cell.attr & GRID_ATTR_CHARSET) ch = tty_get_acs(tty, ch); - buffer_write8(tty->out, ch); + bufferevent_write(tty->event, &ch, 1); if (ch >= 0x20 && ch != 0x7f) { sx = tty->sx; @@ -348,7 +360,7 @@ tty_pututf8(struct tty *tty, const struct grid_utf8 *gu) for (i = 0; i < UTF8_SIZE; i++) { if (gu->data[i] == 0xff) break; - buffer_write8(tty->out, gu->data[i]); + bufferevent_write(tty->event, &gu->data[i], 1); if (tty->log_fd != -1) write(tty->log_fd, &gu->data[i], 1); } |