aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheJackiMonster <thejackimonster@gmail.com>2022-03-30 01:48:38 +0200
committerTheJackiMonster <thejackimonster@gmail.com>2022-03-30 01:48:38 +0200
commit831daf8ab424dc0581fd448432fe1365ad1f3e4a (patch)
tree3b6c57a05b8efa9011896b691cc272e56ba8063c
parent9d1af57afca13c07e5f3612512513c72dcc32956 (diff)
downloadmessenger-cli-831daf8ab424dc0581fd448432fe1365ad1f3e4a.tar.gz
messenger-cli-831daf8ab424dc0581fd448432fe1365ad1f3e4a.zip
Fixed accounts offset and selection handling
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r--src/chat.c12
-rw-r--r--src/ui/accounts.c53
2 files changed, 55 insertions, 10 deletions
diff --git a/src/chat.c b/src/chat.c
index 1b4bd48..c4b67b2 100644
--- a/src/chat.c
+++ b/src/chat.c
@@ -25,6 +25,9 @@
25#include "chat.h" 25#include "chat.h"
26 26
27#include "application.h" 27#include "application.h"
28#include "ui/accounts.h"
29
30UI_ACCOUNTS_Handle accounts;
28 31
29int lc = 0; 32int lc = 0;
30 33
@@ -33,7 +36,7 @@ _chat_message(UNUSED void *cls,
33 UNUSED struct GNUNET_CHAT_Context *context, 36 UNUSED struct GNUNET_CHAT_Context *context,
34 UNUSED const struct GNUNET_CHAT_Message *message) 37 UNUSED const struct GNUNET_CHAT_Message *message)
35{ 38{
36 //MESSENGER_Application *app = cls; 39 // MESSENGER_Application *app = cls;
37 40
38 enum GNUNET_CHAT_MessageKind kind = GNUNET_CHAT_message_get_kind( 41 enum GNUNET_CHAT_MessageKind kind = GNUNET_CHAT_message_get_kind(
39 message 42 message
@@ -46,9 +49,12 @@ _chat_message(UNUSED void *cls,
46} 49}
47 50
48static void 51static void
49_chat_refresh(UNUSED MESSENGER_Application *app) 52_chat_refresh(MESSENGER_Application *app)
50{ 53{
51 // TODO 54 // TODO
55
56 accounts.window = stdscr;
57 accounts_print(&accounts, app);
52} 58}
53 59
54static int 60static int
@@ -64,6 +70,8 @@ _chat_event(MESSENGER_Application *app,
64 move(lc++, 0); 70 move(lc++, 0);
65 printw("KEY %d", key); 71 printw("KEY %d", key);
66 72
73 accounts_event(&accounts, app, key);
74
67refresh: 75refresh:
68 _chat_refresh(app); 76 _chat_refresh(app);
69 return 0; 77 return 0;
diff --git a/src/ui/accounts.c b/src/ui/accounts.c
index 067e781..ef44d13 100644
--- a/src/ui/accounts.c
+++ b/src/ui/accounts.c
@@ -25,6 +25,8 @@
25#include "accounts.h" 25#include "accounts.h"
26#include "../application.h" 26#include "../application.h"
27 27
28#include <stdbool.h>
29
28int 30int
29_accounts_iterate(void *cls, 31_accounts_iterate(void *cls,
30 UNUSED const struct GNUNET_CHAT_Handle *handle, 32 UNUSED const struct GNUNET_CHAT_Handle *handle,
@@ -32,10 +34,14 @@ _accounts_iterate(void *cls,
32{ 34{
33 UI_ACCOUNTS_Handle *accounts = cls; 35 UI_ACCOUNTS_Handle *accounts = cls;
34 36
35 if (accounts->line_index++ == accounts->line_selected) 37 const bool selected = (accounts->line_selected == accounts->line_index);
38
39 accounts->line_index++;
40
41 if (selected)
36 accounts->selected = account; 42 accounts->selected = account;
37 43
38 return GNUNET_NO; 44 return GNUNET_YES;
39} 45}
40 46
41void 47void
@@ -64,6 +70,7 @@ accounts_event(UI_ACCOUNTS_Handle *accounts,
64 accounts->line_selected++; 70 accounts->line_selected++;
65 break; 71 break;
66 } 72 }
73 case '\n':
67 case KEY_ENTER: 74 case KEY_ENTER:
68 { 75 {
69 if (accounts->selected) 76 if (accounts->selected)
@@ -72,12 +79,29 @@ accounts_event(UI_ACCOUNTS_Handle *accounts,
72 break; 79 break;
73 } 80 }
74 default: 81 default:
75 if (accounts->line_selected < 0)
76 accounts->line_selected = 0;
77 else if (accounts->line_selected >= count)
78 accounts->line_selected = count - 1;
79 break; 82 break;
80 } 83 }
84
85 if (accounts->line_selected < 0)
86 accounts->line_selected = 0;
87 else if (accounts->line_selected >= count)
88 accounts->line_selected = count - 1;
89
90 if (!(accounts->window))
91 return;
92
93 const int height = getmaxy(accounts->window) - getbegy(accounts->window);
94 const int y = accounts->line_selected - accounts->line_offset;
95
96 if (y < 0)
97 accounts->line_offset += y;
98 else if (y + 1 >= height)
99 accounts->line_offset += y + 1 - height;
100
101 if (accounts->line_offset < 0)
102 accounts->line_offset = 0;
103 else if (accounts->line_offset >= count)
104 accounts->line_offset = count - 1;
81} 105}
82 106
83int 107int
@@ -87,9 +111,12 @@ _accounts_iterate_print(void *cls,
87{ 111{
88 UI_ACCOUNTS_Handle *accounts = cls; 112 UI_ACCOUNTS_Handle *accounts = cls;
89 113
114 const bool selected = (accounts->line_selected == accounts->line_index);
90 const int y = accounts->line_index - accounts->line_offset; 115 const int y = accounts->line_index - accounts->line_offset;
91 116
92 if (accounts->line_index++ < accounts->line_offset) 117 accounts->line_index++;
118
119 if (y < 0)
93 return GNUNET_YES; 120 return GNUNET_YES;
94 121
95 const int height = getmaxy(accounts->window) - getbegy(accounts->window); 122 const int height = getmaxy(accounts->window) - getbegy(accounts->window);
@@ -99,8 +126,15 @@ _accounts_iterate_print(void *cls,
99 126
100 const char *name = GNUNET_CHAT_account_get_name(account); 127 const char *name = GNUNET_CHAT_account_get_name(account);
101 128
102 move(y, 0); 129 const int attrs_select = A_BOLD;
130
131 if (selected) wattron(accounts->window, attrs_select);
132
133 wmove(accounts->window, y, 0);
103 wprintw(accounts->window, "%s", name); 134 wprintw(accounts->window, "%s", name);
135
136 if (selected) wattroff(accounts->window, attrs_select);
137
104 return GNUNET_YES; 138 return GNUNET_YES;
105} 139}
106 140
@@ -108,6 +142,9 @@ void
108accounts_print(UI_ACCOUNTS_Handle *accounts, 142accounts_print(UI_ACCOUNTS_Handle *accounts,
109 struct MESSENGER_Application *app) 143 struct MESSENGER_Application *app)
110{ 144{
145 if (!(accounts->window))
146 return;
147
111 accounts->line_index = 0; 148 accounts->line_index = 0;
112 149
113 GNUNET_CHAT_iterate_accounts( 150 GNUNET_CHAT_iterate_accounts(