messenger-cli

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

commit e30bd43c171922eab729d5c8e51f92d33bc8d9f5
parent 131b5671c30636ec2ebcd847ca5dc09113b70b89
Author: TheJackiMonster <thejackimonster@gmail.com>
Date:   Sat,  2 Jul 2022 23:25:54 +0200

Fixed member list and added printing of keys

Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>

Diffstat:
Msrc/application.c | 19+++++++++++++++++--
Msrc/application.h | 3+++
Msrc/chat.c | 34+++++++++++++++++-----------------
Msrc/chat.h | 2+-
Msrc/messenger_cli.c | 5++++-
Msrc/ui/accounts.c | 2+-
Msrc/ui/members.c | 9++++++++-
7 files changed, 51 insertions(+), 23 deletions(-)

diff --git a/src/application.c b/src/application.c @@ -25,6 +25,15 @@ #include "application.h" void +application_clear(MESSENGER_Application *app) +{ + app->accounts.window = NULL; + app->chats.window = NULL; + app->current.members.window = NULL; + app->current.messages.window = NULL; +} + +void application_init(MESSENGER_Application *app, int argc, char **argv) @@ -45,7 +54,7 @@ application_init(MESSENGER_Application *app, noecho(); keypad(app->window, TRUE); - timeout(10); + wtimeout(app->window, 10); } static void @@ -82,10 +91,16 @@ application_run(MESSENGER_Application *app) members_clear(&(app->current.members)); messages_clear(&(app->current.messages)); + application_clear(app); + if (app->window) delwin(app->window); - endwin(); + if (ERR == endwin()) + { + app->status = GNUNET_SYSERR; + return; + } } int diff --git a/src/application.h b/src/application.h @@ -51,6 +51,9 @@ typedef struct MESSENGER_Application } MESSENGER_Application; void +application_clear(MESSENGER_Application *app); + +void application_init(MESSENGER_Application *app, int argc, char **argv); diff --git a/src/chat.c b/src/chat.c @@ -33,22 +33,19 @@ _chat_refresh(MESSENGER_Application *app) app->chat.handle ); - app->accounts.window = NULL; - app->chats.window = NULL; - app->current.members.window = NULL; - app->current.messages.window = NULL; + application_clear(app); if (!account) - app->accounts.window = stdscr; + app->accounts.window = app->window; else if (app->chat.context) { if (app->chat.show_members) - app->current.members.window = stdscr; + app->current.members.window = app->window; else - app->current.messages.window = stdscr; + app->current.messages.window = app->window; } else - app->chats.window = stdscr; + app->chats.window = app->window; accounts_print(&(app->accounts), app); chats_print(&(app->chats), app); @@ -56,7 +53,7 @@ _chat_refresh(MESSENGER_Application *app) messages_print(&(app->current.messages)); } -static int +static bool _chat_event(MESSENGER_Application *app, int key) { @@ -79,12 +76,12 @@ _chat_event(MESSENGER_Application *app, else chats_event(&(app->chats), app, key); - if (GNUNET_YES == app->chat.quit) - return 1; + if (app->chat.quit) + return TRUE; refresh: _chat_refresh(app); - return 0; + return FALSE; } static int @@ -106,7 +103,10 @@ _chat_idle(void *cls) MESSENGER_Application *app = cls; app->chat.idle = NULL; - if (0 != _chat_event(app, getch())) + if (app->chat.quit) + return; + + if (_chat_event(app, wgetch(app->window))) { chat_stop(&(app->chat)); return; @@ -115,7 +115,7 @@ _chat_idle(void *cls) app->chat.idle = GNUNET_SCHEDULER_add_delayed_with_priority( GNUNET_TIME_relative_multiply( GNUNET_TIME_relative_get_millisecond_(), - wgetdelay(stdscr) + wgetdelay(app->window) ), GNUNET_SCHEDULER_PRIORITY_IDLE, &_chat_idle, @@ -141,7 +141,7 @@ chat_start(MESSENGER_Chat *chat, app ); - chat->quit = GNUNET_NO; + chat->quit = FALSE; } void @@ -156,7 +156,7 @@ chat_stop(MESSENGER_Chat *chat) GNUNET_CHAT_stop(chat->handle); chat->handle = NULL; - chat->quit = GNUNET_YES; + chat->quit = TRUE; } void @@ -177,7 +177,7 @@ chat_process_message(UNUSED MESSENGER_Chat *chat, bool new_member = FALSE; - if (GNUNET_CHAT_KIND_LEAVE) + if (GNUNET_CHAT_KIND_LEAVE == kind) members_remove(&(current->members), sender); else if (GNUNET_CHAT_KIND_JOIN == kind) new_member = members_add(&(current->members), sender); diff --git a/src/chat.h b/src/chat.h @@ -39,7 +39,7 @@ typedef struct MESSENGER_Chat struct GNUNET_SCHEDULER_Task *idle; bool show_members; - int quit; + bool quit; } MESSENGER_Chat; void diff --git a/src/messenger_cli.c b/src/messenger_cli.c @@ -32,5 +32,8 @@ main (int argc, char** argv) application_init(&app, argc, argv); application_run(&app); - return application_status(&app); + const int status = application_status(&app); + + exit_curses(status); + return status; } diff --git a/src/ui/accounts.c b/src/ui/accounts.c @@ -69,7 +69,7 @@ accounts_event(UI_ACCOUNTS_Handle *accounts, case 27: case KEY_EXIT: { - app->chat.quit = GNUNET_YES; + app->chat.quit = TRUE; break; } case KEY_UP: diff --git a/src/ui/members.c b/src/ui/members.c @@ -124,7 +124,14 @@ _members_iterate_print(UI_MEMBERS_Handle *members, wmove(members->window, y, 0); const char *name = GNUNET_CHAT_contact_get_name(contact); - wprintw(members->window, "%s", name); + const char *key = GNUNET_CHAT_contact_get_key(contact); + + size_t key_len = key? strlen(key) : 0; + + if (key_len > 4) + wprintw(members->window, "[%s]: %s", key + (key_len - 4), name); + else + wprintw(members->window, "%s", name); if (selected) wattroff(members->window, attrs_select); }