diff options
author | Nicholas Marriott <nicholas.marriott@gmail.com> | 2007-11-27 19:23:34 +0000 |
---|---|---|
committer | Nicholas Marriott <nicholas.marriott@gmail.com> | 2007-11-27 19:23:34 +0000 |
commit | 76c8a590db14131928f79123adcab934a3825501 (patch) | |
tree | 359cbfac219a68d5137bd3ec02b31ecb33cbd288 | |
parent | 97eca99d0bae6c4fdfc38a6f42d42f05c8faac4b (diff) |
Big internal reorganisation to move tty control into parent.
-rw-r--r-- | CHANGES | 12 | ||||
-rw-r--r-- | Makefile | 7 | ||||
-rw-r--r-- | TODO | 17 | ||||
-rw-r--r-- | buffer-poll.c | 23 | ||||
-rw-r--r-- | buffer.c | 43 | ||||
-rw-r--r-- | client-msg.c | 25 | ||||
-rw-r--r-- | client.c | 61 | ||||
-rw-r--r-- | cmd-attach-session.c | 9 | ||||
-rw-r--r-- | cmd-copy-mode.c | 4 | ||||
-rw-r--r-- | cmd-list-clients.c | 6 | ||||
-rw-r--r-- | cmd-new-session.c | 13 | ||||
-rw-r--r-- | cmd-scroll-mode.c | 4 | ||||
-rw-r--r-- | input-keys.c | 10 | ||||
-rw-r--r-- | input.c | 217 | ||||
-rw-r--r-- | key-bindings.c | 4 | ||||
-rw-r--r-- | local.c | 793 | ||||
-rw-r--r-- | resize.c | 6 | ||||
-rw-r--r-- | screen.c | 155 | ||||
-rw-r--r-- | server-fn.c | 266 | ||||
-rw-r--r-- | server-msg.c | 44 | ||||
-rw-r--r-- | server.c | 77 | ||||
-rw-r--r-- | status.c | 87 | ||||
-rw-r--r-- | tmux.h | 206 | ||||
-rw-r--r-- | tty-keys.c | 273 | ||||
-rw-r--r-- | tty-write.c | 107 | ||||
-rw-r--r-- | tty.c | 401 | ||||
-rw-r--r-- | window-copy.c | 277 | ||||
-rw-r--r-- | window-more.c | 138 | ||||
-rw-r--r-- | window-scroll.c | 178 | ||||
-rw-r--r-- | window.c | 22 |
30 files changed, 1570 insertions, 1915 deletions
@@ -1,3 +1,13 @@ +27 November 2007 + +* Big internal reorganisation. Rather than leaving control of the tty solely in + the client and piping all data through a socket to it, change so that the + server opens the tty again and reads and writes to it directly. This avoids + a lot of buffering and copying.Also reorganise the redrawing stuff so that + everything goes through screen_draw_* - this makes the code simpler, but + still needs broken up more, and all the ways of writing to screens should be + more consistent. + 26 November 2007 * Rather than shifting up one line at a time once the history is full, @@ -273,4 +283,4 @@ (including mutt, emacs). No status bar yet and no key remapping or other customisation. -$Id: CHANGES,v 1.86 2007-11-26 22:18:57 nicm Exp $ +$Id: CHANGES,v 1.87 2007-11-27 19:23:32 nicm Exp $ @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.48 2007-11-23 17:52:54 nicm Exp $ +# $Id: Makefile,v 1.49 2007-11-27 19:23:33 nicm Exp $ .SUFFIXES: .c .o .y .h .PHONY: clean update-index.html upload-index.html @@ -17,7 +17,7 @@ META?= \002 # C-b SRCS= tmux.c server.c server-msg.c server-fn.c buffer.c buffer-poll.c status.c \ xmalloc.c xmalloc-debug.c input.c input-keys.c screen.c screen-display.c \ - window.c session.c local.c log.c client.c client-msg.c client-fn.c \ + window.c session.c log.c client.c client-msg.c client-fn.c \ key-string.c key-bindings.c resize.c cmd.c cmd-new-session.c \ cmd-detach-client.c cmd-list-sessions.c cmd-new-window.c cmd-bind-key.c \ cmd-unbind-key.c cmd-previous-window.c cmd-last-window.c cmd-list-keys.c \ @@ -27,7 +27,8 @@ SRCS= tmux.c server.c server-msg.c server-fn.c buffer.c buffer-poll.c status.c \ cmd-link-window.c cmd-unlink-window.c cmd-next-window.c \ cmd-swap-window.c cmd-rename-session.c cmd-kill-session.c \ cmd-switch-client.c cmd-has-session.c cmd-scroll-mode.c cmd-copy-mode.c \ - cmd-paste-buffer.c window-scroll.c window-more.c window-copy.c + cmd-paste-buffer.c window-scroll.c window-more.c window-copy.c \ + tty.c tty-keys.c tty-write.c CC?= cc INCDIRS+= -I. -I- -I/usr/local/include @@ -1,31 +1,16 @@ -- it would be nice if there wasn't so much copying buffers about, audit uses - useful env vars like WINDOW? -- sort out who controls the buffers in local.c a bit - better checking/emulation for missing term requirements - alt charset, borders etc (terminfo(5)/Line Graphics) - new window command prompt - mouse handling and some other bits elinks needs -- server doesn't handle SIGTERM anymore... -- the whole input/screen/local thing sucks a bit, reorganise/redesign it - line mode/char-at-a-time mode a la telnet? -- some of the uses of buffers really sucks. buffer_reverse_add/remove, - and buffer_insert_range/delete_range are abominations. this should be - rethought - handle ioctl/termios stuff on window sockets - figure out once and for all what is going on with backspace and del backspace should be translated per the termios setting. del passed through? - window creation/idle time -- attributes could be 8 not 16 bits - profile/optimise, particularly (i suspect) input.c -- tidy up input.c a bit - decide about customised status line -- client could pass term/tty fd up to server and then do nothing. what problems - would this cause? -- need access to all terminfo data at once... signals? -- cleanup/redesign IPC - IPC is slightly arse-about-face: overhead? 8-byte header for - each packet... hrm. already scanning output for \e, could add an extra - byte to it for message - could use bsearch all over the place or get rid of smaller tables (clientmsg) - better errors when creating new windows/sessions (how?) - commands should have to care less about CMD_KEY @@ -71,6 +56,8 @@ in $x time (need window creation/use times) - lift SHRT_MAX limits for history - audit copy/scroll and other modes for problems with very small windows +- screen_draw_* moved out/renamed (accept TTY_*?) +- SIGWINCH can probably be handled in server -- For 0.2 -------------------------------------------------------------------- - window splitting? diff --git a/buffer-poll.c b/buffer-poll.c index 06cbf81f..50785e54 100644 --- a/buffer-poll.c +++ b/buffer-poll.c @@ -1,4 +1,4 @@ -/* $Id: buffer-poll.c,v 1.2 2007-11-07 19:41:17 nicm Exp $ */ +/* $Id: buffer-poll.c,v 1.3 2007-11-27 19:23:33 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -53,3 +53,24 @@ buffer_poll(struct pollfd *pfd, struct buffer *in, struct buffer *out) } return (0); } + +/* Flush buffer output to socket. */ +void +buffer_flush(int fd, struct buffer *in, struct buffer *out) +{ + struct pollfd pfd; + + while (BUFFER_USED(out) > 0) { + pfd.fd = fd; + pfd.events = POLLIN|POLLOUT; + + if (poll(&pfd, 1, INFTIM) == -1) { + if (errno == EAGAIN || errno == EINTR) + continue; + fatal("poll failed"); + } + + if (buffer_poll(&pfd, in, out) != 0) + break; + } +} @@ -1,4 +1,4 @@ -/* $Id: buffer.c,v 1.2 2007-07-25 23:13:18 nicm Exp $ */ +/* $Id: buffer.c,v 1.3 2007-11-27 19:23:33 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -179,3 +179,44 @@ buffer_read(struct buffer *b, void *data, size_t size) memcpy(data, BUFFER_OUT(b), size); buffer_remove(b, size); } + +/* Store an 8-bit value. */ +void +buffer_write8(struct buffer *b, uint8_t n) +{ + buffer_ensure(b, 1); + BUFFER_IN(b)[0] = n; + buffer_add(b, 1); +} + +/* Store a 16-bit value. */ +void +buffer_write16(struct buffer *b, uint16_t n) +{ + buffer_ensure(b, 2); + BUFFER_IN(b)[0] = n & 0xff; + BUFFER_IN(b)[1] = n >> 8; + buffer_add(b, 2); +} + +/* Extract an 8-bit value. */ +uint8_t +buffer_read8(struct buffer *b) +{ + uint8_t n; + + n = BUFFER_OUT(b)[0]; + buffer_remove(b, 1); + return (n); +} + +/* Extract a 16-bit value. */ +uint16_t +buffer_read16(struct buffer *b) +{ + uint16_t n; + + n = BUFFER_OUT(b)[0] | (BUFFER_OUT(b)[1] << 8); + buffer_remove(b, 2); + return (n); +} diff --git a/client-msg.c b/client-msg.c index c334fc48..4e299bc6 100644 --- a/client-msg.c +++ b/client-msg.c @@ -1,4 +1,4 @@ -/* $Id: client-msg.c,v 1.10 2007-10-19 20:50:01 nicm Exp $ */ +/* $Id: client-msg.c,v 1.11 2007-11-27 19:23:33 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -25,7 +25,6 @@ #include "tmux.h" -int client_msg_fn_data(struct hdr *, struct client_ctx *, char **); int client_msg_fn_detach(struct hdr *, struct client_ctx *, char **); int client_msg_fn_error(struct hdr *, struct client_ctx *, char **); int client_msg_fn_exit(struct hdr *, struct client_ctx *, char **); @@ -38,11 +37,9 @@ struct client_msg { int (*fn)(struct hdr *, struct client_ctx *, char **); }; struct client_msg client_msg_table[] = { - { MSG_DATA, client_msg_fn_data }, { MSG_DETACH, client_msg_fn_detach }, { MSG_ERROR, client_msg_fn_error }, { MSG_EXIT, client_msg_fn_exit }, - { MSG_PAUSE, client_msg_fn_pause }, }; #define NCLIENTMSG (sizeof client_msg_table / sizeof client_msg_table[0]) @@ -72,26 +69,6 @@ client_msg_dispatch(struct client_ctx *cctx, char **error) } int -client_msg_fn_data( - struct hdr *hdr, struct client_ctx *cctx, unused char **error) -{ - local_output(cctx->srv_in, hdr->size); - return (0); -} - -int -client_msg_fn_pause( - struct hdr *hdr, unused struct client_ctx *cctx, unused char **error) -{ - if (hdr->size != 0) - fatalx("bad MSG_PAUSE size"); - - cctx->flags |= CCTX_PAUSE; - - return (0); -} - -int client_msg_fn_error(struct hdr *hdr, struct client_ctx *cctx, char **error) { if (hdr->size > SIZE_MAX - 1) @@ -1,4 +1,4 @@ -/* $Id: client.c,v 1.22 2007-11-26 20:36:30 nicm Exp $ */ +/* $Id: client.c,v 1.23 2007-11-27 19:23:33 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -33,7 +33,6 @@ #include "tmux.h" void client_handle_winch(struct client_ctx *); -int client_process_local(struct client_ctx *, char **); int client_init(const char *path, struct client_ctx *cctx, int start_server) @@ -113,6 +112,7 @@ retry: if (ttyname_r(STDIN_FILENO, data.tty, sizeof data.tty) != 0) fatal("ttyname_r failed"); client_write_server(cctx, MSG_IDENTIFY, &data, sizeof data); + cmd_send_string(cctx->srv_out, getenv("TERM")); } return (0); @@ -121,13 +121,11 @@ retry: int client_main(struct client_ctx *cctx) { - struct pollfd pfds[2]; + struct pollfd pfd; char *error; int timeout; siginit(); - if ((cctx->loc_fd = local_init(&cctx->loc_in, &cctx->loc_out)) == -1) - return (1); logfile("client"); #ifndef NO_SETPROCTITLE @@ -140,34 +138,20 @@ client_main(struct client_ctx *cctx) if (sigwinch) client_handle_winch(cctx); - pfds[0].fd = cctx->srv_fd; - pfds[0].events = POLLIN; + pfd.fd = cctx->srv_fd; + pfd.events = POLLIN; if (BUFFER_USED(cctx->srv_out) > 0) - pfds[0].events |= POLLOUT; - pfds[1].fd = cctx->loc_fd; - pfds[1].events = POLLIN; - if (BUFFER_USED(cctx->loc_out) > 0) - pfds[1].events |= POLLOUT; + pfd.events |= POLLOUT; - if (poll(pfds, 2, timeout) == -1) { + if (poll(&pfd, 1, timeout) == -1) { if (errno == EAGAIN || errno == EINTR) continue; fatal("poll failed"); } - if (buffer_poll(&pfds[0], cctx->srv_in, cctx->srv_out) != 0) + if (buffer_poll(&pfd, cctx->srv_in, cctx->srv_out) != 0) goto server_dead; - if (buffer_poll(&pfds[1], cctx->loc_in, cctx->loc_out) != 0) - goto local_dead; - if (cctx->flags & CCTX_PAUSE) { - usleep(750000); - cctx->flags = 0; - } - - if (client_process_local(cctx, &error) == -1) - goto out; - switch (client_msg_dispatch(cctx, &error)) { case -1: goto out; @@ -183,8 +167,6 @@ client_main(struct client_ctx *cctx) } out: - local_done(); - if (sigterm) { printf("[terminated]\n"); return (1); @@ -204,14 +186,8 @@ out: return (1); server_dead: - local_done(); - printf("[lost server]\n"); return (0); - -local_dead: - /* Can't do much here. Log and die. */ - fatalx("local socket dead"); } void @@ -229,24 +205,3 @@ client_handle_winch(struct client_ctx *cctx) sigwinch = 0; } - -int -client_process_local(struct client_ctx *cctx, unused char **error) -{ - struct buffer *b; - int key; - - b = buffer_create(BUFSIZ); - while ((key = local_key()) != KEYC_NONE) - input_store16(b, (uint16_t) key); - - log_debug("transmitting %zu bytes of input", BUFFER_USED(b)); - if (BUFFER_USED(b) != 0) { - client_write_server( - cctx, MSG_KEYS, BUFFER_OUT(b), BUFFER_USED(b)); - } - - buffer_destroy(b); - return (0); -} - diff --git a/cmd-attach-session.c b/cmd-attach-session.c index 621c2bfd..930b756b 100644 --- a/cmd-attach-session.c +++ b/cmd-attach-session.c @@ -1,4 +1,4 @@ -/* $Id: cmd-attach-session.c,v 1.9 2007-11-16 21:12:31 nicm Exp $ */ +/* $Id: cmd-attach-session.c,v 1.10 2007-11-27 19:23:33 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -83,6 +83,7 @@ void cmd_attach_session_exec(void *ptr, struct cmd_ctx *ctx) { struct cmd_attach_session_data *data = ptr; + char *cause; if (ctx->flags & CMD_KEY) return; @@ -92,6 +93,12 @@ cmd_attach_session_exec(void *ptr, struct cmd_ctx *ctx) return; } + if (tty_open(&ctx->cmdclient->tty, &cause) != 0) { + ctx->error(ctx, "%s", cause); + xfree(cause); + return; + } + if (data->flag_detach) server_write_session(ctx->session, MSG_DETACH, NULL, 0); ctx->cmdclient->session = ctx->session; diff --git a/cmd-copy-mode.c b/cmd-copy-mode.c index 9d47ad3f..665507e1 100644 --- a/cmd-copy-mode.c +++ b/cmd-copy-mode.c @@ -1,4 +1,4 @@ -/* $Id: cmd-copy-mode.c,v 1.1 2007-11-23 14:28:47 nicm Exp $ */ +/* $Id: cmd-copy-mode.c,v 1.2 2007-11-27 19:23:33 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -47,7 +47,7 @@ cmd_copy_mode_exec(unused void *ptr, struct cmd_ctx *ctx) if (w->mode == NULL && ctx->flags & CMD_KEY) { w->mode = &window_copy_mode; w->mode->init(w); - server_redraw_window_all(w); + server_redraw_window(w); } if (ctx->cmdclient != NULL) diff --git a/cmd-list-clients.c b/cmd-list-clients.c index 0713e258..54743c42 100644 --- a/cmd-list-clients.c +++ b/cmd-list-clients.c @@ -1,4 +1,4 @@ -/* $Id: cmd-list-clients.c,v 1.2 2007-11-16 21:12:31 nicm Exp $ */ +/* $Id: cmd-list-clients.c,v 1.3 2007-11-27 19:23:33 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -51,8 +51,8 @@ cmd_list_clients_exec(unused void *ptr, struct cmd_ctx *ctx) if (c == NULL || c->session == NULL) continue; - ctx->print(ctx, - "%s: %s [%ux%u]", c->tty, c->session->name, c->sx, c->sy); + ctx->print(ctx, "%s: %s [%ux%u]", + c->tty.path, c->session->name, c->sx, c->sy); } if (ctx->cmdclient != NULL) diff --git a/cmd-new-session.c b/cmd-new-session.c index 75574f41..418fbf8e 100644 --- a/cmd-new-session.c +++ b/cmd-new-session.c @@ -1,4 +1,4 @@ -/* $Id: cmd-new-session.c,v 1.17 2007-11-16 21:12:31 nicm Exp $ */ +/* $Id: cmd-new-session.c,v 1.18 2007-11-27 19:23:33 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -100,8 +100,8 @@ cmd_new_session_exec(void *ptr, struct cmd_ctx *ctx) { struct cmd_new_session_data *data = ptr; struct cmd_new_session_data std = { NULL, NULL, NULL, 0 }; - struct client *c; - char *cmd; + struct client *c = ctx->cmdclient; + char *cmd, *cause; u_int sy; if (data == NULL) @@ -110,7 +110,6 @@ cmd_new_session_exec(void *ptr, struct cmd_ctx *ctx) if (ctx->flags & CMD_KEY) return; - c = ctx->cmdclient; if (!data->flag_detached && !(c->flags & CLIENT_TERMINAL)) { ctx->error(ctx, "not a terminal"); return; @@ -126,6 +125,12 @@ cmd_new_session_exec(void *ptr, struct cmd_ctx *ctx) sy = status_lines + 1; sy -= status_lines; + if (!data->flag_detached && tty_open(&c->tty, &cause) != 0) { + ctx->error(ctx, "%s", cause); + xfree(cause); + return; + } + cmd = data->cmd; if (cmd == NULL) cmd = default_command; diff --git a/cmd-scroll-mode.c b/cmd-scroll-mode.c index 6b7f6abc..17d839ae 100644 --- a/cmd-scroll-mode.c +++ b/cmd-scroll-mode.c @@ -1,4 +1,4 @@ -/* $Id: cmd-scroll-mode.c,v 1.3 2007-11-22 18:09:43 nicm Exp $ */ +/* $Id: cmd-scroll-mode.c,v 1.4 2007-11-27 19:23:33 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -47,7 +47,7 @@ cmd_scroll_mode_exec(unused void *ptr, struct cmd_ctx *ctx) if (w->mode == NULL && ctx->flags & CMD_KEY) { w->mode = &window_scroll_mode; w->mode->init(w); - server_redraw_window_all(w); + server_redraw_window(w); } if (ctx->cmdclient != NULL) diff --git a/input-keys.c b/input-keys.c index 1d11893f..4031d381 100644 --- a/input-keys.c +++ b/input-keys.c @@ -1,4 +1,4 @@ -/* $Id: input-keys.c,v 1.3 2007-11-21 13:11:41 nicm Exp $ */ +/* $Id: input-keys.c,v 1.4 2007-11-27 19:23:33 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -55,13 +55,13 @@ struct { /* Translate a key code from client into an output key sequence. */ void -input_key(struct buffer *b, int key) +input_key(struct window *w, int key) { u_int i; log_debug2("writing key %d", key); if (key != KEYC_NONE && key >= 0) { - input_store8(b, key); + buffer_write8(w->out, (uint8_t) key); return; } @@ -69,8 +69,8 @@ input_key(struct buffer *b, int key) if (input_keys[i].key == key) { log_debug2( "found key %d: \"%s\"", key, input_keys[i].data); - buffer_write( - b, input_keys[i].data, strlen(input_keys[i].data)); + buffer_write(w->out, + input_keys[i].data, strlen(input_keys[i].data)); return; } } @@ -1,4 +1,4 @@ -/* $Id: input.c,v 1.38 2007-11-24 23:29:49 nicm Exp $ */ +/* $Id: input.c,v 1.39 2007-11-27 19:23:33 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -36,7 +36,9 @@ int input_get_argument(struct input_ctx *, u_int, uint16_t *, uint16_t); int input_new_argument(struct input_ctx *); -int input_add_argument(struct input_ctx *, u_char ch); +int input_add_argument(struct input_ctx *, u_char); + +void input_write(struct input_ctx *, int, ...); void *input_state_first(u_char, struct input_ctx *); void *input_state_escape(u_char, struct input_ctx *); @@ -132,6 +134,19 @@ input_get_argument(struct input_ctx *ictx, u_int i, uint16_t *n, uint16_t d) } void +input_write(struct input_ctx *ictx, int cmd, ...) +{ + va_list ap; + + if (ictx->w->screen.mode & (MODE_HIDDEN|MODE_BACKGROUND)) + return; + + va_start(ap, cmd); + tty_vwrite_window(ictx->w, cmd, ap); + va_end(ap); +} + +void input_init(struct window *w) { ARRAY_INIT(&w->ictx.args); @@ -146,7 +161,7 @@ input_free(struct window *w) } void -input_parse(struct window *w, struct buffer *b) +input_parse(struct window *w) { struct input_ctx *ictx = &w->ictx; u_char ch; @@ -159,7 +174,6 @@ input_parse(struct window *w, struct buffer *b) ictx->off = 0; ictx->w = w; - ictx->b = b; log_debug2("entry; buffer=%zu", ictx->len); @@ -264,8 +278,7 @@ input_state_title_next(u_char ch, struct input_ctx *ictx) switch (ictx->title_type) { case 0: strlcpy(s->title, ictx->title_buf, sizeof s->title); - input_store_one(ictx->b, CODE_TITLE, ictx->title_len); - buffer_write(ictx->b, ictx->title_buf, ictx->title_len); + input_write(ictx, TTY_TITLE, s->title); break; } return (input_state_first); @@ -373,10 +386,8 @@ input_handle_character(u_char ch, struct input_ctx *ictx) log_debug2("-- ch %zu: %hhu (%c)", ictx->off, ch, ch); if (s->cx == screen_size_x(s)) { - if (!screen_hidden(s)) { - input_store8(ictx->b, '\r'); - input_store8(ictx->b, '\n'); - } + input_write(ictx, TTY_CHARACTER, '\r'); + input_write(ictx, TTY_CHARACTER, '\n'); s->cx = 0; screen_display_cursor_down(s); @@ -384,8 +395,7 @@ input_handle_character(u_char ch, struct input_ctx *ictx) return; screen_display_cursor_set(s, ch); - if (!screen_hidden(s)) - input_store8(ictx->b, ch); + input_write(ictx, TTY_CHARACTER, ch); s->cx++; } @@ -399,7 +409,7 @@ input_handle_c0_control(u_char ch, struct input_ctx *ictx) switch (ch) { case '\0': /* NUL */ - break; + return; case '\n': /* LF */ screen_display_cursor_down(s); break; @@ -419,28 +429,21 @@ input_handle_c0_control(u_char ch, struct input_ctx *ictx) s->cx = 0; screen_display_cursor_down(s); } - if (screen_hidden(s)) - return; - input_store_two(ictx->b, CODE_CURSORMOVE, s->cy + 1, s->cx + 1); + input_write(ictx, TTY_CURSORMOVE, s->cy, s->cx); return; case '\016': /* SO */ s->attr |= ATTR_DRAWING; - if (screen_hidden(s)) - return; - input_store_two(ictx->b, CODE_ATTRIBUTES, s->attr, s->colr); + input_write(ictx, TTY_ATTRIBUTES, s->attr, s->colr); return; case '\017': /* SI */ s->attr &= ~ATTR_DRAWING; - if (screen_hidden(s)) - return; - input_store_two(ictx->b, CODE_ATTRIBUTES, s->attr, s->colr); + input_write(ictx, TTY_ATTRIBUTES, s->attr, s->colr); return; default: log_debug("unknown c0: %hhu", ch); return; } - if (!screen_hidden(s)) - input_store8(ictx->b, ch); + input_write(ictx, TTY_CHARACTER, ch); } void @@ -453,8 +456,7 @@ input_handle_c1_control(u_char ch, struct input_ctx *ictx) switch (ch) { case 'M': /* RI */ screen_display_cursor_up(s); - if (!screen_hidden(s)) - input_store_zero(ictx->b, CODE_REVERSEINDEX); + input_write(ictx, TTY_REVERSEINDEX); break; default: log_debug("unknown c1: %hhu", ch); @@ -471,12 +473,10 @@ input_handle_private_two(u_char ch, struct input_ctx *ictx) switch (ch) { case '=': /* DECKPAM */ - if (!screen_hidden(s)) - input_store_zero(ictx->b, CODE_KKEYPADON); + input_write(ictx, TTY_KKEYPADON); break; case '>': /* DECKPNM*/ - if (!screen_hidden(s)) - input_store_zero(ictx->b, CODE_KKEYPADOFF); + input_write(ictx, TTY_KKEYPADOFF); break; case '7': /* DECSC */ s->saved_cx = s->cx; @@ -492,10 +492,8 @@ input_handle_private_two(u_char ch, struct input_ctx *ictx) s->cy = s->saved_cy; s->attr = s->saved_attr; s->colr = s->saved_colr; - if (screen_hidden(s)) - break; - input_store_two(ictx->b, CODE_ATTRIBUTES, s->attr, s->colr); - input_store_two(ictx->b, CODE_CURSORMOVE, s->cy + 1, s->cx + 1); + input_write(ictx, TTY_ATTRIBUTES, s->attr, s->colr); + input_write(ictx, TTY_CURSORMOVE, s->cy, s->cx); break; default: log_debug("unknown p2: %hhu", ch); @@ -583,8 +581,7 @@ input_handle_sequence_cuu(struct input_ctx *ictx) } s->cy -= n; - if (!screen_hidden(s)) - input_store_one(ictx->b, CODE_CURSORUP, n); + input_write(ictx, TTY_CURSORUP, n); } void @@ -606,8 +603,7 @@ input_handle_sequence_cud(struct input_ctx *ictx) input_limit(n, 1, screen_last_y(s) - s->cy); s->cy += n; - if (!screen_hidden(s)) - input_store_one(ictx->b, CODE_CURSORDOWN, n); + input_write(ictx, TTY_CURSORDOWN, n); } void @@ -629,8 +625,7 @@ input_handle_sequence_cuf(struct input_ctx *ictx) input_limit(n, 1, screen_last_x(s) - s->cx); s->cx += n; - if (!screen_hidden(s)) - input_store_one(ictx->b, CODE_CURSORRIGHT, n); + input_write(ictx, TTY_CURSORRIGHT, n); } void @@ -653,8 +648,7 @@ input_handle_sequence_cub(struct input_ctx *ictx) } s->cx -= n; - if (!screen_hidden(s)) - input_store_one(ictx->b, CODE_CURSORLEFT, n); + input_write(ictx, TTY_CURSORLEFT, n); } void @@ -676,8 +670,7 @@ input_handle_sequence_dch(struct input_ctx *ictx) input_limit(n, 1, screen_last_x(s) - s->cx); screen_display_delete_characters(s, s->cx, s->cy, n); - if (!screen_hidden(s)) - input_store_one(ictx->b, CODE_DELETECHARACTER, n); + input_write(ictx, TTY_DELETECHARACTER, n); } void @@ -702,8 +695,7 @@ input_handle_sequence_dl(struct input_ctx *ictx) screen_display_delete_lines(s, s->cy, n); else screen_display_delete_lines_region(s, s->cy, n); - if (!screen_hidden(s)) - input_store_one(ictx->b, CODE_DELETELINE, n); + input_write(ictx, TTY_DELETELINE, n); } void @@ -725,8 +717,7 @@ input_handle_sequence_ich(struct input_ctx *ictx) input_limit(n, 1, screen_last_x(s) - s->cx); screen_display_insert_characters(s, s->cx, s->cy, n); - if (!screen_hidden(s)) - input_store_one(ictx->b, CODE_INSERTCHARACTER, n); + input_write(ictx, TTY_INSERTCHARACTER, n); } void @@ -751,8 +742,7 @@ input_handle_sequence_il(struct input_ctx *ictx) screen_display_insert_lines(s, s->cy, n); else screen_display_insert_lines_region(s, s->cy, n); - if (!screen_hidden(s)) - input_store_one(ictx->b, CODE_INSERTLINE, n); + input_write(ictx, TTY_INSERTLINE, n); } void @@ -774,8 +764,7 @@ input_handle_sequence_vpa(struct input_ctx *ictx) input_limit(n, 1, screen_size_y(s)); s->cy = n - 1; - if (!screen_hidden(s)) - input_store_two(ictx->b, CODE_CURSORMOVE, n, s->cx + 1); + input_write(ictx, TTY_CURSORMOVE, s->cy, s->cx); } void @@ -797,8 +786,7 @@ input_handle_sequence_hpa(struct input_ctx *ictx) input_limit(n, 1, screen_size_x(s)); s->cx = n - 1; - if (!screen_hidden(s)) - input_store_two(ictx->b, CODE_CURSORMOVE, s->cy + 1, n); + input_write(ictx, TTY_CURSORMOVE, s->cy, s->cx); } void @@ -822,8 +810,7 @@ input_handle_sequence_cup(struct input_ctx *ictx) s->cx = m - 1; s->cy = n - 1; - if (!screen_hidden(s)) - input_store_two(ictx->b, CODE_CURSORMOVE, n, m); + input_write(ictx, TTY_CURSORMOVE, s->cy, s->cx); } void @@ -849,28 +836,21 @@ input_handle_sequence_ed(struct input_ctx *ictx) screen_display_fill_cursor_eos( s, SCREEN_DEFDATA, s->attr, s->colr); - if (screen_hidden(s)) - break; - input_store_zero(ictx->b, CODE_CLEARLINE); - for (i = s->cy + 1; i < screen_size_y(s); i++) { - input_store_two(ictx->b, CODE_CURSORMOVE, i + 1, 1); - input_store_zero(ictx->b, CODE_CLEARLINE); + for (i = s->cy; i < screen_size_y(s); i++) { + input_write(ictx, TTY_CURSORMOVE, i, 0); + input_write(ictx, TTY_CLEARENDOFLINE); } - input_store_two( - ictx->b, CODE_CURSORMOVE, s->cy + 1, s->cx + 1); + input_write(ictx, TTY_CURSORMOVE, s->cy, s->cx); break; case 2: screen_display_fill_lines( s, 0, screen_size_y(s), SCREEN_DEFDATA, s->attr, s->colr); - if (screen_hidden(s)) - break; for (i = 0; i < screen_size_y(s); i++) { - input_store_two(ictx->b, CODE_CURSORMOVE, i + 1, 1); - input_store_zero(ictx->b, CODE_CLEARLINE); + input_write(ictx, TTY_CURSORMOVE, i, 0); + input_write(ictx, TTY_CLEARENDOFLINE); } - input_store_two( - ictx->b, CODE_CURSORMOVE, s->cy + 1, s->cx + 1); + input_write(ictx, TTY_CURSORMOVE, s->cy, s->cx); break; } } @@ -896,23 +876,17 @@ input_handle_sequence_el(struct input_ctx *ictx) case 0: screen_display_fill_cursor_eol( s, SCREEN_DEFDATA, s->attr, s->colr); - - if (!screen_hidden(s)) - input_store_zero(ictx->b, CODE_CLEARENDOFLINE); + input_write(ictx, TTY_CLEARENDOFLINE); break; case 1: screen_display_fill_cursor_bol( s, SCREEN_DEFDATA, s->attr, s->colr); - - if (!screen_hidden(s)) - input_store_zero(ictx->b, CODE_CLEARSTARTOFLINE); + input_write(ictx, TTY_CLEARSTARTOFLINE); break; case 2: screen_display_fill_line( s, s->cy, SCREEN_DEFDATA, s->attr, s->colr); -< |