aboutsummaryrefslogtreecommitdiff
path: root/tty.c
diff options
context:
space:
mode:
authornicm <nicm>2017-04-05 10:49:46 +0000
committernicm <nicm>2017-04-05 10:49:46 +0000
commit9b28200578670183a0dc70f1d16d5642101a6982 (patch)
tree745e1455c441ab36e2b39ec9398bfb40c14c9a56 /tty.c
parentab4a4b2ad0ce2c8fdb485bc0fe871571181eace8 (diff)
downloadrtmux-9b28200578670183a0dc70f1d16d5642101a6982.tar.gz
rtmux-9b28200578670183a0dc70f1d16d5642101a6982.tar.bz2
rtmux-9b28200578670183a0dc70f1d16d5642101a6982.zip
Give each client a name. This defaults to the tty name as before but
falls back to an alternative if the tty name is not available. This is clearer than overloading the client ttyname member and allows us to remove the path stored in the tty struct, it should always be the same as the client.
Diffstat (limited to 'tty.c')
-rw-r--r--tty.c46
1 files changed, 26 insertions, 20 deletions
diff --git a/tty.c b/tty.c
index 8d54007b..04a673fc 100644
--- a/tty.c
+++ b/tty.c
@@ -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