summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheJackiMonster <thejackimonster@gmail.com>2022-07-02 23:25:54 +0200
committerTheJackiMonster <thejackimonster@gmail.com>2022-07-02 23:25:54 +0200
commite30bd43c171922eab729d5c8e51f92d33bc8d9f5 (patch)
treeb3ae067feff4f6de40364af7b7923b5e2409f070
parent131b5671c30636ec2ebcd847ca5dc09113b70b89 (diff)
Fixed member list and added printing of keys
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r--src/application.c19
-rw-r--r--src/application.h3
-rw-r--r--src/chat.c34
-rw-r--r--src/chat.h2
-rw-r--r--src/messenger_cli.c5
-rw-r--r--src/ui/accounts.c2
-rw-r--r--src/ui/members.c9
7 files changed, 51 insertions, 23 deletions
diff --git a/src/application.c b/src/application.c
index f3b99c5..65bdd81 100644
--- 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
index ad8a7f5..1ad0c11 100644
--- 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
index 4bf7972..fac192e 100644
--- 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
index 8f3a309..8ce5f3e 100644
--- 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
index 1c68b9a..7127514 100644
--- 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
index 377bdc9..ced1d68 100644
--- 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
index c500d58..710c0d6 100644
--- 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);
}