aboutsummaryrefslogtreecommitdiff
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)
downloadmessenger-cli-e30bd43c171922eab729d5c8e51f92d33bc8d9f5.tar.gz
messenger-cli-e30bd43c171922eab729d5c8e51f92d33bc8d9f5.zip
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 @@
25#include "application.h" 25#include "application.h"
26 26
27void 27void
28application_clear(MESSENGER_Application *app)
29{
30 app->accounts.window = NULL;
31 app->chats.window = NULL;
32 app->current.members.window = NULL;
33 app->current.messages.window = NULL;
34}
35
36void
28application_init(MESSENGER_Application *app, 37application_init(MESSENGER_Application *app,
29 int argc, 38 int argc,
30 char **argv) 39 char **argv)
@@ -45,7 +54,7 @@ application_init(MESSENGER_Application *app,
45 noecho(); 54 noecho();
46 55
47 keypad(app->window, TRUE); 56 keypad(app->window, TRUE);
48 timeout(10); 57 wtimeout(app->window, 10);
49} 58}
50 59
51static void 60static void
@@ -82,10 +91,16 @@ application_run(MESSENGER_Application *app)
82 members_clear(&(app->current.members)); 91 members_clear(&(app->current.members));
83 messages_clear(&(app->current.messages)); 92 messages_clear(&(app->current.messages));
84 93
94 application_clear(app);
95
85 if (app->window) 96 if (app->window)
86 delwin(app->window); 97 delwin(app->window);
87 98
88 endwin(); 99 if (ERR == endwin())
100 {
101 app->status = GNUNET_SYSERR;
102 return;
103 }
89} 104}
90 105
91int 106int
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
51} MESSENGER_Application; 51} MESSENGER_Application;
52 52
53void 53void
54application_clear(MESSENGER_Application *app);
55
56void
54application_init(MESSENGER_Application *app, 57application_init(MESSENGER_Application *app,
55 int argc, 58 int argc,
56 char **argv); 59 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)
33 app->chat.handle 33 app->chat.handle
34 ); 34 );
35 35
36 app->accounts.window = NULL; 36 application_clear(app);
37 app->chats.window = NULL;
38 app->current.members.window = NULL;
39 app->current.messages.window = NULL;
40 37
41 if (!account) 38 if (!account)
42 app->accounts.window = stdscr; 39 app->accounts.window = app->window;
43 else if (app->chat.context) 40 else if (app->chat.context)
44 { 41 {
45 if (app->chat.show_members) 42 if (app->chat.show_members)
46 app->current.members.window = stdscr; 43 app->current.members.window = app->window;
47 else 44 else
48 app->current.messages.window = stdscr; 45 app->current.messages.window = app->window;
49 } 46 }
50 else 47 else
51 app->chats.window = stdscr; 48 app->chats.window = app->window;
52 49
53 accounts_print(&(app->accounts), app); 50 accounts_print(&(app->accounts), app);
54 chats_print(&(app->chats), app); 51 chats_print(&(app->chats), app);
@@ -56,7 +53,7 @@ _chat_refresh(MESSENGER_Application *app)
56 messages_print(&(app->current.messages)); 53 messages_print(&(app->current.messages));
57} 54}
58 55
59static int 56static bool
60_chat_event(MESSENGER_Application *app, 57_chat_event(MESSENGER_Application *app,
61 int key) 58 int key)
62{ 59{
@@ -79,12 +76,12 @@ _chat_event(MESSENGER_Application *app,
79 else 76 else
80 chats_event(&(app->chats), app, key); 77 chats_event(&(app->chats), app, key);
81 78
82 if (GNUNET_YES == app->chat.quit) 79 if (app->chat.quit)
83 return 1; 80 return TRUE;
84 81
85refresh: 82refresh:
86 _chat_refresh(app); 83 _chat_refresh(app);
87 return 0; 84 return FALSE;
88} 85}
89 86
90static int 87static int
@@ -106,7 +103,10 @@ _chat_idle(void *cls)
106 MESSENGER_Application *app = cls; 103 MESSENGER_Application *app = cls;
107 app->chat.idle = NULL; 104 app->chat.idle = NULL;
108 105
109 if (0 != _chat_event(app, getch())) 106 if (app->chat.quit)
107 return;
108
109 if (_chat_event(app, wgetch(app->window)))
110 { 110 {
111 chat_stop(&(app->chat)); 111 chat_stop(&(app->chat));
112 return; 112 return;
@@ -115,7 +115,7 @@ _chat_idle(void *cls)
115 app->chat.idle = GNUNET_SCHEDULER_add_delayed_with_priority( 115 app->chat.idle = GNUNET_SCHEDULER_add_delayed_with_priority(
116 GNUNET_TIME_relative_multiply( 116 GNUNET_TIME_relative_multiply(
117 GNUNET_TIME_relative_get_millisecond_(), 117 GNUNET_TIME_relative_get_millisecond_(),
118 wgetdelay(stdscr) 118 wgetdelay(app->window)
119 ), 119 ),
120 GNUNET_SCHEDULER_PRIORITY_IDLE, 120 GNUNET_SCHEDULER_PRIORITY_IDLE,
121 &_chat_idle, 121 &_chat_idle,
@@ -141,7 +141,7 @@ chat_start(MESSENGER_Chat *chat,
141 app 141 app
142 ); 142 );
143 143
144 chat->quit = GNUNET_NO; 144 chat->quit = FALSE;
145} 145}
146 146
147void 147void
@@ -156,7 +156,7 @@ chat_stop(MESSENGER_Chat *chat)
156 GNUNET_CHAT_stop(chat->handle); 156 GNUNET_CHAT_stop(chat->handle);
157 chat->handle = NULL; 157 chat->handle = NULL;
158 158
159 chat->quit = GNUNET_YES; 159 chat->quit = TRUE;
160} 160}
161 161
162void 162void
@@ -177,7 +177,7 @@ chat_process_message(UNUSED MESSENGER_Chat *chat,
177 177
178 bool new_member = FALSE; 178 bool new_member = FALSE;
179 179
180 if (GNUNET_CHAT_KIND_LEAVE) 180 if (GNUNET_CHAT_KIND_LEAVE == kind)
181 members_remove(&(current->members), sender); 181 members_remove(&(current->members), sender);
182 else if (GNUNET_CHAT_KIND_JOIN == kind) 182 else if (GNUNET_CHAT_KIND_JOIN == kind)
183 new_member = members_add(&(current->members), sender); 183 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
39 struct GNUNET_SCHEDULER_Task *idle; 39 struct GNUNET_SCHEDULER_Task *idle;
40 40
41 bool show_members; 41 bool show_members;
42 int quit; 42 bool quit;
43} MESSENGER_Chat; 43} MESSENGER_Chat;
44 44
45void 45void
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)
32 application_init(&app, argc, argv); 32 application_init(&app, argc, argv);
33 application_run(&app); 33 application_run(&app);
34 34
35 return application_status(&app); 35 const int status = application_status(&app);
36
37 exit_curses(status);
38 return status;
36} 39}
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,
69 case 27: 69 case 27:
70 case KEY_EXIT: 70 case KEY_EXIT:
71 { 71 {
72 app->chat.quit = GNUNET_YES; 72 app->chat.quit = TRUE;
73 break; 73 break;
74 } 74 }
75 case KEY_UP: 75 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,
124 wmove(members->window, y, 0); 124 wmove(members->window, y, 0);
125 125
126 const char *name = GNUNET_CHAT_contact_get_name(contact); 126 const char *name = GNUNET_CHAT_contact_get_name(contact);
127 wprintw(members->window, "%s", name); 127 const char *key = GNUNET_CHAT_contact_get_key(contact);
128
129 size_t key_len = key? strlen(key) : 0;
130
131 if (key_len > 4)
132 wprintw(members->window, "[%s]: %s", key + (key_len - 4), name);
133 else
134 wprintw(members->window, "%s", name);
128 135
129 if (selected) wattroff(members->window, attrs_select); 136 if (selected) wattroff(members->window, attrs_select);
130} 137}