From cd9ccbc1e98b48fd8bfb64356664313a8eb1f7b0 Mon Sep 17 00:00:00 2001 From: nicm Date: Wed, 11 Mar 2015 08:17:37 +0000 Subject: [PATCH 1/9] set-titles-string now uses formats, not the status bits (so no #() for now). Reported by landry. --- tmux.1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tmux.1 b/tmux.1 index ca7d392a..7052484c 100644 --- a/tmux.1 +++ b/tmux.1 @@ -2499,9 +2499,9 @@ variable is set. String used to set the window title if .Ic set-titles is on. -Character sequences are replaced as for the -.Ic status-left -option. +Formats are expanded, see the +.Sx FORMATS +section. .It Xo Ic status .Op Ic on | off .Xc From 02df86079b1f3155313ebb6f891cf6cf593d3ad9 Mon Sep 17 00:00:00 2001 From: nicm Date: Tue, 31 Mar 2015 17:45:10 +0000 Subject: [PATCH 2/9] Fix some format specifier nits, from Ben Boeckel. --- client.c | 6 +++--- cmd-capture-pane.c | 2 +- cmd-respawn-pane.c | 2 +- colour.c | 2 +- format.c | 30 +++++++++++++++--------------- input-keys.c | 2 +- input.c | 2 +- server-client.c | 2 +- server-fn.c | 4 ++-- server-window.c | 6 +++--- window-choose.c | 2 +- window-copy.c | 2 +- 12 files changed, 31 insertions(+), 31 deletions(-) diff --git a/client.c b/client.c index 5458dfc9..6d4b8a5a 100644 --- a/client.c +++ b/client.c @@ -557,7 +557,7 @@ client_dispatch_wait(void *data0) data = imsg.data; datalen = imsg.hdr.len - IMSG_HEADER_SIZE; - log_debug("got %d from server", imsg.hdr.type); + log_debug("got %u from server", imsg.hdr.type); switch (imsg.hdr.type) { case MSG_EXIT: case MSG_SHUTDOWN: @@ -604,7 +604,7 @@ client_dispatch_wait(void *data0) fatalx("bad MSG_VERSION size"); fprintf(stderr, "protocol version mismatch " - "(client %u, server %u)\n", PROTOCOL_VERSION, + "(client %d, server %u)\n", PROTOCOL_VERSION, imsg.hdr.peerid); client_exitval = 1; @@ -648,7 +648,7 @@ client_dispatch_attached(void) data = imsg.data; datalen = imsg.hdr.len - IMSG_HEADER_SIZE; - log_debug("got %d from server", imsg.hdr.type); + log_debug("got %u from server", imsg.hdr.type); switch (imsg.hdr.type) { case MSG_DETACH: case MSG_DETACHKILL: diff --git a/cmd-capture-pane.c b/cmd-capture-pane.c index ce60b4c5..b44ebe9d 100644 --- a/cmd-capture-pane.c +++ b/cmd-capture-pane.c @@ -74,7 +74,7 @@ cmd_capture_pane_pending(struct args *args, struct window_pane *wp, tmp[0] = line[i]; tmp[1] = '\0'; } else - xsnprintf(tmp, sizeof tmp, "\\%03o", line[i]); + xsnprintf(tmp, sizeof tmp, "\\%03hho", line[i]); buf = cmd_capture_pane_append(buf, len, tmp, strlen(tmp)); } diff --git a/cmd-respawn-pane.c b/cmd-respawn-pane.c index 47031539..6575e8e4 100644 --- a/cmd-respawn-pane.c +++ b/cmd-respawn-pane.c @@ -59,7 +59,7 @@ cmd_respawn_pane_exec(struct cmd *self, struct cmd_q *cmdq) if (!args_has(self->args, 'k') && wp->fd != -1) { if (window_pane_index(wp, &idx) != 0) fatalx("index not found"); - cmdq_error(cmdq, "pane still active: %s:%u.%u", + cmdq_error(cmdq, "pane still active: %s:%d.%u", s->name, wl->idx, idx); return (CMD_RETURN_ERROR); } diff --git a/colour.c b/colour.c index b5efd6f1..82f8533a 100644 --- a/colour.c +++ b/colour.c @@ -147,7 +147,7 @@ colour_tostring(int c) static char s[32]; if (c & 0x100) { - xsnprintf(s, sizeof s, "colour%u", c & ~0x100); + xsnprintf(s, sizeof s, "colour%d", c & ~0x100); return (s); } diff --git a/format.c b/format.c index 01fa3ade..92271753 100644 --- a/format.c +++ b/format.c @@ -503,7 +503,7 @@ format_defaults_session(struct format_tree *ft, struct session *s) format_add(ft, "session_created_string", "%s", tim); format_add(ft, "session_attached", "%u", s->attached); - format_add(ft, "session_many_attached", "%u", s->attached > 1); + format_add(ft, "session_many_attached", "%d", s->attached > 1); } /* Set default format keys for a client. */ @@ -572,7 +572,7 @@ format_defaults_window(struct format_tree *ft, struct window *w) format_add(ft, "window_height", "%u", w->sy); format_add(ft, "window_layout", "%s", layout); format_add(ft, "window_panes", "%u", window_count_panes(w)); - format_add(ft, "window_zoomed_flag", "%u", + format_add(ft, "window_zoomed_flag", "%d", !!(w->flags & WINDOW_ZOOMED)); free(layout); @@ -597,13 +597,13 @@ format_defaults_winlink(struct format_tree *ft, struct session *s, format_add(ft, "window_flags", "%s", flags); format_add(ft, "window_active", "%d", wl == s->curw); - format_add(ft, "window_bell_flag", "%u", + format_add(ft, "window_bell_flag", "%d", !!(wl->flags & WINLINK_BELL)); - format_add(ft, "window_activity_flag", "%u", + format_add(ft, "window_activity_flag", "%d", !!(wl->flags & WINLINK_ACTIVITY)); - format_add(ft, "window_silence_flag", "%u", + format_add(ft, "window_silence_flag", "%d", !!(wl->flags & WINLINK_SILENCE)); - format_add(ft, "window_last_flag", "%u", + format_add(ft, "window_last_flag", "%d", !!(wl == TAILQ_FIRST(&s->lastw))); free(flags); @@ -623,7 +623,7 @@ format_defaults_pane_tabs(struct format_tree *ft, struct window_pane *wp) if (EVBUFFER_LENGTH(buffer) > 0) evbuffer_add(buffer, ",", 1); - evbuffer_add_printf(buffer, "%d", i); + evbuffer_add_printf(buffer, "%u", i); } format_add(ft, "pane_tabs", "%.*s", (int) EVBUFFER_LENGTH(buffer), @@ -694,16 +694,16 @@ format_defaults_pane(struct format_tree *ft, struct window_pane *wp) free(cmd); } - format_add(ft, "cursor_x", "%d", wp->base.cx); - format_add(ft, "cursor_y", "%d", wp->base.cy); - format_add(ft, "scroll_region_upper", "%d", wp->base.rupper); - format_add(ft, "scroll_region_lower", "%d", wp->base.rlower); - format_add(ft, "saved_cursor_x", "%d", wp->ictx.old_cx); - format_add(ft, "saved_cursor_y", "%d", wp->ictx.old_cy); + format_add(ft, "cursor_x", "%u", wp->base.cx); + format_add(ft, "cursor_y", "%u", wp->base.cy); + format_add(ft, "scroll_region_upper", "%u", wp->base.rupper); + format_add(ft, "scroll_region_lower", "%u", wp->base.rlower); + format_add(ft, "saved_cursor_x", "%u", wp->ictx.old_cx); + format_add(ft, "saved_cursor_y", "%u", wp->ictx.old_cy); format_add(ft, "alternate_on", "%d", wp->saved_grid ? 1 : 0); - format_add(ft, "alternate_saved_x", "%d", wp->saved_cx); - format_add(ft, "alternate_saved_y", "%d", wp->saved_cy); + format_add(ft, "alternate_saved_x", "%u", wp->saved_cx); + format_add(ft, "alternate_saved_y", "%u", wp->saved_cy); format_add(ft, "cursor_flag", "%d", !!(wp->base.mode & MODE_CURSOR)); diff --git a/input-keys.c b/input-keys.c index 040a0605..f2d010d8 100644 --- a/input-keys.c +++ b/input-keys.c @@ -219,7 +219,7 @@ input_mouse(struct window_pane *wp, struct session *s, struct mouse_event *m) * legacy format. */ if (m->sgr && (wp->screen->mode & MODE_MOUSE_SGR)) { - len = xsnprintf(buf, sizeof buf, "\033[<%d;%d;%d%c", + len = xsnprintf(buf, sizeof buf, "\033[<%u;%u;%u%c", m->sgr_xb, m->x + 1, m->y + 1, m->sgr_rel ? 'm' : 'M'); } else if (wp->screen->mode & MODE_MOUSE_UTF8) { diff --git a/input.c b/input.c index de11f629..9f7d4413 100644 --- a/input.c +++ b/input.c @@ -1717,7 +1717,7 @@ void input_exit_osc(struct input_ctx *ictx) { u_char *p = ictx->input_buf; - int option; + u_int option; if (ictx->flags & INPUT_DISCARD) return; diff --git a/server-client.c b/server-client.c index 280815cb..8373a0ef 100644 --- a/server-client.c +++ b/server-client.c @@ -824,7 +824,7 @@ server_client_msg_dispatch(struct client *c) continue; } - log_debug("got %d from client %d", imsg.hdr.type, c->ibuf.fd); + log_debug("got %u from client %d", imsg.hdr.type, c->ibuf.fd); switch (imsg.hdr.type) { case MSG_IDENTIFY_FLAGS: case MSG_IDENTIFY_TERM: diff --git a/server-fn.c b/server-fn.c index b8cdb31a..f89eca8e 100644 --- a/server-fn.c +++ b/server-fn.c @@ -41,9 +41,9 @@ server_fill_environ(struct session *s, struct environ *env) idx = s->id; } else - idx = -1; + idx = (u_int)-1; pid = getpid(); - xsnprintf(var, sizeof var, "%s,%ld,%d", socket_path, pid, idx); + xsnprintf(var, sizeof var, "%s,%ld,%u", socket_path, pid, idx); environ_set(env, "TMUX", var); } diff --git a/server-window.c b/server-window.c index a14c3150..a2355701 100644 --- a/server-window.c +++ b/server-window.c @@ -90,7 +90,7 @@ server_window_check_bell(struct session *s, struct winlink *wl) if (c->session->curw->window == w) status_message_set(c, "Bell in current window"); else if (action == BELL_ANY) - status_message_set(c, "Bell in window %u", wl->idx); + status_message_set(c, "Bell in window %d", wl->idx); } return (1); @@ -124,7 +124,7 @@ server_window_check_activity(struct session *s, struct winlink *wl) c = ARRAY_ITEM(&clients, i); if (c == NULL || c->session != s) continue; - status_message_set(c, "Activity in window %u", wl->idx); + status_message_set(c, "Activity in window %d", wl->idx); } } @@ -175,7 +175,7 @@ server_window_check_silence(struct session *s, struct winlink *wl) c = ARRAY_ITEM(&clients, i); if (c == NULL || c->session != s) continue; - status_message_set(c, "Silence in window %u", wl->idx); + status_message_set(c, "Silence in window %d", wl->idx); } } diff --git a/window-choose.c b/window-choose.c index 69141676..8bed8d45 100644 --- a/window-choose.c +++ b/window-choose.c @@ -98,7 +98,7 @@ window_choose_add(struct window_pane *wp, struct window_choose_data *wcd) item->pos = ARRAY_LENGTH(&data->list) - 1; item->state = 0; - data->width = xsnprintf(tmp, sizeof tmp , "%u", item->pos); + data->width = xsnprintf(tmp, sizeof tmp , "%d", item->pos); } void diff --git a/window-copy.c b/window-copy.c index 223df88a..074e7310 100644 --- a/window-copy.c +++ b/window-copy.c @@ -1216,7 +1216,7 @@ window_copy_write_line(struct window_pane *wp, struct screen_write_ctx *ctx, limit = screen_size_x(s) + 1; if (data->inputtype == WINDOW_COPY_NUMERICPREFIX) { xoff = size = xsnprintf(hdr, limit, - "Repeat: %u", data->numprefix); + "Repeat: %d", data->numprefix); } else { xoff = size = xsnprintf(hdr, limit, "%s: %s", data->inputprompt, data->inputstr); From 3aa72b42b2a317b0ae531219d269f2a636d6482a Mon Sep 17 00:00:00 2001 From: nicm Date: Tue, 31 Mar 2015 17:58:36 +0000 Subject: [PATCH 3/9] Add a helper function to convert time, and add session_activity formats (the latter from Takatoshi Matsumoto). --- format.c | 33 +++++++++++++++++++++------------ tmux.1 | 2 ++ 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/format.c b/format.c index 92271753..cf1713ba 100644 --- a/format.c +++ b/format.c @@ -37,6 +37,7 @@ int format_replace(struct format_tree *, const char *, size_t, char **, size_t *, size_t *); +char *format_time_string(time_t); char *format_get_command(struct window_pane *); void format_defaults_pane_tabs(struct format_tree *, struct window_pane *); @@ -453,6 +454,18 @@ format_get_command(struct window_pane *wp) return (out); } +/* Get time as a string. */ +char * +format_time_string(time_t t) +{ + char *tim; + + tim = ctime(&t); + *strchr(tim, '\n') = '\0'; + + return (tim); +} + /* Set defaults for any of arguments that are not NULL. */ void format_defaults(struct format_tree *ft, struct client *c, struct session *s, @@ -480,7 +493,6 @@ void format_defaults_session(struct format_tree *ft, struct session *s) { struct session_group *sg; - char *tim; time_t t; ft->s = s; @@ -498,9 +510,11 @@ format_defaults_session(struct format_tree *ft, struct session *s) t = s->creation_time.tv_sec; format_add(ft, "session_created", "%lld", (long long) t); - tim = ctime(&t); - *strchr(tim, '\n') = '\0'; - format_add(ft, "session_created_string", "%s", tim); + format_add(ft, "session_created_string", "%s", format_time_string(t)); + + t = s->activity_time.tv_sec; + format_add(ft, "session_activity", "%lld", (long long) t); + format_add(ft, "session_activity_string", "%s", format_time_string(t)); format_add(ft, "session_attached", "%u", s->attached); format_add(ft, "session_many_attached", "%d", s->attached > 1); @@ -510,9 +524,8 @@ format_defaults_session(struct format_tree *ft, struct session *s) void format_defaults_client(struct format_tree *ft, struct client *c) { - char *tim; - time_t t; struct session *s; + time_t t; if (ft->s == NULL) ft->s = c->session; @@ -526,15 +539,11 @@ format_defaults_client(struct format_tree *ft, struct client *c) t = c->creation_time.tv_sec; format_add(ft, "client_created", "%lld", (long long) t); - tim = ctime(&t); - *strchr(tim, '\n') = '\0'; - format_add(ft, "client_created_string", "%s", tim); + format_add(ft, "client_created_string", "%s", format_time_string(t)); t = c->activity_time.tv_sec; format_add(ft, "client_activity", "%lld", (long long) t); - tim = ctime(&t); - *strchr(tim, '\n') = '\0'; - format_add(ft, "client_activity_string", "%s", tim); + format_add(ft, "client_activity_string", "%s", format_time_string(t)); format_add(ft, "client_prefix", "%d", !!(c->flags & CLIENT_PREFIX)); diff --git a/tmux.1 b/tmux.1 index 7052484c..c8fab92c 100644 --- a/tmux.1 +++ b/tmux.1 @@ -3148,6 +3148,8 @@ The following variables are available, where appropriate: .It Li "scroll_region_lower" Ta "" Ta "Bottom of scroll region in pane" .It Li "scroll_region_upper" Ta "" Ta "Top of scroll region in pane" .It Li "session_attached" Ta "" Ta "Number of clients session is attached to" +.It Li "session_activity" Ta "" Ta "Integer time of session last activity" +.It Li "session_activity_string" Ta "" Ta "String time of session last activity" .It Li "session_created" Ta "" Ta "Integer time session created" .It Li "session_created_string" Ta "" Ta "String time session created" .It Li "session_group" Ta "" Ta "Number of session group" From 6920be311b276277ad7c38a96ccca4746b94bd95 Mon Sep 17 00:00:00 2001 From: nicm Date: Tue, 7 Apr 2015 13:06:22 +0000 Subject: [PATCH 4/9] When replacing, don't free the old paste until after the new one's name has been copied. Fixes a use-after-free in window-copy.c. Bug reported by J Raynor (who also provided a different fix). --- paste.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/paste.c b/paste.c index de80115e..2ccc3cd2 100644 --- a/paste.c +++ b/paste.c @@ -247,9 +247,6 @@ paste_set(char *data, size_t size, const char *name, char **cause) return (-1); } - pb = paste_get_name(name); - if (pb != NULL) - paste_free_name(name); pb = xmalloc(sizeof *pb); @@ -261,6 +258,9 @@ paste_set(char *data, size_t size, const char *name, char **cause) pb->automatic = 0; pb->order = paste_next_order++; + if (paste_get_name(name) != NULL) + paste_free_name(name); + RB_INSERT(paste_name_tree, &paste_by_name, pb); RB_INSERT(paste_time_tree, &paste_by_time, pb); From 009a5e4213a04555be0fb654f80fe8685082ba20 Mon Sep 17 00:00:00 2001 From: nicm Date: Fri, 10 Apr 2015 07:23:14 +0000 Subject: [PATCH 5/9] in the case -> in this case. --- tmux.1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tmux.1 b/tmux.1 index c8fab92c..2764626e 100644 --- a/tmux.1 +++ b/tmux.1 @@ -747,7 +747,7 @@ behave like .Ic attach-session if .Ar session-name -already exists; in the case, +already exists; in this case, .Fl D behaves like .Fl d From 0cd55eb1e7823a75810b7f43f53b6266cb8b0bc0 Mon Sep 17 00:00:00 2001 From: nicm Date: Fri, 10 Apr 2015 16:00:08 +0000 Subject: [PATCH 6/9] Add a -x flag to copy-selection, append-selection and start-named-buffer to prevent it exiting copy mode after copying. From J Raynor with a few tweaks by me. --- cmd-bind-key.c | 28 ++++++++++++++++++++++------ tmux.1 | 18 +++++++++++++++--- window-copy.c | 27 +++++++++++++++++++++------ 3 files changed, 58 insertions(+), 15 deletions(-) diff --git a/cmd-bind-key.c b/cmd-bind-key.c index 5d68d486..47c58e51 100644 --- a/cmd-bind-key.c +++ b/cmd-bind-key.c @@ -104,18 +104,34 @@ cmd_bind_key_mode_table(struct cmd *self, struct cmd_q *cmdq, int key) return (CMD_RETURN_ERROR); } - if (cmd != MODEKEYCOPY_COPYPIPE) { - if (args->argc != 2) { - cmdq_error(cmdq, "no argument allowed"); - return (CMD_RETURN_ERROR); + switch (cmd) { + case MODEKEYCOPY_APPENDSELECTION: + case MODEKEYCOPY_COPYSELECTION: + case MODEKEYCOPY_STARTNAMEDBUFFER: + if (args->argc == 2) + arg = NULL; + else { + arg = args->argv[2]; + if (strcmp(arg, "-x") != 0) { + cmdq_error(cmdq, "unknown argument"); + return (CMD_RETURN_ERROR); + } } - arg = NULL; - } else { + break; + case MODEKEYCOPY_COPYPIPE: if (args->argc != 3) { cmdq_error(cmdq, "no argument given"); return (CMD_RETURN_ERROR); } arg = args->argv[2]; + break; + default: + if (args->argc != 2) { + cmdq_error(cmdq, "no argument allowed"); + return (CMD_RETURN_ERROR); + } + arg = NULL; + break; } mtmp.key = key; diff --git a/tmux.1 b/tmux.1 index 2764626e..abdeba54 100644 --- a/tmux.1 +++ b/tmux.1 @@ -987,15 +987,27 @@ command and keys modified or removed with .Ic bind-key and .Ic unbind-key . -One command accepts an argument, -.Ic copy-pipe , -which copies the selection and pipes it to a command. +If +.Ic append-selection , +.Ic copy-selection , +or +.Ic start-named-buffer +are given the +.Fl x +flag, +.Nm +will not exit copy mode after copying. +.Ic copy-pipe +copies the selection and pipes it to a command. For example the following will bind +.Ql C-w +not to exit after copying and .Ql C-q to copy the selection into .Pa /tmp as well as the paste buffer: .Bd -literal -offset indent +bind-key -temacs-copy C-w copy-selection -x bind-key -temacs-copy C-q copy-pipe "cat >/tmp/out" .Ed .Pp diff --git a/window-copy.c b/window-copy.c index 074e7310..feb8c481 100644 --- a/window-copy.c +++ b/window-copy.c @@ -147,6 +147,7 @@ struct window_copy_mode_data { enum window_copy_input_type inputtype; const char *inputprompt; char *inputstr; + int inputexit; int numprefix; @@ -424,8 +425,12 @@ window_copy_key(struct window_pane *wp, struct session *sess, int key) case MODEKEYCOPY_APPENDSELECTION: if (sess != NULL) { window_copy_append_selection(wp, NULL); - window_pane_reset_mode(wp); - return; + if (arg == NULL) { + window_pane_reset_mode(wp); + return; + } + window_copy_clear_selection(wp); + window_copy_redraw_screen(wp); } break; case MODEKEYCOPY_CANCEL: @@ -572,8 +577,12 @@ window_copy_key(struct window_pane *wp, struct session *sess, int key) case MODEKEYCOPY_COPYSELECTION: if (sess != NULL) { window_copy_copy_selection(wp, NULL); - window_pane_reset_mode(wp); - return; + if (arg == NULL) { + window_pane_reset_mode(wp); + return; + } + window_copy_clear_selection(wp); + window_copy_redraw_screen(wp); } break; case MODEKEYCOPY_STARTOFLINE: @@ -718,6 +727,7 @@ window_copy_key(struct window_pane *wp, struct session *sess, int key) goto input_on; case MODEKEYCOPY_STARTNAMEDBUFFER: data->inputtype = WINDOW_COPY_NAMEDBUFFER; + data->inputexit = (arg == NULL); data->inputprompt = "Buffer"; *data->inputstr = '\0'; goto input_on; @@ -828,8 +838,13 @@ window_copy_key_input(struct window_pane *wp, int key) case WINDOW_COPY_NAMEDBUFFER: window_copy_copy_selection(wp, data->inputstr); *data->inputstr = '\0'; - window_pane_reset_mode(wp); - return (0); + if (data->inputexit) { + window_pane_reset_mode(wp); + return (0); + } + window_copy_clear_selection(wp); + window_copy_redraw_screen(wp); + break; case WINDOW_COPY_GOTOLINE: window_copy_goto_line(wp, data->inputstr); *data->inputstr = '\0'; From f922920609063ff5ac1ee11a48bf8f1bd13e8d16 Mon Sep 17 00:00:00 2001 From: nicm Date: Wed, 15 Apr 2015 15:44:40 +0000 Subject: [PATCH 7/9] Fix setting old-style window -fg/-bg/-attr options that aren't global. --- style.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/style.c b/style.c index d8ab07a3..5534f118 100644 --- a/style.c +++ b/style.c @@ -160,13 +160,21 @@ style_update_new(struct options *oo, const char *name, const char *newname) { int value; struct grid_cell *gc; + struct options_entry *o; /* It's a colour or attribute, but with no -style equivalent. */ if (newname == NULL) return; - gc = options_get_style(oo, newname); - value = options_get_number(oo, name); + o = options_find1(oo, newname); + if (o == NULL) + o = options_set_style (oo, newname, "default", 0); + gc = &o->style; + + o = options_find1(oo, name); + if (o == NULL) + o = options_set_number (oo, name, 8); + value = o->num; if (strstr(name, "-bg") != NULL) colour_set_bg(gc, value); From eec27f9257976d063db279594bff264c2e32d52c Mon Sep 17 00:00:00 2001 From: nicm Date: Wed, 15 Apr 2015 22:10:13 +0000 Subject: [PATCH 8/9] Use tty_term_flag not _has for flags, also fix a typo (position not permission). --- tty.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tty.c b/tty.c index 1bb89811..05d422d0 100644 --- a/tty.c +++ b/tty.c @@ -629,7 +629,7 @@ tty_draw_line(struct tty *tty, struct screen *s, u_int py, u_int ox, u_int oy) sx = tty->sx; /* - * Don't move the cursor to the start permission if it will wrap there + * Don't move the cursor to the start position if it will wrap there * itself. */ gl = NULL; @@ -1407,7 +1407,7 @@ tty_colours(struct tty *tty, const struct grid_cell *gc) * * Otherwise, try to set the default colour only as needed. */ - have_ax = tty_term_has(tty->term, TTYC_AX); + have_ax = tty_term_flag(tty->term, TTYC_AX); if (!have_ax && tty_term_has(tty->term, TTYC_OP)) tty_reset(tty); else { From 4a7587931ce54aa1a94a104480113d658c295b6b Mon Sep 17 00:00:00 2001 From: nicm Date: Wed, 15 Apr 2015 22:34:46 +0000 Subject: [PATCH 9/9] Fix some issues in bright colour handling. Bold background doesn't exist so there is no reason for tty_check_bg to mess with the BRIGHT flag at all, ever. Also use aixterm colours for 256-to-16 translation if the terminal supports them. And there is no reason for tty_colours_bg to worry about whether the terminal supports them - tty_check_bg has already taken care of it. --- tty.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/tty.c b/tty.c index 05d422d0..83ae8282 100644 --- a/tty.c +++ b/tty.c @@ -1453,6 +1453,8 @@ tty_check_fg(struct tty *tty, struct grid_cell *gc) { u_int colours; + colours = tty_term_number(tty->term, TTYC_COLORS); + /* Is this a 256-colour colour? */ if (gc->flags & GRID_FLAG_FG256) { /* And not a 256 colour mode? */ @@ -1461,7 +1463,10 @@ tty_check_fg(struct tty *tty, struct grid_cell *gc) gc->fg = colour_256to16(gc->fg); if (gc->fg & 8) { gc->fg &= 7; - gc->attr |= GRID_ATTR_BRIGHT; + if (colours >= 16) + gc->fg += 90; + else + gc->attr |= GRID_ATTR_BRIGHT; } else gc->attr &= ~GRID_ATTR_BRIGHT; gc->flags &= ~GRID_FLAG_FG256; @@ -1470,7 +1475,6 @@ tty_check_fg(struct tty *tty, struct grid_cell *gc) } /* Is this an aixterm colour? */ - colours = tty_term_number(tty->term, TTYC_COLORS); if (gc->fg >= 90 && gc->fg <= 97 && colours < 16) { gc->fg -= 90; gc->attr |= GRID_ATTR_BRIGHT; @@ -1482,6 +1486,8 @@ tty_check_bg(struct tty *tty, struct grid_cell *gc) { u_int colours; + colours = tty_term_number(tty->term, TTYC_COLORS); + /* Is this a 256-colour colour? */ if (gc->flags & GRID_FLAG_BG256) { /* @@ -1492,20 +1498,19 @@ tty_check_bg(struct tty *tty, struct grid_cell *gc) if (!(tty->term->flags & TERM_256COLOURS) && !(tty->term_flags & TERM_256COLOURS)) { gc->bg = colour_256to16(gc->bg); - if (gc->bg & 8) + if (gc->bg & 8) { gc->bg &= 7; - gc->attr &= ~GRID_ATTR_BRIGHT; + if (colours >= 16) + gc->fg += 90; + } gc->flags &= ~GRID_FLAG_BG256; } return; } /* Is this an aixterm colour? */ - colours = tty_term_number(tty->term, TTYC_COLORS); - if (gc->bg >= 90 && gc->bg <= 97 && colours < 16) { + if (gc->bg >= 90 && gc->bg <= 97 && colours < 16) gc->bg -= 90; - gc->attr |= GRID_ATTR_BRIGHT; - } } void @@ -1559,14 +1564,9 @@ tty_colours_bg(struct tty *tty, const struct grid_cell *gc) /* Is this an aixterm bright colour? */ if (bg >= 90 && bg <= 97) { - /* 16 colour terminals or above only. */ - if (tty_term_number(tty->term, TTYC_COLORS) >= 16) { - xsnprintf(s, sizeof s, "\033[%dm", bg + 10); - tty_puts(tty, s); - goto save_bg; - } - bg -= 90; - /* no such thing as a bold background */ + xsnprintf(s, sizeof s, "\033[%dm", bg + 10); + tty_puts(tty, s); + goto save_bg; } /* Otherwise set the background colour. */