diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2009-11-04 21:47:43 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2009-11-04 21:47:43 +0000 |
commit | 61f1e016a392ec594bd75c723836afda9e8af879 (patch) | |
tree | 9e4a33bd9e94ea82a64f94ea857ccda80f47e47a /usr.bin/tmux/tty.c | |
parent | 4a10595dee0afa24fc6f3744ea05adc59019ae4e (diff) |
Switch tty fds over to a bufferevent.
Diffstat (limited to 'usr.bin/tmux/tty.c')
-rw-r--r-- | usr.bin/tmux/tty.c | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/usr.bin/tmux/tty.c b/usr.bin/tmux/tty.c index c07ac40a83e..d2296f17d4c 100644 --- a/usr.bin/tmux/tty.c +++ b/usr.bin/tmux/tty.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tty.c,v 1.65 2009/11/04 15:59:27 nicm Exp $ */ +/* $OpenBSD: tty.c,v 1.66 2009/11/04 21:47:42 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -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); } |