version 1.37, 2009/10/10 10:02:48 |
version 1.38, 2009/10/10 15:03:01 |
|
|
|
|
#include "tmux.h" |
#include "tmux.h" |
|
|
char *status_replace_popen(char **); |
char *status_job(struct client *, char **); |
|
void status_job_callback(struct job *); |
size_t status_width(struct winlink *); |
size_t status_width(struct winlink *); |
char *status_print(struct session *, struct winlink *, struct grid_cell *); |
char *status_print(struct session *, struct winlink *, struct grid_cell *); |
|
|
|
|
utf8flag = options_get_number(&s->options, "status-utf8"); |
utf8flag = options_get_number(&s->options, "status-utf8"); |
|
|
/* Work out the left and right strings. */ |
/* Work out the left and right strings. */ |
left = status_replace(s, options_get_string( |
left = status_replace(c, options_get_string( |
&s->options, "status-left"), c->status_timer.tv_sec); |
&s->options, "status-left"), c->status_timer.tv_sec); |
llen = options_get_number(&s->options, "status-left-length"); |
llen = options_get_number(&s->options, "status-left-length"); |
llen2 = screen_write_cstrlen(utf8flag, "%s", left); |
llen2 = screen_write_cstrlen(utf8flag, "%s", left); |
if (llen2 < llen) |
if (llen2 < llen) |
llen = llen2; |
llen = llen2; |
|
|
right = status_replace(s, options_get_string( |
right = status_replace(c, options_get_string( |
&s->options, "status-right"), c->status_timer.tv_sec); |
&s->options, "status-right"), c->status_timer.tv_sec); |
rlen = options_get_number(&s->options, "status-right-length"); |
rlen = options_get_number(&s->options, "status-right-length"); |
rlen2 = screen_write_cstrlen(utf8flag, "%s", right); |
rlen2 = screen_write_cstrlen(utf8flag, "%s", right); |
|
|
} |
} |
|
|
char * |
char * |
status_replace(struct session *s, const char *fmt, time_t t) |
status_replace(struct client *c, const char *fmt, time_t t) |
{ |
{ |
|
struct session *s = c->session; |
struct winlink *wl = s->curw; |
struct winlink *wl = s->curw; |
static char out[BUFSIZ]; |
static char out[BUFSIZ]; |
char in[BUFSIZ], tmp[256], ch, *iptr, *optr, *ptr, *endptr; |
char in[BUFSIZ], tmp[256], ch, *iptr, *optr, *ptr, *endptr; |
char *savedptr; |
char *savedptr; /* freed at end of each loop */ |
size_t len; |
size_t len; |
long n; |
long n; |
|
|
|
|
strftime(in, sizeof in, fmt, localtime(&t)); |
strftime(in, sizeof in, fmt, localtime(&t)); |
in[(sizeof in) - 1] = '\0'; |
in[(sizeof in) - 1] = '\0'; |
|
|
|
|
switch (*iptr++) { |
switch (*iptr++) { |
case '(': |
case '(': |
if (ptr == NULL) { |
if (ptr == NULL) { |
ptr = status_replace_popen(&iptr); |
ptr = status_job(c, &iptr); |
if (ptr == NULL) |
if (ptr == NULL) |
break; |
break; |
savedptr = ptr; |
savedptr = ptr; |
|
|
case 'P': |
case 'P': |
if (ptr == NULL) { |
if (ptr == NULL) { |
xsnprintf(tmp, sizeof tmp, "%u", |
xsnprintf(tmp, sizeof tmp, "%u", |
window_pane_index(wl->window, |
window_pane_index(wl->window, |
wl->window->active)); |
wl->window->active)); |
ptr = tmp; |
ptr = tmp; |
} |
} |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
|
|
} |
} |
|
|
char * |
char * |
status_replace_popen(char **iptr) |
status_job(struct client *c, char **iptr) |
{ |
{ |
FILE *f; |
struct job *job; |
char *buf, *cmd, *ptr; |
char *buf, *cmd; |
int lastesc; |
int lastesc; |
size_t len; |
size_t len; |
|
|
if (**iptr == '\0') |
if (**iptr == '\0') |
return (NULL); |
return (NULL); |
|
|
lastesc = 0; |
lastesc = 0; |
cmd[len++] = **iptr; |
cmd[len++] = **iptr; |
} |
} |
if (**iptr == '\0') /* no terminating ) */ |
if (**iptr == '\0') /* no terminating ) */ { |
goto out; |
xfree(cmd); |
|
return (NULL); |
|
} |
(*iptr)++; /* skip final ) */ |
(*iptr)++; /* skip final ) */ |
cmd[len] = '\0'; |
cmd[len] = '\0'; |
|
|
if ((f = popen(cmd, "r")) == NULL) |
job = job_get(&c->status_jobs, cmd); |
goto out; |
if (job == NULL) { |
|
job = job_add( |
if ((buf = fgetln(f, &len)) == NULL) { |
&c->status_jobs, c, cmd, status_job_callback, xfree, NULL); |
pclose(f); |
job_run(job); |
goto out; |
|
} |
} |
if (buf[len - 1] == '\n') { |
if (job->data == NULL) |
buf[len - 1] = '\0'; |
return (xstrdup("")); |
buf = xstrdup(buf); |
return (xstrdup(job->data)); |
} else { |
} |
ptr = xmalloc(len + 1); |
|
memcpy(ptr, buf, len); |
|
ptr[len] = '\0'; |
|
buf = ptr; |
|
} |
|
pclose(f); |
|
|
|
out: |
void |
xfree(cmd); |
status_job_callback(struct job *job) |
return (buf); |
{ |
|
char *buf; |
|
size_t len; |
|
|
|
len = BUFFER_USED(job->out); |
|
buf = xmalloc(len + 1); |
|
if (len != 0) |
|
buffer_read(job->out, buf, len); |
|
buf[len] = '\0'; |
|
buf[strcspn(buf, "\n")] = '\0'; |
|
|
|
if (job->data != NULL) |
|
xfree(job->data); |
|
else |
|
server_redraw_client(job->client); |
|
job->data = xstrdup(buf); |
|
|
|
xfree(buf); |
} |
} |
|
|
size_t |
size_t |