hirc

IRC client
Log | Files | Refs

commit 6f0dbca27bac03e6c9b5232ad95f0e17150f7900
parent d7ca250a7b4296e750a070aa96949c6953a3219c
Author: hhvn <dev@hhvn.uk>
Date:   Sat, 12 Mar 2022 20:40:47 +0000

More granular /clear options

Diffstat:
Msrc/commands.c | 35+++++++++++++++++++++++++++++------
Msrc/handle.c | 16++++++----------
Msrc/hist.c | 6+++---
Msrc/struct.h | 7+++++--
Msrc/ui.c | 8++++----
5 files changed, 47 insertions(+), 25 deletions(-)

diff --git a/src/commands.c b/src/commands.c @@ -290,8 +290,14 @@ struct Command commands[] = { "Searches are also cleared after selecting another buffer", "See also config variables: regex.extended and regex.icase", NULL}}, {"clear", command_clear, 0, { - "usage: /clear [-tmp]", - "Clear selected buffer of (temporary if -tmp) messages", NULL}}, + "usage: /clear [-tmp] [-err] [-serr] [-log]", + "Clear selected buffer of messages.", + "By default all messages are cleared.", + "The following options clear only certain messages:", + " -tmp: temporary messages - cleared when switching buffer", + " -err: hirc generated errors", + " -serr: server generated errors", + " -log: messages restored from log files", NULL}}, {"alias", command_alias, 0, { "usage: /alias [<alias> [cmd [...]]]", " /alias -delete <alias>", @@ -1432,10 +1438,13 @@ command_grep) { COMMAND( command_clear) { - int ret, tmp = 0; - enum { opt_tmp }; + int ret, cleared = 0; + enum { opt_tmp, opt_err, opt_serr, opt_log }; static struct CommandOpts opts[] = { {"tmp", CMD_NARG, opt_tmp}, + {"err", CMD_NARG, opt_err}, + {"serr", CMD_NARG, opt_serr}, + {"log", CMD_NARG, opt_log}, {NULL, 0, 0}, }; @@ -1445,7 +1454,20 @@ command_clear) { case opt_error: return; case opt_tmp: - tmp = 1; + hist_purgeopt(selected.history, HIST_TMP); + cleared = 1; + break; + case opt_err: + hist_purgeopt(selected.history, HIST_ERR); + cleared = 1; + break; + case opt_serr: + hist_purgeopt(selected.history, HIST_SERR); + cleared = 1; + break; + case opt_log: + hist_purgeopt(selected.history, HIST_RLOG); + cleared = 1; break; } } @@ -1456,7 +1478,8 @@ command_clear) { } } - hist_purgeopt(selected.history, tmp ? HIST_TMP : HIST_ALL); + if (!cleared) + hist_purgeopt(selected.history, HIST_ALL); windows[Win_main].refresh = 1; } diff --git a/src/handle.c b/src/handle.c @@ -429,7 +429,7 @@ handle_ERR_NOSUCHNICK) { expect_set(server, Expect_nosuchnick, NULL); } - hist_addp(chan ? chan->history : server->history, msg, Activity_error, HIST_DFL); + hist_addp(chan ? chan->history : server->history, msg, Activity_error, HIST_DFL|HIST_SERR); } HANDLER( @@ -612,14 +612,7 @@ handle(struct Server *server, char *msg) { char *schmsg; int i; - if (*msg == '!' && strchr(msg, ' ') && *(strchr(msg, ' ')+1) && *(msg+1) != ' ') { - msg++; - timestamp = (time_t)strtoll(msg, NULL, 10); - msg = strchr(msg, ' ') + 1; - } else { - timestamp = time(NULL); - } - + timestamp = time(NULL); params = param_create(msg); if (!*params) { free(params); @@ -650,6 +643,9 @@ handle(struct Server *server, char *msg) { } /* add it to server->history if there is no handler */ - hist_add(server->history, msg, Activity_status, timestamp, HIST_DFL); + if (*cmd == '4' && *cmd == '5') + hist_add(server->history, msg, Activity_error, timestamp, HIST_DFL|HIST_SERR); + else + hist_add(server->history, msg, Activity_status, timestamp, HIST_DFL); param_free(params); } diff --git a/src/hist.c b/src/hist.c @@ -188,7 +188,7 @@ hist_purgeopt(struct HistInfo *histinfo, enum HistOpt options) { if (p->next) p->next->prev = p->prev; - else + else if (!p->prev) histinfo->history = NULL; free(p); @@ -351,7 +351,7 @@ hist_loadlog(struct HistInfo *hist, char *server, char *channel) { if (from) from->self = *tok[3] == '1'; - p = hist_create(hist, from, tok[8], activity, timestamp, *tok[2] == '1' ? HIST_SHOW : 0); + p = hist_create(hist, from, tok[8], activity, timestamp, HIST_RLOG|(*tok[2] == '1' ? HIST_SHOW : 0)); if (!head) head = p; @@ -372,7 +372,7 @@ hist_loadlog(struct HistInfo *hist, char *server, char *channel) { len = snprintf(format, 0, "SELF_LOG_RESTORE %lld :log restored up to", (long long)head->timestamp) + 1; format = emalloc(len); snprintf(format, len, "SELF_LOG_RESTORE %lld :log restored up to", (long long)head->timestamp); - p = hist_create(hist, NULL, format, Activity_status, time(NULL), HIST_SHOW); + p = hist_create(hist, NULL, format, Activity_status, time(NULL), HIST_SHOW|HIST_RLOG); free(format); p->next = head; head->prev = p; diff --git a/src/struct.h b/src/struct.h @@ -48,11 +48,14 @@ enum Activity { enum HistOpt { HIST_SHOW = 1, /* show in buffer */ - HIST_LOG = 2, /* log to server->logfd */ + HIST_LOG = 2, /* log to server->logfd */ HIST_MAIN = 4, /* copy to &main_buf */ HIST_SELF = 8, /* from = self */ - HIST_TMP = 16, /* purge later */ + HIST_TMP = 16, /* purge later */ HIST_GREP = 32, /* generated by /grep */ + HIST_ERR = 64, /* generated by ui_error and friends */ + HIST_SERR = 128,/* generated by 400-599 numerics (which should be errors) */ + HIST_RLOG = 256,/* messages read from log, useful for clearing the log */ HIST_DFL = HIST_SHOW|HIST_LOG, HIST_ALL = 0xFFFF }; diff --git a/src/ui.c b/src/ui.c @@ -278,14 +278,14 @@ ui_error_(char *file, int line, const char *func, char *format, ...) { vsnprintf(msg, sizeof(msg), format, ap); va_end(ap); - hist_format(selected.history, Activity_error, HIST_SHOW|HIST_TMP|HIST_MAIN, + hist_format(selected.history, Activity_error, HIST_SHOW|HIST_TMP|HIST_MAIN|HIST_ERR, "SELF_ERROR %s %d %s :%s", file, line, func, msg); } void ui_perror_(char *file, int line, const char *func, char *str) { - hist_format(selected.history, Activity_error, HIST_SHOW|HIST_TMP|HIST_MAIN, + hist_format(selected.history, Activity_error, HIST_SHOW|HIST_TMP|HIST_MAIN|HIST_ERR, "SELF_ERROR %s %d %s :%s: %s", file, line, func, str, strerror(errno)); } @@ -293,14 +293,14 @@ ui_perror_(char *file, int line, const char *func, char *str) { #ifdef TLS void ui_tls_config_error_(char *file, int line, const char *func, struct tls_config *config, char *str) { - hist_format(selected.history, Activity_error, HIST_SHOW|HIST_TMP|HIST_MAIN, + hist_format(selected.history, Activity_error, HIST_SHOW|HIST_TMP|HIST_MAIN|HIST_ERR, "SELF_ERROR %s %d %s :%s: %s", file, line, func, str, tls_config_error(config)); } void ui_tls_error_(char *file, int line, const char *func, struct tls *ctx, char *str) { - hist_format(selected.history, Activity_error, HIST_SHOW|HIST_TMP|HIST_MAIN, + hist_format(selected.history, Activity_error, HIST_SHOW|HIST_TMP|HIST_MAIN|HIST_ERR, "SELF_ERROR %s %d %s :%s: %s", file, line, func, str, tls_error(ctx)); }