From a878b1e6290bc5e0844719c9a14c3449630d6627 Mon Sep 17 00:00:00 2001 From: "jabber.developer2" Date: Sat, 1 Aug 2026 12:59:28 +0300 Subject: [PATCH] feat(ui): add cons_show_warning() (issue #87) The console had cons_show() for information and cons_show_error() for failures, but nothing in between, so callers reporting a condition the user should notice had to pick between hiding it and dressing it up as an error. cons_show_warning() prints through the new THEME_WARNING item, yellow by default, and prefixes the text with "Warning: ". Themes that do not set the "warning" colour fall back to that default, so the bundled themes need no change. Logging stays with the caller, as it does for the other console functions. --- src/config/theme.c | 4 ++++ src/config/theme.h | 1 + src/ui/console.c | 14 ++++++++++++++ src/ui/ui.h | 2 ++ tests/unittests/ui/stub_ui.c | 22 ++++++++++++++++++++++ tests/unittests/ui/stub_ui.h | 2 ++ 6 files changed, 45 insertions(+) diff --git a/src/config/theme.c b/src/config/theme.c index 1a3e8e30..236c2e8d 100644 --- a/src/config/theme.c +++ b/src/config/theme.c @@ -87,6 +87,7 @@ theme_init(const char* const theme_name) g_hash_table_insert(defaults, strdup("main.help.header"), strdup("default")); g_hash_table_insert(defaults, strdup("main.trackbar"), strdup("default")); g_hash_table_insert(defaults, strdup("error"), strdup("red")); + g_hash_table_insert(defaults, strdup("warning"), strdup("yellow")); g_hash_table_insert(defaults, strdup("incoming"), strdup("yellow")); g_hash_table_insert(defaults, strdup("mention"), strdup("yellow")); g_hash_table_insert(defaults, strdup("trigger"), strdup("yellow")); @@ -703,6 +704,9 @@ theme_attrs(theme_item_t attrs) case THEME_ERROR: _theme_prep_fgnd("error", lookup_str, &bold); break; + case THEME_WARNING: + _theme_prep_fgnd("warning", lookup_str, &bold); + break; case THEME_INCOMING: _theme_prep_fgnd("incoming", lookup_str, &bold); break; diff --git a/src/config/theme.h b/src/config/theme.h index 1d459ed7..bba5ec28 100644 --- a/src/config/theme.h +++ b/src/config/theme.h @@ -23,6 +23,7 @@ typedef enum { THEME_SPLASH, THEME_HELP_HEADER, THEME_ERROR, + THEME_WARNING, THEME_INCOMING, THEME_MENTION, THEME_TRIGGER, diff --git a/src/ui/console.c b/src/ui/console.c index 02a8b2a4..6dc4fad2 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -155,6 +155,20 @@ cons_show_error(const char* const msg, ...) cons_alert(NULL); } +void +cons_show_warning(const char* const msg, ...) +{ + va_list arg; + va_start(arg, msg); + GString* fmt_msg = g_string_new(NULL); + g_string_vprintf(fmt_msg, msg, arg); + win_println(wins_get_console(), THEME_WARNING, "-", "Warning: %s", fmt_msg->str); + g_string_free(fmt_msg, TRUE); + va_end(arg); + + cons_alert(NULL); +} + void cons_show_tlscert_summary(const TLSCertificate* cert) { diff --git a/src/ui/ui.h b/src/ui/ui.h index bdcdb406..cbe64329 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -252,6 +252,8 @@ G_GNUC_PRINTF(1, 2) void cons_debug(const char* const msg, ...); G_GNUC_PRINTF(1, 2) void cons_show_error(const char* const cmd, ...); +G_GNUC_PRINTF(1, 2) +void cons_show_warning(const char* const msg, ...); void cons_show_contacts(GSList* list); void cons_show_roster(GSList* list); void cons_show_roster_group(const char* const group, GSList* list); diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c index 7ac85dbe..80cf6ae9 100644 --- a/tests/unittests/ui/stub_ui.c +++ b/tests/unittests/ui/stub_ui.c @@ -49,6 +49,18 @@ expect_any_cons_show_error(void) expect_any(cons_show_error, output); } +void +expect_cons_show_warning(char* expected) +{ + expect_string(cons_show_warning, output, expected); +} + +void +expect_any_cons_show_warning(void) +{ + expect_any(cons_show_warning, output); +} + void expect_win_println(char* message) { @@ -845,6 +857,16 @@ cons_show_error(const char* const cmd, ...) va_end(args); } +void +cons_show_warning(const char* const msg, ...) +{ + va_list args; + va_start(args, msg); + vsnprintf(output, sizeof(output), msg, args); + check_expected(output); + va_end(args); +} + void cons_show_contacts(GSList* list) { diff --git a/tests/unittests/ui/stub_ui.h b/tests/unittests/ui/stub_ui.h index 21ea5bbf..4a9e4523 100644 --- a/tests/unittests/ui/stub_ui.h +++ b/tests/unittests/ui/stub_ui.h @@ -10,4 +10,6 @@ void expect_cons_show(char* expected); void expect_any_cons_show(void); void expect_cons_show_error(char* expected); void expect_any_cons_show_error(void); +void expect_cons_show_warning(char* expected); +void expect_any_cons_show_warning(void); void expect_win_println(char* message);