messenger-cli

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

commit 0ad8b90c95b8cd6bf7e89bf04eb03628b09eb05b
parent b5766a658c8b6b74a54dba0aa9e870afaa38fb87
Author: Jacki <jacki@thejackimonster.de>
Date:   Tue,  1 Jul 2025 20:33:59 +0200

Improve dialogs with text prompts

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

Diffstat:
Msrc/application.h | 4++--
Msrc/ui/account_create_dialog.c | 15+++++++++++++--
Msrc/ui/chat_open_dialog.c | 15+++++++++++++--
Msrc/ui/lobby_create_dialog.c | 24++++++++++++++++--------
Msrc/ui/lobby_enter_dialog.c | 17++++++++++++++---
Msrc/util.c | 20++++++++++++++++++++
Msrc/util.h | 11+++++++++++
7 files changed, 89 insertions(+), 17 deletions(-)

diff --git a/src/application.h b/src/application.h @@ -79,8 +79,8 @@ application_clear(MESSENGER_Application *app); */ void application_init(MESSENGER_Application *app, - int argc, - char **argv); + int argc, + char **argv); /** * Refreshes the application handle freeing all temporary diff --git a/src/ui/account_create_dialog.c b/src/ui/account_create_dialog.c @@ -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 @@ -29,6 +29,7 @@ #include "text_input.h" #include "../application.h" +#include "../util.h" void account_create_dialog_event(UI_ACCOUNT_CREATE_DIALOG_Handle *create_dialog, @@ -67,8 +68,18 @@ account_create_dialog_print(UI_ACCOUNT_CREATE_DIALOG_Handle *create_dialog) werase(window); wmove(window, 0, 0); + util_print_prompt(window, "Enter name of the new account:"); + wmove(window, 1, 0); + + wprintw(window, "> "); + wmove(window, 1, 2); + + wattron(window, A_BOLD); + wprintw(window, "%s", create_dialog->name); - wmove(window, 0, create_dialog->name_pos); + wmove(window, 1, 2 + create_dialog->name_pos); + + wattroff(window, A_BOLD); wcursyncup(window); curs_set(1); diff --git a/src/ui/chat_open_dialog.c b/src/ui/chat_open_dialog.c @@ -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 @@ -29,6 +29,7 @@ #include "text_input.h" #include "../application.h" +#include "../util.h" void chat_open_dialog_event(UI_CHAT_OPEN_DIALOG_Handle *open_dialog, @@ -79,8 +80,18 @@ chat_open_dialog_print(UI_CHAT_OPEN_DIALOG_Handle *open_dialog) werase(window); wmove(window, 0, 0); + util_print_prompt(window, "Enter the topic of the public chat:"); + wmove(window, 1, 0); + + wprintw(window, "> "); + wmove(window, 1, 2); + + wattron(window, A_BOLD); + wprintw(window, "%s", open_dialog->topic); - wmove(window, 0, open_dialog->topic_pos); + wmove(window, 1, 2 + open_dialog->topic_pos); + + wattroff(window, A_BOLD); wcursyncup(window); curs_set(1); diff --git a/src/ui/lobby_create_dialog.c b/src/ui/lobby_create_dialog.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 @@ -30,7 +30,7 @@ void _lobby_open_with_uri(void *cls, - const struct GNUNET_CHAT_Uri *uri) + const struct GNUNET_CHAT_Uri *uri) { UI_LOBBY_CREATE_DIALOG_Handle *create_dialog = cls; @@ -42,8 +42,8 @@ _lobby_open_with_uri(void *cls, void lobby_create_dialog_event(UI_LOBBY_CREATE_DIALOG_Handle *create_dialog, - UNUSED struct MESSENGER_Application *app, - int key) + UNUSED struct MESSENGER_Application *app, + int key) { create_dialog->window = *(create_dialog->win); @@ -103,7 +103,7 @@ lobby_create_dialog_event(UI_LOBBY_CREATE_DIALOG_Handle *create_dialog, static void _lobby_iterate_print(UI_LOBBY_CREATE_DIALOG_Handle *create_dialog, - const char *label) + const char *label) { list_input_print(create_dialog, 1); @@ -111,8 +111,8 @@ _lobby_iterate_print(UI_LOBBY_CREATE_DIALOG_Handle *create_dialog, if (selected) wattron(create_dialog->window, attrs_select); - wmove(create_dialog->window, y, 0); - wprintw(create_dialog->window, "%s", label); + wmove(create_dialog->window, 1 + y, 0); + wprintw(create_dialog->window, "> %s", label); if (selected) wattroff(create_dialog->window, attrs_select); } @@ -128,10 +128,18 @@ lobby_create_dialog_print(UI_LOBBY_CREATE_DIALOG_Handle *create_dialog) list_input_reset(create_dialog); werase(create_dialog->window); + wmove(create_dialog->window, 0, 0); + if (create_dialog->uri) - _lobby_iterate_print(create_dialog, create_dialog->uri); + { + util_print_prompt(create_dialog->window, "This is the URI of the new lobby:"); + + _lobby_iterate_print(create_dialog, create_dialog->uri); + } else { + util_print_prompt(create_dialog->window, "Select the duration for the new lobby:"); + _lobby_iterate_print(create_dialog, "30 seconds"); _lobby_iterate_print(create_dialog, "5 minutes"); _lobby_iterate_print(create_dialog, "1 hour"); diff --git a/src/ui/lobby_enter_dialog.c b/src/ui/lobby_enter_dialog.c @@ -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 @@ -29,6 +29,7 @@ #include "text_input.h" #include "../application.h" +#include "../util.h" void lobby_enter_dialog_event(UI_LOBBY_ENTER_DIALOG_Handle *enter_dialog, @@ -86,15 +87,25 @@ lobby_enter_dialog_print(UI_LOBBY_ENTER_DIALOG_Handle *enter_dialog) werase(window); wmove(window, 0, 0); + util_print_prompt(window, "Enter the URI of the lobby:"); + wmove(window, 1, 0); + + wprintw(window, "> "); + wmove(window, 1, 2); + + wattron(window, A_BOLD); wprintw(window, "%s", enter_dialog->uri); + wattroff(window, A_BOLD); if (enter_dialog->error) { - wmove(window, 1, 0); + wmove(window, 2, 0); wprintw(window, "ERROR: %s", enter_dialog->error); } - wmove(window, 0, enter_dialog->uri_pos); + wattron(window, A_BOLD); + wmove(window, 1, 2 + enter_dialog->uri_pos); + wattroff(window, A_BOLD); wcursyncup(window); curs_set(1); diff --git a/src/util.c b/src/util.c @@ -59,6 +59,26 @@ util_print_info(WINDOW *window, } void +util_print_prompt(WINDOW *window, + const char *prompt) +{ + const int x = getcurx(window); + const int y = getcury(window); + int remaining = getmaxx(window) - x; + + if (strlen(prompt) < remaining) + wprintw(window, "%s", prompt); + else + { + for (int i = 0; i < remaining; i++) + { + wmove(window, y, x + i); + wprintw(window, "%c", prompt[i]); + } + } +} + +void util_init_unique_colors() { start_color(); diff --git a/src/util.h b/src/util.h @@ -57,6 +57,17 @@ util_print_info(WINDOW *window, const char *info); /** + * Print a prompt with properly cut text + * into a window view of the application. + * + * @param[in,out] window Window view + * @param[in] prompt Prompt text + */ +void +util_print_prompt(WINDOW *window, + const char *prompt); + +/** * Initializes the unique color attributes * for using inside window views. */