messenger-cli

Command-line user interface for GNUnet Messenger
Log | Files | Refs | README | LICENSE

commit b5766a658c8b6b74a54dba0aa9e870afaa38fb87
parent 14988419ae094810e47864afe9392b26355840db
Author: Jacki <jacki@thejackimonster.de>
Date:   Tue,  1 Jul 2025 19:31:14 +0200

Add unique colors to entries in application

Signed-off-by: Jacki <jacki@thejackimonster.de>

Diffstat:
Msrc/application.c | 5++++-
Msrc/application.h | 2+-
Msrc/ui/accounts.c | 17++++++++++++-----
Msrc/ui/chats.c | 20+++++++++++++-------
Msrc/ui/members.c | 6+++++-
Msrc/ui/messages.c | 6+++++-
Msrc/util.c | 37++++++++++++++++++++++++++++++++++++-
Msrc/util.h | 35++++++++++++++++++++++++++++++++++-
8 files changed, 110 insertions(+), 18 deletions(-)

diff --git a/src/application.c b/src/application.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2022--2024 GNUnet e.V. + Copyright (C) 2022--2025 GNUnet e.V. GNUnet is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published @@ -88,6 +88,9 @@ application_init(MESSENGER_Application *app, return; } + if (has_colors()) + util_init_unique_colors(); + application_refresh(app); noecho(); diff --git a/src/application.h b/src/application.h @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2022--2023 GNUnet e.V. + Copyright (C) 2022--2025 GNUnet e.V. GNUnet is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published diff --git a/src/ui/accounts.c b/src/ui/accounts.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2022--2024 GNUnet e.V. + Copyright (C) 2022--2025 GNUnet e.V. GNUnet is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published @@ -82,16 +82,23 @@ accounts_event(UI_ACCOUNTS_Handle *accounts, static int _accounts_print_entry(UI_ACCOUNTS_Handle *accounts, char type, - const char *text) + const char *text, + const void *data) { list_input_print_gnunet(accounts, 1); const int attrs_select = A_BOLD; if (selected) wattron(accounts->window, attrs_select); + else type = ' '; wmove(accounts->window, y, 0); - wprintw(accounts->window, "[%c] %s", selected? type : ' ', text); + + util_enable_unique_color(accounts->window, data); + + wprintw(accounts->window, "[%c] %s", type, text); + + util_disable_unique_color(accounts->window, data); if (selected) wattroff(accounts->window, attrs_select); @@ -105,7 +112,7 @@ _accounts_iterate_print(void *cls, { UI_ACCOUNTS_Handle *accounts = cls; const char *name = GNUNET_CHAT_account_get_name(account); - return _accounts_print_entry(accounts, 'x', name); + return _accounts_print_entry(accounts, 'x', name, account); } void @@ -130,5 +137,5 @@ accounts_print(UI_ACCOUNTS_Handle *accounts, accounts ); - _accounts_print_entry(accounts, '+', "Add account"); + _accounts_print_entry(accounts, '+', "Add account", NULL); } diff --git a/src/ui/chats.c b/src/ui/chats.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2022--2024 GNUnet e.V. + Copyright (C) 2022--2025 GNUnet e.V. GNUnet is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published @@ -147,21 +147,27 @@ static int _chats_print_entry(UI_CHATS_Handle *chats, char type, char chat_type, - const char *text) + const char *text, + const void *data) { list_input_print_gnunet(chats, 1); const int attrs_select = A_BOLD; if (selected) wattron(chats->window, attrs_select); + else type = ' '; wmove(chats->window, y, 0); + util_enable_unique_color(chats->window, data); + if (chat_type) wprintw(chats->window, "[%c][%c] %s", type, chat_type, text); else wprintw(chats->window, "[%c] %s", type, text); + util_disable_unique_color(chats->window, data); + if (selected) wattroff(chats->window, attrs_select); return GNUNET_YES; @@ -174,7 +180,7 @@ _chats_iterate_print_group(void *cls, { UI_CHATS_Handle *chats = cls; const char *name = GNUNET_CHAT_group_get_name(group); - return _chats_print_entry(chats, 'x', 'G', name); + return _chats_print_entry(chats, 'x', 'G', name, group); } enum GNUNET_GenericReturnValue @@ -184,7 +190,7 @@ _chats_iterate_print_contact(void *cls, { UI_CHATS_Handle *chats = cls; const char *name = GNUNET_CHAT_contact_get_name(contact); - return _chats_print_entry(chats, 'x', 'C', name); + return _chats_print_entry(chats, 'x', 'C', name, contact); } void @@ -225,7 +231,7 @@ chats_print(UI_CHATS_Handle *chats, chats ); - _chats_print_entry(chats, '+', '\0', "Add chat"); - _chats_print_entry(chats, '+', '\0', "Open lobby"); - _chats_print_entry(chats, '+', '\0', "Enter lobby"); + _chats_print_entry(chats, '+', '\0', "Add chat", NULL); + _chats_print_entry(chats, '+', '\0', "Open lobby", NULL); + _chats_print_entry(chats, '+', '\0', "Enter lobby", NULL); } diff --git a/src/ui/members.c b/src/ui/members.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2022 GNUnet e.V. + Copyright (C) 2022--2025 GNUnet e.V. GNUnet is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published @@ -87,11 +87,15 @@ _members_iterate_print(UI_MEMBERS_Handle *members, size_t key_len = key? strlen(key) : 0; + util_enable_unique_color(members->window, contact); + if (key_len > 4) wprintw(members->window, "[%s]: %s", key + (key_len - 4), name); else wprintw(members->window, "%s", name); + util_disable_unique_color(members->window, contact); + if (selected) wattroff(members->window, attrs_select); } diff --git a/src/ui/messages.c b/src/ui/messages.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2022--2024 GNUnet e.V. + Copyright (C) 2022--2025 GNUnet e.V. GNUnet is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published @@ -223,6 +223,8 @@ _messages_iterate_print(UI_MESSAGES_Handle *messages, wprintw(messages->window, " %s | ", time_buf); + util_enable_unique_color(messages->window, sender); + switch (kind) { case GNUNET_CHAT_KIND_JOIN: wprintw( @@ -285,6 +287,8 @@ _messages_iterate_print(UI_MESSAGES_Handle *messages, break; } + util_disable_unique_color(messages->window, sender); + if (selected) wattroff(messages->window, attrs_select); } diff --git a/src/util.c b/src/util.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2022--2024 GNUnet e.V. + Copyright (C) 2022--2025 GNUnet e.V. GNUnet is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published @@ -57,3 +57,38 @@ util_print_info(WINDOW *window, wmove(window, y, x); wprintw(window, "%s", info); } + +void +util_init_unique_colors() +{ + start_color(); + + init_pair(1, COLOR_RED, COLOR_BLACK); + init_pair(2, COLOR_GREEN, COLOR_BLACK); + init_pair(3, COLOR_YELLOW, COLOR_BLACK); + init_pair(4, COLOR_BLUE, COLOR_BLACK); + init_pair(5, COLOR_MAGENTA, COLOR_BLACK); + init_pair(6, COLOR_CYAN, COLOR_BLACK); +} + +void +util_enable_unique_color(WINDOW *window, + const void *data) +{ + if ((FALSE == has_colors()) || (!data)) + return; + + const int attr_color = COLOR_PAIR(1 + ((size_t) data) % UTIL_UNIQUE_COLORS); + wattron(window, attr_color); +} + +void +util_disable_unique_color(WINDOW *window, + const void *data) +{ + if ((FALSE == has_colors()) || (!data)) + return; + + const int attr_color = COLOR_PAIR(1 + ((size_t) data) % UTIL_UNIQUE_COLORS); + wattroff(window, attr_color); +} diff --git a/src/util.h b/src/util.h @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2022--2024 GNUnet e.V. + Copyright (C) 2022--2025 GNUnet e.V. GNUnet is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published @@ -34,6 +34,8 @@ #define UTIL_LOGO_ROWS 10 #define UTIL_LOGO_COLS 28 +#define UTIL_UNIQUE_COLORS 6 + /** * Prints the main logo of the application * onto a specified view. @@ -54,4 +56,35 @@ void util_print_info(WINDOW *window, const char *info); +/** + * Initializes the unique color attributes + * for using inside window views. + */ +void +util_init_unique_colors(void); + +/** + * Enables a color attribute representing + * a unique color for some specific data + * pointer. + * + * @param[in,out] window Window view + * @param[in] data Data pointer + */ +void +util_enable_unique_color(WINDOW *window, + const void *data); + +/** + * Disables a color attribute representing + * a unique color for some specific data + * pointer. + * + * @param[in,out] window Window view + * @param[in] data Data pointer + */ +void +util_disable_unique_color(WINDOW *window, + const void *data); + #endif /* UTIL_H_ */