From 8ed93ae03e7d3dd14b97a5f42e949e7fad1ffe77 Mon Sep 17 00:00:00 2001
From: Přemysl Janouch
Date: Sat, 11 Jul 2015 06:10:46 +0200
Subject: degesch: write date change messages earlier
---
degesch.c | 26 +++++++++++++++++++++++++-
1 file changed, 25 insertions(+), 1 deletion(-)
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);
}
@@ -9014,6 +9017,22 @@ on_flush_timer (struct app_context *ctx)
rearm_flush_timer (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)
{
@@ -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 ------------------------------------------------------------
--
cgit v1.2.3-70-g09d2