From ff16e15389c4ad10a31a8286edc98a5e9761ba43 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Sun, 25 Nov 2001 15:41:37 +0000 Subject: [PATCH] /FORMAT timestamp and /FORMAT day_changed use now strftime()-style formats for specifying time. %x is still treated as color format, so you'll need to escape them with another % (%%H:%%S). The $ parameters don't work anymore. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@2142 dbcabf3a-b0e7-0310-adc4-f8d773084564 --- src/fe-common/core/fe-windows.c | 28 +++++++++++++++++++--------- src/fe-common/core/formats.c | 11 +++++++---- src/fe-common/core/module-formats.c | 4 ++-- 3 files changed, 28 insertions(+), 15 deletions(-) diff --git a/src/fe-common/core/fe-windows.c b/src/fe-common/core/fe-windows.c index 5c323c68..5eb19314 100644 --- a/src/fe-common/core/fe-windows.c +++ b/src/fe-common/core/fe-windows.c @@ -500,18 +500,31 @@ static void sig_server_disconnected(SERVER_REC *server) } } +static void window_print_daychange(WINDOW_REC *window, struct tm *tm) +{ + THEME_REC *theme; + TEXT_DEST_REC dest; + char *format, str[256]; + + theme = active_win->theme != NULL ? active_win->theme : current_theme; + format_create_dest(&dest, NULL, NULL, MSGLEVEL_NEVER, window); + format = format_get_text_theme(theme, MODULE_NAME, &dest, + TXT_DAYCHANGE); + if (strftime(str, sizeof(str), format, tm) <= 0) + str[0] = '\0'; + g_free(format); + + printtext_string_window(window, MSGLEVEL_NEVER, str); +} + static void sig_print_text(void) { GSList *tmp; - char month[100]; time_t t; struct tm *tm; t = time(NULL); tm = localtime(&t); - if (strftime(month, sizeof(month), "%b", tm) <= 0) - month[0] = '\0'; - if (tm->tm_hour != 0 || tm->tm_min != 0) return; @@ -519,11 +532,8 @@ static void sig_print_text(void) signal_remove("print text", (SIGNAL_FUNC) sig_print_text); /* day changed, print notice about it to every window */ - for (tmp = windows; tmp != NULL; tmp = tmp->next) { - printformat_window(tmp->data, MSGLEVEL_NEVER, TXT_DAYCHANGE, - tm->tm_mday, tm->tm_mon+1, - 1900+tm->tm_year, month); - } + for (tmp = windows; tmp != NULL; tmp = tmp->next) + window_print_daychange(tmp->data, tm); } static int sig_check_daychange(void) diff --git a/src/fe-common/core/formats.c b/src/fe-common/core/formats.c index cb4a2829..9ff57056 100644 --- a/src/fe-common/core/formats.c +++ b/src/fe-common/core/formats.c @@ -579,6 +579,7 @@ char *format_get_level_tag(THEME_REC *theme, TEXT_DEST_REC *dest) static char *get_timestamp(THEME_REC *theme, TEXT_DEST_REC *dest, time_t t) { + char *format, str[256]; struct tm *tm; int diff; @@ -602,10 +603,12 @@ static char *get_timestamp(THEME_REC *theme, TEXT_DEST_REC *dest, time_t t) } tm = localtime(&t); - return format_get_text_theme(theme, MODULE_NAME, dest, TXT_TIMESTAMP, - tm->tm_year+1900, - tm->tm_mon+1, tm->tm_mday, - tm->tm_hour, tm->tm_min, tm->tm_sec); + format = format_get_text_theme(theme, MODULE_NAME, dest, + TXT_TIMESTAMP); + if (strftime(str, sizeof(str), format, tm) <= 0) + str[0] = '\0'; + g_free(format); + return g_strdup(str); } static char *get_server_tag(THEME_REC *theme, TEXT_DEST_REC *dest) diff --git a/src/fe-common/core/module-formats.c b/src/fe-common/core/module-formats.c index ba6bbbe6..2f6a1d30 100644 --- a/src/fe-common/core/module-formats.c +++ b/src/fe-common/core/module-formats.c @@ -29,9 +29,9 @@ FORMAT_REC fecommon_core_formats[] = { { "line_start", "{line_start}", 0 }, { "line_start_irssi", "{line_start}{hilight Irssi:} ", 0 }, - { "timestamp", "{timestamp $Z} ", 6, { 1, 1, 1, 1, 1, 1 } }, + { "timestamp", "{timestamp $Z} ", 0 }, { "servertag", "[$0] ", 1, { 0 } }, - { "daychange", "Day changed to $[-2.0]{0} $3 $2", 4, { 1, 1, 1, 0 } }, + { "daychange", "Day changed to %%d %%b %%Y", 0 }, { "talking_with", "You are now talking with {nick $0}", 1, { 0 } }, { "refnum_too_low", "Window number must be greater than 1", 0 }, { "error_server_sticky", "Window's server is sticky and it cannot be changed without -unsticky option", 0 },