mirror of
https://github.com/tmux/tmux.git
synced 2025-09-02 05:21:10 +00:00
Switch tty fds over to a bufferevent.
This commit is contained in:
30
tty.c
30
tty.c
@ -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);
|
||||
@ -122,6 +124,13 @@ tty_open(struct tty *tty, const char *overrides, char **cause)
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
tty_error_callback(
|
||||
unused struct bufferevent *bufev, unused short what, unused void *data)
|
||||
{
|
||||
fatalx("lost terminal");
|
||||
}
|
||||
|
||||
void
|
||||
tty_start_tty(struct tty *tty)
|
||||
{
|
||||
@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user