summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--degesch.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/degesch.c b/degesch.c
index 9078473..93ee71a 100644
--- a/degesch.c
+++ b/degesch.c
@@ -1309,6 +1309,7 @@ struct app_context
struct poller_fd signal_event; ///< Signal FD event
struct poller_timer flush_timer; ///< Flush all open files (e.g. logs)
+ struct poller_timer date_chg_tmr; ///< Print a date change
struct poller poller; ///< Manages polled descriptors
bool quitting; ///< User requested quitting
@@ -1326,7 +1327,6 @@ struct app_context
// TODO: make buffer names fully unique like weechat does
struct str_map buffers_by_name; ///< Buffers by name
- // TODO: So that we always output proper date change messages
time_t last_displayed_msg_time; ///< Time of last displayed message
// Terminal:
@@ -2967,6 +2967,9 @@ buffer_print_backlog (struct app_context *ctx, struct buffer *buffer)
buffer->unseen_messages_count = 0;
buffer->highlighted = false;
+ // So that it is obvious if the last line in the buffer is not from today
+ buffer_update_time (ctx, time (NULL));
+
refresh_prompt (ctx);
input_show (&ctx->input);
}
@@ -9015,6 +9018,22 @@ on_flush_timer (struct app_context *ctx)
}
static void
+rearm_date_change_timer (struct app_context *ctx)
+{
+ const time_t seconds_per_day = 60 * 60 * 12;
+ poller_timer_set (&ctx->date_chg_tmr,
+ (time (NULL) + seconds_per_day - 1)
+ / seconds_per_day * seconds_per_day * 1000);
+}
+
+static void
+on_date_change_timer (struct app_context *ctx)
+{
+ buffer_update_time (ctx, time (NULL));
+ rearm_date_change_timer (ctx);
+}
+
+static void
init_poller_events (struct app_context *ctx)
{
poller_fd_init (&ctx->signal_event, &ctx->poller, g_signal_pipe[0]);
@@ -9031,6 +9050,11 @@ init_poller_events (struct app_context *ctx)
ctx->flush_timer.dispatcher = (poller_timer_fn) on_flush_timer;
ctx->flush_timer.user_data = ctx;
rearm_flush_timer (ctx);
+
+ poller_timer_init (&ctx->date_chg_tmr, &ctx->poller);
+ ctx->flush_timer.dispatcher = (poller_timer_fn) on_date_change_timer;
+ ctx->flush_timer.user_data = ctx;
+ rearm_date_change_timer (ctx);
}
// --- Main program ------------------------------------------------------------