hirc

IRC client
Log | Files | Refs

commit b1e09c297d2a83651209236fd83fe29925dce4b6
parent b513f0aa40b0888f2c211db07db6c7a19c4a3afd
Author: hhvn <dev@hhvn.uk>
Date:   Tue,  3 May 2022 17:35:04 +0100

Insert indicator between messages on different days

Diffstat:
Msrc/data/config.h | 5+++++
Msrc/data/formats.h | 1+
Msrc/hist.c | 13+++++++++++++
3 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/src/data/config.h b/src/data/config.h @@ -335,6 +335,11 @@ struct Config config[] = { .strhandle = config_redraws, .description = { "Format of unread message indicator.", NULL}}, + {"format.ui.newday", 1, Val_string, + .str = "%{c:93}---%{=}%{c:93}%{b}%{time:%A %d %B %Y,${1}}%{b} ---", + .strhandle = config_redraws, + .description = { + "Format of indicator placed between messages on different days.", NULL}}, {"format.ui.ignores.start", 1, Val_string, .str = "Ignoring:", .strhandle = config_redraws, diff --git a/src/data/formats.h b/src/data/formats.h @@ -52,6 +52,7 @@ struct { {"SELF_AUTOCMDS_LIST", "format.ui.autocmds"}, {"SELF_AUTOCMDS_END", "format.ui.autocmds.end"}, {"SELF_LOG_RESTORE", "format.ui.logrestore"}, + {"SELF_NEW_DAY", "format.ui.newday"}, {"SELF_UNREAD", "format.ui.unread"}, {"SELF_IGNORES_START", "format.ui.ignores.start"}, {"SELF_IGNORES_LIST", "format.ui.ignores"}, diff --git a/src/hist.c b/src/hist.c @@ -126,6 +126,7 @@ hist_add(struct HistInfo *histinfo, struct Nick *from = NULL; struct History *new, *p; struct Ignore *ign; + struct tm ptm, ctm, dtm; int i; if (!histinfo || !msg) @@ -166,6 +167,18 @@ hist_add(struct HistInfo *histinfo, } } + if (strncmp(msg, "SELF_NEW_DAY", CONSTLEN("SELF_NEW_DAY")) != 0 && histinfo && histinfo->history && + histinfo->history->timestamp < timestamp && !(histinfo->history->options & HIST_RLOG)) { + localtime_r(&histinfo->history->timestamp, &ptm); + localtime_r(&timestamp, &ctm); + if (ptm.tm_mday != ctm.tm_mday || ptm.tm_mon != ctm.tm_mon || ptm.tm_year != ctm.tm_year) { + memcpy(&dtm, &ctm, sizeof(struct tm)); + dtm.tm_sec = dtm.tm_min = dtm.tm_hour = 0; + hist_format(histinfo, Activity_none, histinfo->server ? HIST_DFL : HIST_SHOW, + "SELF_NEW_DAY %d :day changed to", (long long)mktime(&dtm)); + } + } + if (!histinfo->history) { histinfo->history = new; goto ui;