mirror of
https://github.com/tmux/tmux.git
synced 2025-03-24 06:48:48 +00:00
Store the time in the format tree rather than passing it around.
This commit is contained in:
parent
bace79a571
commit
10d60faba5
@ -86,7 +86,7 @@ cmd_display_message_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
ft = format_create(item->client, item, FORMAT_NONE, 0);
|
ft = format_create(item->client, item, FORMAT_NONE, 0);
|
||||||
format_defaults(ft, target_c, s, wl, wp);
|
format_defaults(ft, target_c, s, wl, wp);
|
||||||
|
|
||||||
msg = format_expand_time(ft, template, 0);
|
msg = format_expand_time(ft, template);
|
||||||
if (args_has(self->args, 'p'))
|
if (args_has(self->args, 'p'))
|
||||||
cmdq_print(item, "%s", msg);
|
cmdq_print(item, "%s", msg);
|
||||||
else if (c != NULL)
|
else if (c != NULL)
|
||||||
|
@ -110,7 +110,7 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
/* Expand the command. */
|
/* Expand the command. */
|
||||||
ft = format_create(item->client, item, FORMAT_NONE, 0);
|
ft = format_create(item->client, item, FORMAT_NONE, 0);
|
||||||
format_defaults(ft, c, s, wl, wp);
|
format_defaults(ft, c, s, wl, wp);
|
||||||
cmd = format_expand_time(ft, args->argv[0], 0);
|
cmd = format_expand_time(ft, args->argv[0]);
|
||||||
format_free(ft);
|
format_free(ft);
|
||||||
|
|
||||||
/* Fork the child. */
|
/* Fork the child. */
|
||||||
|
11
format.c
11
format.c
@ -121,6 +121,7 @@ struct format_tree {
|
|||||||
struct client *client;
|
struct client *client;
|
||||||
u_int tag;
|
u_int tag;
|
||||||
int flags;
|
int flags;
|
||||||
|
time_t time;
|
||||||
|
|
||||||
RB_HEAD(format_entry_tree, format_entry) tree;
|
RB_HEAD(format_entry_tree, format_entry) tree;
|
||||||
};
|
};
|
||||||
@ -682,6 +683,7 @@ format_create(struct client *c, struct cmdq_item *item, int tag, int flags)
|
|||||||
|
|
||||||
ft->tag = tag;
|
ft->tag = tag;
|
||||||
ft->flags = flags;
|
ft->flags = flags;
|
||||||
|
ft->time = time(NULL);
|
||||||
|
|
||||||
format_add_cb(ft, "host", format_cb_host);
|
format_add_cb(ft, "host", format_cb_host);
|
||||||
format_add_cb(ft, "host_short", format_cb_host_short);
|
format_add_cb(ft, "host_short", format_cb_host_short);
|
||||||
@ -1437,7 +1439,7 @@ done:
|
|||||||
value = new;
|
value = new;
|
||||||
}
|
}
|
||||||
else if (modifiers & FORMAT_EXPANDTIME) {
|
else if (modifiers & FORMAT_EXPANDTIME) {
|
||||||
new = format_expand_time(ft, value, 0);
|
new = format_expand_time(ft, value);
|
||||||
free(value);
|
free(value);
|
||||||
value = new;
|
value = new;
|
||||||
}
|
}
|
||||||
@ -1483,7 +1485,7 @@ fail:
|
|||||||
|
|
||||||
/* Expand keys in a template, passing through strftime first. */
|
/* Expand keys in a template, passing through strftime first. */
|
||||||
char *
|
char *
|
||||||
format_expand_time(struct format_tree *ft, const char *fmt, time_t t)
|
format_expand_time(struct format_tree *ft, const char *fmt)
|
||||||
{
|
{
|
||||||
struct tm *tm;
|
struct tm *tm;
|
||||||
char s[2048];
|
char s[2048];
|
||||||
@ -1491,10 +1493,7 @@ format_expand_time(struct format_tree *ft, const char *fmt, time_t t)
|
|||||||
if (fmt == NULL || *fmt == '\0')
|
if (fmt == NULL || *fmt == '\0')
|
||||||
return (xstrdup(""));
|
return (xstrdup(""));
|
||||||
|
|
||||||
if (t == 0)
|
tm = localtime(&ft->time);
|
||||||
t = time(NULL);
|
|
||||||
tm = localtime(&t);
|
|
||||||
|
|
||||||
if (strftime(s, sizeof s, fmt, tm) == 0)
|
if (strftime(s, sizeof s, fmt, tm) == 0)
|
||||||
return (xstrdup(""));
|
return (xstrdup(""));
|
||||||
|
|
||||||
|
@ -1537,7 +1537,7 @@ server_client_set_title(struct client *c)
|
|||||||
ft = format_create(c, NULL, FORMAT_NONE, 0);
|
ft = format_create(c, NULL, FORMAT_NONE, 0);
|
||||||
format_defaults(ft, c, NULL, NULL, NULL);
|
format_defaults(ft, c, NULL, NULL, NULL);
|
||||||
|
|
||||||
title = format_expand_time(ft, template, 0);
|
title = format_expand_time(ft, template);
|
||||||
if (c->title == NULL || strcmp(title, c->title) != 0) {
|
if (c->title == NULL || strcmp(title, c->title) != 0) {
|
||||||
free(c->title);
|
free(c->title);
|
||||||
c->title = xstrdup(title);
|
c->title = xstrdup(title);
|
||||||
|
55
status.c
55
status.c
@ -29,14 +29,14 @@
|
|||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
static char *status_redraw_get_left(struct client *, time_t,
|
static char *status_redraw_get_left(struct client *, struct grid_cell *,
|
||||||
struct grid_cell *, size_t *);
|
size_t *);
|
||||||
static char *status_redraw_get_right(struct client *, time_t,
|
static char *status_redraw_get_right(struct client *, struct grid_cell *,
|
||||||
struct grid_cell *, size_t *);
|
size_t *);
|
||||||
static char *status_print(struct client *, struct winlink *, time_t,
|
static char *status_print(struct client *, struct winlink *,
|
||||||
struct grid_cell *);
|
struct grid_cell *);
|
||||||
static char *status_replace(struct client *, struct winlink *, const char *,
|
static char *status_replace(struct client *, struct winlink *,
|
||||||
time_t);
|
const char *);
|
||||||
static void status_message_callback(int, short, void *);
|
static void status_message_callback(int, short, void *);
|
||||||
static void status_timer_callback(int, short, void *);
|
static void status_timer_callback(int, short, void *);
|
||||||
|
|
||||||
@ -232,8 +232,7 @@ status_line_size(struct client *c)
|
|||||||
|
|
||||||
/* Retrieve options for left string. */
|
/* Retrieve options for left string. */
|
||||||
static char *
|
static char *
|
||||||
status_redraw_get_left(struct client *c, time_t t, struct grid_cell *gc,
|
status_redraw_get_left(struct client *c, struct grid_cell *gc, size_t *size)
|
||||||
size_t *size)
|
|
||||||
{
|
{
|
||||||
struct session *s = c->session;
|
struct session *s = c->session;
|
||||||
const char *template;
|
const char *template;
|
||||||
@ -243,7 +242,7 @@ status_redraw_get_left(struct client *c, time_t t, struct grid_cell *gc,
|
|||||||
style_apply_update(gc, s->options, "status-left-style");
|
style_apply_update(gc, s->options, "status-left-style");
|
||||||
|
|
||||||
template = options_get_string(s->options, "status-left");
|
template = options_get_string(s->options, "status-left");
|
||||||
left = status_replace(c, NULL, template, t);
|
left = status_replace(c, NULL, template);
|
||||||
|
|
||||||
*size = options_get_number(s->options, "status-left-length");
|
*size = options_get_number(s->options, "status-left-length");
|
||||||
leftlen = screen_write_cstrlen("%s", left);
|
leftlen = screen_write_cstrlen("%s", left);
|
||||||
@ -254,8 +253,7 @@ status_redraw_get_left(struct client *c, time_t t, struct grid_cell *gc,
|
|||||||
|
|
||||||
/* Retrieve options for right string. */
|
/* Retrieve options for right string. */
|
||||||
static char *
|
static char *
|
||||||
status_redraw_get_right(struct client *c, time_t t, struct grid_cell *gc,
|
status_redraw_get_right(struct client *c, struct grid_cell *gc, size_t *size)
|
||||||
size_t *size)
|
|
||||||
{
|
{
|
||||||
struct session *s = c->session;
|
struct session *s = c->session;
|
||||||
const char *template;
|
const char *template;
|
||||||
@ -265,7 +263,7 @@ status_redraw_get_right(struct client *c, time_t t, struct grid_cell *gc,
|
|||||||
style_apply_update(gc, s->options, "status-right-style");
|
style_apply_update(gc, s->options, "status-right-style");
|
||||||
|
|
||||||
template = options_get_string(s->options, "status-right");
|
template = options_get_string(s->options, "status-right");
|
||||||
right = status_replace(c, NULL, template, t);
|
right = status_replace(c, NULL, template);
|
||||||
|
|
||||||
*size = options_get_number(s->options, "status-right-length");
|
*size = options_get_number(s->options, "status-right-length");
|
||||||
rightlen = screen_write_cstrlen("%s", right);
|
rightlen = screen_write_cstrlen("%s", right);
|
||||||
@ -308,7 +306,6 @@ status_redraw(struct client *c)
|
|||||||
struct screen old_status, window_list;
|
struct screen old_status, window_list;
|
||||||
struct grid_cell stdgc, lgc, rgc, gc;
|
struct grid_cell stdgc, lgc, rgc, gc;
|
||||||
struct options *oo;
|
struct options *oo;
|
||||||
time_t t;
|
|
||||||
char *left, *right;
|
char *left, *right;
|
||||||
const char *sep;
|
const char *sep;
|
||||||
u_int offset, needed, lines;
|
u_int offset, needed, lines;
|
||||||
@ -330,9 +327,6 @@ status_redraw(struct client *c)
|
|||||||
left = right = NULL;
|
left = right = NULL;
|
||||||
larrow = rarrow = 0;
|
larrow = rarrow = 0;
|
||||||
|
|
||||||
/* Store current time. */
|
|
||||||
t = time(NULL);
|
|
||||||
|
|
||||||
/* Set up default colour. */
|
/* Set up default colour. */
|
||||||
style_apply(&stdgc, s->options, "status-style");
|
style_apply(&stdgc, s->options, "status-style");
|
||||||
|
|
||||||
@ -350,9 +344,9 @@ status_redraw(struct client *c)
|
|||||||
|
|
||||||
/* Work out left and right strings. */
|
/* Work out left and right strings. */
|
||||||
memcpy(&lgc, &stdgc, sizeof lgc);
|
memcpy(&lgc, &stdgc, sizeof lgc);
|
||||||
left = status_redraw_get_left(c, t, &lgc, &llen);
|
left = status_redraw_get_left(c, &lgc, &llen);
|
||||||
memcpy(&rgc, &stdgc, sizeof rgc);
|
memcpy(&rgc, &stdgc, sizeof rgc);
|
||||||
right = status_redraw_get_right(c, t, &rgc, &rlen);
|
right = status_redraw_get_right(c, &rgc, &rlen);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Figure out how much space we have for the window list. If there
|
* Figure out how much space we have for the window list. If there
|
||||||
@ -372,7 +366,7 @@ status_redraw(struct client *c)
|
|||||||
RB_FOREACH(wl, winlinks, &s->windows) {
|
RB_FOREACH(wl, winlinks, &s->windows) {
|
||||||
free(wl->status_text);
|
free(wl->status_text);
|
||||||
memcpy(&wl->status_cell, &stdgc, sizeof wl->status_cell);
|
memcpy(&wl->status_cell, &stdgc, sizeof wl->status_cell);
|
||||||
wl->status_text = status_print(c, wl, t, &wl->status_cell);
|
wl->status_text = status_print(c, wl, &wl->status_cell);
|
||||||
wl->status_width = screen_write_cstrlen("%s", wl->status_text);
|
wl->status_width = screen_write_cstrlen("%s", wl->status_text);
|
||||||
|
|
||||||
if (wl == s->curw)
|
if (wl == s->curw)
|
||||||
@ -531,7 +525,7 @@ out:
|
|||||||
|
|
||||||
/* Replace special sequences in fmt. */
|
/* Replace special sequences in fmt. */
|
||||||
static char *
|
static char *
|
||||||
status_replace(struct client *c, struct winlink *wl, const char *fmt, time_t t)
|
status_replace(struct client *c, struct winlink *wl, const char *fmt)
|
||||||
{
|
{
|
||||||
struct format_tree *ft;
|
struct format_tree *ft;
|
||||||
char *expanded;
|
char *expanded;
|
||||||
@ -550,7 +544,7 @@ status_replace(struct client *c, struct winlink *wl, const char *fmt, time_t t)
|
|||||||
ft = format_create(c, NULL, tag, FORMAT_STATUS);
|
ft = format_create(c, NULL, tag, FORMAT_STATUS);
|
||||||
format_defaults(ft, c, NULL, wl, NULL);
|
format_defaults(ft, c, NULL, wl, NULL);
|
||||||
|
|
||||||
expanded = format_expand_time(ft, fmt, t);
|
expanded = format_expand_time(ft, fmt);
|
||||||
|
|
||||||
format_free(ft);
|
format_free(ft);
|
||||||
return (expanded);
|
return (expanded);
|
||||||
@ -558,8 +552,7 @@ status_replace(struct client *c, struct winlink *wl, const char *fmt, time_t t)
|
|||||||
|
|
||||||
/* Return winlink status line entry and adjust gc as necessary. */
|
/* Return winlink status line entry and adjust gc as necessary. */
|
||||||
static char *
|
static char *
|
||||||
status_print(struct client *c, struct winlink *wl, time_t t,
|
status_print(struct client *c, struct winlink *wl, struct grid_cell *gc)
|
||||||
struct grid_cell *gc)
|
|
||||||
{
|
{
|
||||||
struct options *oo = wl->window->options;
|
struct options *oo = wl->window->options;
|
||||||
struct session *s = c->session;
|
struct session *s = c->session;
|
||||||
@ -580,7 +573,7 @@ status_print(struct client *c, struct winlink *wl, time_t t,
|
|||||||
else if (wl->flags & (WINLINK_ACTIVITY|WINLINK_SILENCE))
|
else if (wl->flags & (WINLINK_ACTIVITY|WINLINK_SILENCE))
|
||||||
style_apply_update(gc, oo, "window-status-activity-style");
|
style_apply_update(gc, oo, "window-status-activity-style");
|
||||||
|
|
||||||
text = status_replace(c, wl, fmt, t);
|
text = status_replace(c, wl, fmt);
|
||||||
return (text);
|
return (text);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -698,19 +691,17 @@ status_prompt_set(struct client *c, const char *msg, const char *input,
|
|||||||
prompt_input_cb inputcb, prompt_free_cb freecb, void *data, int flags)
|
prompt_input_cb inputcb, prompt_free_cb freecb, void *data, int flags)
|
||||||
{
|
{
|
||||||
struct format_tree *ft;
|
struct format_tree *ft;
|
||||||
time_t t;
|
|
||||||
char *tmp, *cp;
|
char *tmp, *cp;
|
||||||
|
|
||||||
ft = format_create(c, NULL, FORMAT_NONE, 0);
|
ft = format_create(c, NULL, FORMAT_NONE, 0);
|
||||||
format_defaults(ft, c, NULL, NULL, NULL);
|
format_defaults(ft, c, NULL, NULL, NULL);
|
||||||
t = time(NULL);
|
|
||||||
|
|
||||||
if (input == NULL)
|
if (input == NULL)
|
||||||
input = "";
|
input = "";
|
||||||
if (flags & PROMPT_NOFORMAT)
|
if (flags & PROMPT_NOFORMAT)
|
||||||
tmp = xstrdup(input);
|
tmp = xstrdup(input);
|
||||||
else
|
else
|
||||||
tmp = format_expand_time(ft, input, t);
|
tmp = format_expand_time(ft, input);
|
||||||
|
|
||||||
status_message_clear(c);
|
status_message_clear(c);
|
||||||
status_prompt_clear(c);
|
status_prompt_clear(c);
|
||||||
@ -722,7 +713,7 @@ status_prompt_set(struct client *c, const char *msg, const char *input,
|
|||||||
screen_init(&c->status.status, c->tty.sx, 1, 0);
|
screen_init(&c->status.status, c->tty.sx, 1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
c->prompt_string = format_expand_time(ft, msg, t);
|
c->prompt_string = format_expand_time(ft, msg);
|
||||||
|
|
||||||
c->prompt_buffer = utf8_fromcstr(tmp);
|
c->prompt_buffer = utf8_fromcstr(tmp);
|
||||||
c->prompt_index = utf8_strlen(c->prompt_buffer);
|
c->prompt_index = utf8_strlen(c->prompt_buffer);
|
||||||
@ -780,17 +771,15 @@ void
|
|||||||
status_prompt_update(struct client *c, const char *msg, const char *input)
|
status_prompt_update(struct client *c, const char *msg, const char *input)
|
||||||
{
|
{
|
||||||
struct format_tree *ft;
|
struct format_tree *ft;
|
||||||
time_t t;
|
|
||||||
char *tmp;
|
char *tmp;
|
||||||
|
|
||||||
ft = format_create(c, NULL, FORMAT_NONE, 0);
|
ft = format_create(c, NULL, FORMAT_NONE, 0);
|
||||||
format_defaults(ft, c, NULL, NULL, NULL);
|
format_defaults(ft, c, NULL, NULL, NULL);
|
||||||
|
|
||||||
t = time(NULL);
|
tmp = format_expand_time(ft, input);
|
||||||
tmp = format_expand_time(ft, input, t);
|
|
||||||
|
|
||||||
free(c->prompt_string);
|
free(c->prompt_string);
|
||||||
c->prompt_string = format_expand_time(ft, msg, t);
|
c->prompt_string = format_expand_time(ft, msg);
|
||||||
|
|
||||||
free(c->prompt_buffer);
|
free(c->prompt_buffer);
|
||||||
c->prompt_buffer = utf8_fromcstr(tmp);
|
c->prompt_buffer = utf8_fromcstr(tmp);
|
||||||
|
2
tmux.h
2
tmux.h
@ -1585,7 +1585,7 @@ struct format_tree *format_create(struct client *, struct cmdq_item *, int,
|
|||||||
void format_free(struct format_tree *);
|
void format_free(struct format_tree *);
|
||||||
void printflike(3, 4) format_add(struct format_tree *, const char *,
|
void printflike(3, 4) format_add(struct format_tree *, const char *,
|
||||||
const char *, ...);
|
const char *, ...);
|
||||||
char *format_expand_time(struct format_tree *, const char *, time_t);
|
char *format_expand_time(struct format_tree *, const char *);
|
||||||
char *format_expand(struct format_tree *, const char *);
|
char *format_expand(struct format_tree *, const char *);
|
||||||
char *format_single(struct cmdq_item *, const char *,
|
char *format_single(struct cmdq_item *, const char *,
|
||||||
struct client *, struct session *, struct winlink *,
|
struct client *, struct session *, struct winlink *,
|
||||||
|
Loading…
Reference in New Issue
Block a user