diff options
author | Thomas Adam <thomas@xteddy.org> | 2017-04-06 11:10:17 +0100 |
---|---|---|
committer | Thomas Adam <thomas@xteddy.org> | 2017-04-06 11:10:17 +0100 |
commit | 5f662d91db658abbcd46d7a678c0250754be35e3 (patch) | |
tree | bed316d0ce8c4a770b5e42608a36dafc0a9eee2d /tty.c | |
parent | 05c97d7fe9ede1b9d185ed21242eb8470350affc (diff) | |
parent | 94b71bcb6403d381515319b08a85878b829785d5 (diff) | |
download | rtmux-5f662d91db658abbcd46d7a678c0250754be35e3.tar.gz rtmux-5f662d91db658abbcd46d7a678c0250754be35e3.tar.bz2 rtmux-5f662d91db658abbcd46d7a678c0250754be35e3.zip |
Merge branch 'obsd-master'
Conflicts:
server-client.c
tmux.1
Diffstat (limited to 'tty.c')
-rw-r--r-- | tty.c | 46 |
1 files changed, 26 insertions, 20 deletions
@@ -94,8 +94,6 @@ tty_create_log(void) int tty_init(struct tty *tty, struct client *c, int fd, char *term) { - char *path; - if (!isatty(fd)) return (-1); @@ -105,12 +103,10 @@ tty_init(struct tty *tty, struct client *c, int fd, char *term) tty->term_name = xstrdup("unknown"); else tty->term_name = xstrdup(term); + tty->fd = fd; tty->client = c; - if ((path = ttyname(fd)) == NULL) - return (-1); - tty->path = xstrdup(path); tty->cstyle = 0; tty->ccolour = xstrdup(""); @@ -125,8 +121,9 @@ tty_init(struct tty *tty, struct client *c, int fd, char *term) int tty_resize(struct tty *tty) { - struct winsize ws; - u_int sx, sy; + struct client *c = tty->client; + struct winsize ws; + u_int sx, sy; if (ioctl(tty->fd, TIOCGWINSZ, &ws) != -1) { sx = ws.ws_col; @@ -139,7 +136,8 @@ tty_resize(struct tty *tty) sx = 80; sy = 24; } - log_debug("%s: %s now %ux%u", __func__, tty->path, sx, sy); + log_debug("%s: %s now %ux%u", __func__, c->name, sx, sy); + if (!tty_set_size(tty, sx, sy)) return (0); tty_invalidate(tty); @@ -160,13 +158,14 @@ static void tty_read_callback(__unused int fd, __unused short events, void *data) { struct tty *tty = data; + struct client *c = tty->client; size_t size = EVBUFFER_LENGTH(tty->in); int nread; nread = evbuffer_read(tty->in, tty->fd, -1); if (nread == -1) return; - log_debug("%s: read %d bytes (already %zu)", tty->path, nread, size); + log_debug("%s: read %d bytes (already %zu)", c->name, nread, size); while (tty_keys_next(tty)) ; @@ -176,13 +175,14 @@ static void tty_write_callback(__unused int fd, __unused short events, void *data) { struct tty *tty = data; + struct client *c = tty->client; size_t size = EVBUFFER_LENGTH(tty->out); int nwrite; nwrite = evbuffer_write(tty->out, tty->fd); if (nwrite == -1) return; - log_debug("%s: wrote %d bytes (of %zu)", tty->path, nwrite, size); + log_debug("%s: wrote %d bytes (of %zu)", c->name, nwrite, size); if (EVBUFFER_LENGTH(tty->out) != 0) event_add(&tty->event_out, NULL); @@ -351,7 +351,6 @@ tty_free(struct tty *tty) tty_close(tty); free(tty->ccolour); - free(tty->path); free(tty->term_name); } @@ -424,8 +423,10 @@ tty_putcode_ptr2(struct tty *tty, enum tty_code_code code, const void *a, static void tty_add(struct tty *tty, const char *buf, size_t len) { + struct client *c = tty->client; + evbuffer_add(tty->out, buf, len); - log_debug("%s: %.*s", tty->path, (int)len, (const char *)buf); + log_debug("%s: %.*s", c->name, (int)len, (const char *)buf); if (tty_log_fd != -1) write(tty_log_fd, buf, len); @@ -602,8 +603,17 @@ tty_emulate_repeat(struct tty *tty, enum tty_code_code code, static void tty_repeat_space(struct tty *tty, u_int n) { - while (n-- > 0) - tty_putc(tty, ' '); + static char s[500]; + + if (*s != ' ') + memset(s, ' ', sizeof s); + + while (n > sizeof s) { + tty_putn(tty, s, sizeof s, sizeof s); + n -= sizeof s; + } + if (n != 0) + tty_putn(tty, s, n, n); } /* @@ -856,8 +866,6 @@ tty_cmd_deletecharacter(struct tty *tty, const struct tty_ctx *ctx) void tty_cmd_clearcharacter(struct tty *tty, const struct tty_ctx *ctx) { - u_int i; - tty_attributes(tty, &grid_default_cell, ctx->wp); tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy); @@ -865,10 +873,8 @@ tty_cmd_clearcharacter(struct tty *tty, const struct tty_ctx *ctx) if (tty_term_has(tty->term, TTYC_ECH) && !tty_fake_bce(tty, ctx->wp, ctx->bg)) tty_putcode1(tty, TTYC_ECH, ctx->num); - else { - for (i = 0; i < ctx->num; i++) - tty_putc(tty, ' '); - } + else + tty_repeat_space(tty, ctx->num); } void |