aboutsummaryrefslogtreecommitdiff
path: root/src/ui/accounts.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/accounts.c')
-rw-r--r--src/ui/accounts.c53
1 files changed, 45 insertions, 8 deletions
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(