diff options
Diffstat (limited to 'status.c')
-rw-r--r-- | status.c | 147 |
1 files changed, 68 insertions, 79 deletions
@@ -1,4 +1,4 @@ -/* $Id$ */ +/* $OpenBSD$ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -29,16 +29,17 @@ #include "tmux.h" -char *status_redraw_get_left( - struct client *, time_t, int, struct grid_cell *, size_t *); -char *status_redraw_get_right( - struct client *, time_t, int, struct grid_cell *, size_t *); +char *status_redraw_get_left(struct client *, time_t, int, struct grid_cell *, + size_t *); +char *status_redraw_get_right(struct client *, time_t, int, + struct grid_cell *, size_t *); char *status_find_job(struct client *, char **); void status_job_free(void *); void status_job_callback(struct job *); -char *status_print( - struct client *, struct winlink *, time_t, struct grid_cell *); -void status_replace1(struct client *, char **, char **, char *, size_t, int); +char *status_print(struct client *, struct winlink *, time_t, + struct grid_cell *); +char *status_replace(struct client *, struct winlink *, const char *, time_t); +void status_replace1(struct client *, char **, char **, char *, size_t); void status_message_callback(int, short, void *); const char *status_prompt_up_history(u_int *); @@ -75,17 +76,18 @@ status_at_line(struct client *c) /* Retrieve options for left string. */ char * -status_redraw_get_left(struct client *c, - time_t t, int utf8flag, struct grid_cell *gc, size_t *size) +status_redraw_get_left(struct client *c, time_t t, int utf8flag, + struct grid_cell *gc, size_t *size) { struct session *s = c->session; + const char *template; char *left; size_t leftlen; style_apply_update(gc, &s->options, "status-left-style"); - left = status_replace(c, NULL, - NULL, NULL, options_get_string(&s->options, "status-left"), t, 1); + template = options_get_string(&s->options, "status-left"); + left = status_replace(c, NULL, template, t); *size = options_get_number(&s->options, "status-left-length"); leftlen = screen_write_cstrlen(utf8flag, "%s", left); @@ -96,17 +98,18 @@ status_redraw_get_left(struct client *c, /* Retrieve options for right string. */ char * -status_redraw_get_right(struct client *c, - time_t t, int utf8flag, struct grid_cell *gc, size_t *size) +status_redraw_get_right(struct client *c, time_t t, int utf8flag, + struct grid_cell *gc, size_t *size) { struct session *s = c->session; + const char *template; char *right; size_t rightlen; style_apply_update(gc, &s->options, "status-right-style"); - right = status_replace(c, NULL, - NULL, NULL, options_get_string(&s->options, "status-right"), t, 1); + template = options_get_string(&s->options, "status-right"); + right = status_replace(c, NULL, template, t); *size = options_get_number(&s->options, "status-right-length"); rightlen = screen_write_cstrlen(utf8flag, "%s", right); @@ -121,12 +124,17 @@ status_set_window_at(struct client *c, u_int x) { struct session *s = c->session; struct winlink *wl; + struct options *oo; + size_t len; x += c->wlmouse; RB_FOREACH(wl, winlinks, &s->windows) { + oo = &wl->window->options; + + len = strlen(options_get_string(oo, "window-status-separator")); if (x < wl->status_width && session_select(s, wl->idx) == 0) server_redraw_session(s); - x -= wl->status_width + 1; + x -= wl->status_width + len; } } @@ -188,9 +196,9 @@ status_redraw(struct client *c) */ needed = 0; if (llen != 0) - needed += llen + 1; + needed += llen; if (rlen != 0) - needed += rlen + 1; + needed += rlen; if (c->tty.sx == 0 || c->tty.sx <= needed) goto out; wlavailable = c->tty.sx - needed; @@ -295,10 +303,8 @@ draw: /* Draw the left string and arrow. */ screen_write_cursormove(&ctx, 0, 0); - if (llen != 0) { + if (llen != 0) screen_write_cnputs(&ctx, llen, &lgc, utf8flag, "%s", left); - screen_write_putc(&ctx, &stdgc, ' '); - } if (larrow != 0) { memcpy(&gc, &stdgc, sizeof gc); if (larrow == -1) @@ -308,26 +314,24 @@ draw: /* Draw the right string and arrow. */ if (rarrow != 0) { - screen_write_cursormove(&ctx, c->tty.sx - rlen - 2, 0); + screen_write_cursormove(&ctx, c->tty.sx - rlen - 1, 0); memcpy(&gc, &stdgc, sizeof gc); if (rarrow == -1) gc.attr ^= GRID_ATTR_REVERSE; screen_write_putc(&ctx, &gc, '>'); } else - screen_write_cursormove(&ctx, c->tty.sx - rlen - 1, 0); - if (rlen != 0) { - screen_write_putc(&ctx, &stdgc, ' '); + screen_write_cursormove(&ctx, c->tty.sx - rlen, 0); + if (rlen != 0) screen_write_cnputs(&ctx, rlen, &rgc, utf8flag, "%s", right); - } /* Figure out the offset for the window list. */ if (llen != 0) - wloffset = llen + 1; + wloffset = llen; else wloffset = 0; if (wlwidth < wlavailable) { switch (options_get_number(&s->options, "status-justify")) { - case 1: /* centered */ + case 1: /* centred */ wloffset += (wlavailable - wlwidth) / 2; break; case 2: /* right */ @@ -361,7 +365,7 @@ out: /* Replace a single special sequence (prefixed by #). */ void status_replace1(struct client *c, char **iptr, char **optr, char *out, - size_t outsize, int jobsflag) + size_t outsize) { char ch, tmp[256], *ptr, *endptr; size_t ptrlen; @@ -379,10 +383,6 @@ status_replace1(struct client *c, char **iptr, char **optr, char *out, switch (*(*iptr)++) { case '(': - if (!jobsflag) { - ch = ')'; - goto skip_to; - } if ((ptr = status_find_job(c, iptr)) == NULL) return; goto do_replace; @@ -396,9 +396,6 @@ status_replace1(struct client *c, char **iptr, char **optr, char *out, case '{': ptr = (char *) "#{"; goto do_replace; - case '#': - *(*optr)++ = '#'; - break; default: xsnprintf(tmp, sizeof tmp, "#%c", *(*iptr - 1)); ptr = tmp; @@ -434,8 +431,7 @@ skip_to: /* Replace special sequences in fmt. */ char * -status_replace(struct client *c, struct session *s, struct winlink *wl, - struct window_pane *wp, const char *fmt, time_t t, int jobsflag) +status_replace(struct client *c, struct winlink *wl, const char *fmt, time_t t) { static char out[BUFSIZ]; char in[BUFSIZ], ch, *iptr, *optr, *expanded; @@ -445,13 +441,6 @@ status_replace(struct client *c, struct session *s, struct winlink *wl, if (fmt == NULL) return (xstrdup("")); - if (s == NULL && c != NULL) - s = c->session; - if (wl == NULL && s != NULL) - wl = s->curw; - if (wp == NULL && wl != NULL) - wp = wl->window->active; - len = strftime(in, sizeof in, fmt, localtime(&t)); in[len] = '\0'; @@ -467,19 +456,12 @@ status_replace(struct client *c, struct session *s, struct winlink *wl, *optr++ = ch; continue; } - status_replace1(c, &iptr, &optr, out, sizeof out, jobsflag); + status_replace1(c, &iptr, &optr, out, sizeof out); } *optr = '\0'; ft = format_create(); - if (c != NULL) - format_client(ft, c); - if (s != NULL) - format_session(ft, s); - if (s != NULL && wl != NULL) - format_winlink(ft, s, wl); - if (wp != NULL) - format_window_pane(ft, wp); + format_defaults(ft, c, NULL, wl, NULL); expanded = format_expand(ft, out); format_free(ft); return (expanded); @@ -622,8 +604,8 @@ status_job_callback(struct job *job) /* Return winlink status line entry and adjust gc as necessary. */ char * -status_print( - struct client *c, struct winlink *wl, time_t t, struct grid_cell *gc) +status_print(struct client *c, struct winlink *wl, time_t t, + struct grid_cell *gc) { struct options *oo = &wl->window->options; struct session *s = c->session; @@ -641,21 +623,18 @@ status_print( if (wl->flags & WINLINK_BELL) style_apply_update(gc, oo, "window-status-bell-style"); - else if (wl->flags & WINLINK_CONTENT) - style_apply_update(gc, oo, "window-status-content-style"); else if (wl->flags & (WINLINK_ACTIVITY|WINLINK_SILENCE)) style_apply_update(gc, oo, "window-status-activity-style"); - text = status_replace(c, NULL, wl, NULL, fmt, t, 1); + text = status_replace(c, wl, fmt, t); return (text); } /* Set a status line message. */ -void printflike2 +void status_message_set(struct client *c, const char *fmt, ...) { struct timeval tv; - struct session *s = c->session; struct message_entry *msg; va_list ap; int delay; @@ -673,10 +652,7 @@ status_message_set(struct client *c, const char *fmt, ...) msg->msg_time = time(NULL); msg->msg = xstrdup(c->message_string); - if (s == NULL) - limit = 0; - else - limit = options_get_number(&s->options, "message-limit"); + limit = options_get_number(&global_options, "message-limit"); if (ARRAY_LENGTH(&c->message_log) > limit) { limit = ARRAY_LENGTH(&c->message_log) - limit; for (i = 0; i < limit; i++) { @@ -771,16 +747,20 @@ status_prompt_set(struct client *c, const char *msg, const char *input, int (*callbackfn)(void *, const char *), void (*freefn)(void *), void *data, int flags) { - int keys; + struct format_tree *ft; + int keys; + time_t t; + + ft = format_create(); + format_defaults(ft, c, NULL, NULL, NULL); + t = time(NULL); status_message_clear(c); status_prompt_clear(c); - c->prompt_string = status_replace(c, NULL, NULL, NULL, msg, - time(NULL), 0); + c->prompt_string = format_expand_time(ft, msg, time(NULL)); - c->prompt_buffer = status_replace(c, NULL, NULL, NULL, input, - time(NULL), 0); + c->prompt_buffer = format_expand_time(ft, input, time(NULL)); c->prompt_index = strlen(c->prompt_buffer); c->prompt_callbackfn = callbackfn; @@ -799,6 +779,8 @@ status_prompt_set(struct client *c, const char *msg, const char *input, c->tty.flags |= (TTY_NOCURSOR|TTY_FREEZE); c->flags |= CLIENT_STATUS; + + format_free(ft); } /* Remove status line prompt. */ @@ -827,18 +809,25 @@ status_prompt_clear(struct client *c) void status_prompt_update(struct client *c, const char *msg, const char *input) { + struct format_tree *ft; + time_t t; + + ft = format_create(); + format_defaults(ft, c, NULL, NULL, NULL); + t = time(NULL); + free(c->prompt_string); - c->prompt_string = status_replace(c, NULL, NULL, NULL, msg, - time(NULL), 0); + c->prompt_string = format_expand_time(ft, msg, time(NULL)); free(c->prompt_buffer); - c->prompt_buffer = status_replace(c, NULL, NULL, NULL, input, - time(NULL), 0); + c->prompt_buffer = format_expand_time(ft, input, time(NULL)); c->prompt_index = strlen(c->prompt_buffer); c->prompt_hindex = 0; c->flags |= CLIENT_STATUS; + + format_free(ft); } /* Draw client prompt on status line of present else on last line. */ @@ -996,7 +985,7 @@ status_prompt_key(struct client *c, int key) /* Insert the new word. */ size += strlen(s); off = first - c->prompt_buffer; - c->prompt_buffer = xrealloc(c->prompt_buffer, 1, size + 1); + c->prompt_buffer = xrealloc(c->prompt_buffer, size + 1); first = c->prompt_buffer + off; memmove(first + strlen(s), first, n); memcpy(first, s, strlen(s)); @@ -1166,7 +1155,7 @@ status_prompt_key(struct client *c, int key) c->flags |= CLIENT_STATUS; break; case MODEKEYEDIT_PASTE: - if ((pb = paste_get_top(&global_buffers)) == NULL) + if ((pb = paste_get_top()) == NULL) break; for (n = 0; n < pb->size; n++) { ch = (u_char) pb->data[n]; @@ -1174,7 +1163,7 @@ status_prompt_key(struct client *c, int key) break; } - c->prompt_buffer = xrealloc(c->prompt_buffer, 1, size + n + 1); + c->prompt_buffer = xrealloc(c->prompt_buffer, size + n + 1); if (c->prompt_index == size) { memcpy(c->prompt_buffer + c->prompt_index, pb->data, n); c->prompt_index += n; @@ -1214,7 +1203,7 @@ status_prompt_key(struct client *c, int key) case MODEKEY_OTHER: if ((key & 0xff00) != 0 || key < 32 || key == 127) break; - c->prompt_buffer = xrealloc(c->prompt_buffer, 1, size + 2); + c->prompt_buffer = xrealloc(c->prompt_buffer, size + 2); if (c->prompt_index == size) { c->prompt_buffer[c->prompt_index++] = key; |