summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2008-06-07 06:13:21 +0000
committerNicholas Marriott <nicholas.marriott@gmail.com>2008-06-07 06:13:21 +0000
commit713bad063aefe78960c94e7f482e206524400e6f (patch)
tree92807bda0faf9158823adeb474a7bd53c18cc039
parent29e225361168640eca39b2d2e2108bc2792d4fbb (diff)
Make status-interval actually changeable.
-rw-r--r--CHANGES6
-rw-r--r--cmd-set-option.c20
-rw-r--r--server.c34
-rw-r--r--status.c5
4 files changed, 49 insertions, 16 deletions
diff --git a/CHANGES b/CHANGES
index c6710ddc..a59a8bd6 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,7 @@
+07 June 2008
+
+* Make status-interval actually changable.
+
06 June 2008
* New window option: aggressive-resize. Normally, windows are resized to the
@@ -452,4 +456,4 @@
(including mutt, emacs). No status bar yet and no key remapping or other
customisation.
-$Id: CHANGES,v 1.115 2008-06-06 20:02:27 nicm Exp $
+$Id: CHANGES,v 1.116 2008-06-07 06:13:21 nicm Exp $
diff --git a/cmd-set-option.c b/cmd-set-option.c
index ee962da9..f6752223 100644
--- a/cmd-set-option.c
+++ b/cmd-set-option.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-set-option.c,v 1.25 2008-06-05 21:25:00 nicm Exp $ */
+/* $Id: cmd-set-option.c,v 1.26 2008-06-07 06:13:21 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -125,6 +125,8 @@ cmd_set_option_exec(struct cmd *self, unused struct cmd_ctx *ctx)
number = -1;
if (data->value != NULL) {
number = strtonum(data->value, 0, INT_MAX, &errstr);
+ if (errstr != NULL)
+ number = 0;
bool = -1;
if (number == 1 || strcasecmp(data->value, "on") == 0 ||
@@ -221,10 +223,14 @@ cmd_set_option_exec(struct cmd *self, unused struct cmd_ctx *ctx)
}
options_set_string(oo, "default-command", "%s", data->value);
} else if (strcmp(data->option, "history-limit") == 0) {
- if (data->value == NULL) {
+ if (data->value == NULL || number == -1) {
ctx->error(ctx, "invalid value");
return;
}
+ if (errstr != NULL) {
+ ctx->error(ctx, "history-limit %s", errstr);
+ return;
+ }
if (number > SHRT_MAX) {
ctx->error(ctx, "history-limit too big: %u", number);
return;
@@ -256,6 +262,16 @@ cmd_set_option_exec(struct cmd *self, unused struct cmd_ctx *ctx)
if (c != NULL && c->session != NULL)
server_redraw_client(c);
}
+ } else if (strcmp(data->option, "status-interval") == 0) {
+ if (data->value == NULL || number == -1) {
+ ctx->error(ctx, "invalid value");
+ return;
+ }
+ if (errstr != NULL) {
+ ctx->error(ctx, "status-interval %s", errstr);
+ return;
+ }
+ options_set_number(oo, "status-interval", number);
} else {
ctx->error(ctx, "unknown option: %s", data->option);
return;
diff --git a/server.c b/server.c
index 0d20b298..0f8a6fb4 100644
--- a/server.c
+++ b/server.c
@@ -1,4 +1,4 @@
-/* $Id: server.c,v 1.55 2008-06-06 17:55:27 nicm Exp $ */
+/* $Id: server.c,v 1.56 2008-06-07 06:13:21 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -54,6 +54,7 @@ void server_handle_client(struct client *);
void server_handle_window(struct window *);
void server_lost_client(struct client *);
void server_lost_window(struct window *);
+void server_check_status(struct client *);
/* Fork new server. */
pid_t
@@ -268,6 +269,28 @@ server_handle_windows(struct pollfd **pfd)
}
}
+/* Check for status line redraw on client. */
+void
+server_check_status(struct client *c)
+{
+ struct timespec ts;
+ u_int nlines, interval;
+
+ if (c->session == NULL)
+ return;
+ nlines = options_get_number(&c->session->options, "status-lines");
+ interval = options_get_number(&c->session->options, "status-interval");
+ if (nlines == 0 || interval == 0)
+ return;
+
+ if (clock_gettime(CLOCK_REALTIME, &ts) != 0)
+ fatal("clock_gettime");
+ ts.tv_sec -= interval;
+
+ if (timespeccmp(&c->status_ts, &ts, <))
+ server_status_client(c);
+}
+
/* Fill client pollfds. */
void
server_fill_clients(struct pollfd **pfd)
@@ -307,20 +330,13 @@ void
server_handle_clients(struct pollfd **pfd)
{
struct client *c;
- struct timespec now;
u_int i;
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
c = ARRAY_ITEM(&clients, i);
if (c != NULL) {
- if (c->session != NULL && options_get_number(
- &c->session->options, "status-lines") != 0) {
- if (clock_gettime(CLOCK_REALTIME, &now) != 0)
- fatal("clock_gettime");
- if (timespeccmp(&now, &c->status_ts, >))
- server_status_client(c);
- }
+ server_check_status(c);
log_debug("testing client %d (%d)", (*pfd)->fd, c->fd);
if (buffer_poll(*pfd, c->in, c->out) != 0) {
diff --git a/status.c b/status.c
index 1bec6f35..4e950d76 100644
--- a/status.c
+++ b/status.c
@@ -1,4 +1,4 @@
-/* $Id: status.c,v 1.22 2008-06-06 17:20:30 nicm Exp $ */
+/* $Id: status.c,v 1.23 2008-06-07 06:13:21 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -52,9 +52,6 @@ status_write_client(struct client *c)
strftime(rbuf, sizeof rbuf, right, localtime(&(c->status_ts.tv_sec)));
rlen = strlen(rbuf) + 1;
- c->status_ts.tv_sec +=
- options_get_number(&c->session->options, "status-interval");
-
screen_redraw_start_client(&ctx, c);
screen_redraw_move_cursor(&ctx, llen, c->sy - slines);
screen_redraw_set_attributes(&ctx, 0, scolour);