diff options
Diffstat (limited to 'status.c')
-rw-r--r-- | status.c | 99 |
1 files changed, 48 insertions, 51 deletions
@@ -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); @@ -328,7 +331,7 @@ draw: 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 */ @@ -362,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; @@ -380,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; @@ -432,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; @@ -443,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'; @@ -465,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); @@ -620,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; @@ -642,7 +626,7 @@ status_print( 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); } @@ -763,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; @@ -791,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. */ @@ -819,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. */ |