From 4363d4b53505708608b1a82f8bff45d7aefe18dc Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Thu, 28 Oct 2021 17:50:45 -0400 Subject: Parse IRC formatting in timestamp string MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Strip formatting when calculating the timestamp width to avoid moving a bunch of code around. Use styleAdd (now with an initial style parameter) to show timestamps. This allows changing the style of the timestamps from the default gray using literal IRC formatting codes in the string. Not ideal, but no new options needed. Suggested by Hoël Bézier and Sebastian LaVine. --- ui.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/ui.c b/ui.c index 1adcafe..2789bd7 100644 --- a/ui.c +++ b/ui.c @@ -276,10 +276,12 @@ void uiInitEarly(void) { if (!main) err(EX_OSERR, "newwin"); int y; + char fmt[TimeCap]; char buf[TimeCap]; + styleStrip(fmt, sizeof(fmt), uiTime.format); struct tm *time = localtime(&(time_t) { -22100400 }); - size_t len = strftime(buf, sizeof(buf), uiTime.format, time); - if (!len) errx(EX_CONFIG, "invalid timestamp format: %s", uiTime.format); + size_t len = strftime(buf, sizeof(buf), fmt, time); + if (!len) errx(EX_CONFIG, "invalid timestamp format: %s", fmt); waddstr(main, buf); waddch(main, ' '); getyx(main, y, uiTime.width); @@ -386,8 +388,8 @@ static short stylePair(struct Style style) { return colorPair(Colors[style.fg], Colors[style.bg]); } -static int styleAdd(WINDOW *win, const char *str) { - struct Style style = StyleDefault; +static int styleAdd(WINDOW *win, struct Style init, const char *str) { + struct Style style = init; while (*str) { size_t len = styleParse(&style, &str); wattr_set(win, styleAttr(style), stylePair(style), NULL); @@ -433,7 +435,7 @@ static void statusUpdate(void) { if (window->scroll) { ptr = seprintf(ptr, end, "~%d ", window->scroll); } - if (styleAdd(status, buf) < 0) break; + if (styleAdd(status, StyleDefault, buf) < 0) break; } wclrtoeol(status); @@ -514,18 +516,14 @@ static void mainAdd(int y, bool time, const struct Line *line) { if (time && line->time) { char buf[TimeCap]; strftime(buf, sizeof(buf), uiTime.format, localtime(&line->time)); - wattr_set( - main, - colorAttr(Colors[Gray]), colorPair(Colors[Gray], -1), - NULL - ); - waddstr(main, buf); + struct Style init = { .fg = Gray, .bg = Default }; + styleAdd(main, init, buf); waddch(main, ' '); } else if (time) { whline(main, ' ', uiTime.width); wmove(main, y, uiTime.width); } - styleAdd(main, line->str); + styleAdd(main, StyleDefault, line->str); getyx(main, ny, nx); if (ny != y) return; wclrtoeol(main); -- cgit 1.4.1