.. | .. |
---|
1 | 1 | // SPDX-License-Identifier: GPL-2.0 |
---|
2 | | -#include "../../util/util.h" |
---|
3 | 2 | #include <signal.h> |
---|
4 | 3 | #include <stdbool.h> |
---|
5 | 4 | #include <string.h> |
---|
| 5 | +#include <stdlib.h> |
---|
6 | 6 | #include <sys/ttydefaults.h> |
---|
7 | 7 | |
---|
8 | | -#include "../../util/cache.h" |
---|
9 | | -#include "../../util/debug.h" |
---|
10 | 8 | #include "../browser.h" |
---|
11 | 9 | #include "../keysyms.h" |
---|
12 | 10 | #include "../helpline.h" |
---|
.. | .. |
---|
25 | 23 | ui_browser__write_nstring(browser, *arg, browser->width); |
---|
26 | 24 | } |
---|
27 | 25 | |
---|
28 | | -static int popup_menu__run(struct ui_browser *menu) |
---|
| 26 | +static int popup_menu__run(struct ui_browser *menu, int *keyp) |
---|
29 | 27 | { |
---|
30 | 28 | int key; |
---|
31 | 29 | |
---|
.. | .. |
---|
47 | 45 | key = -1; |
---|
48 | 46 | break; |
---|
49 | 47 | default: |
---|
| 48 | + if (keyp) { |
---|
| 49 | + *keyp = key; |
---|
| 50 | + key = menu->nr_entries; |
---|
| 51 | + break; |
---|
| 52 | + } |
---|
50 | 53 | continue; |
---|
51 | 54 | } |
---|
52 | 55 | |
---|
.. | .. |
---|
57 | 60 | return key; |
---|
58 | 61 | } |
---|
59 | 62 | |
---|
60 | | -int ui__popup_menu(int argc, char * const argv[]) |
---|
| 63 | +int ui__popup_menu(int argc, char * const argv[], int *keyp) |
---|
61 | 64 | { |
---|
62 | 65 | struct ui_browser menu = { |
---|
63 | 66 | .entries = (void *)argv, |
---|
.. | .. |
---|
66 | 69 | .write = ui_browser__argv_write, |
---|
67 | 70 | .nr_entries = argc, |
---|
68 | 71 | }; |
---|
69 | | - |
---|
70 | | - return popup_menu__run(&menu); |
---|
| 72 | + return popup_menu__run(&menu, keyp); |
---|
71 | 73 | } |
---|
72 | 74 | |
---|
73 | 75 | int ui_browser__input_window(const char *title, const char *text, char *input, |
---|
.. | .. |
---|
162 | 164 | return key; |
---|
163 | 165 | } |
---|
164 | 166 | |
---|
165 | | -int ui__question_window(const char *title, const char *text, |
---|
166 | | - const char *exit_msg, int delay_secs) |
---|
| 167 | +void __ui__info_window(const char *title, const char *text, const char *exit_msg) |
---|
167 | 168 | { |
---|
168 | 169 | int x, y; |
---|
169 | 170 | int max_len = 0, nr_lines = 0; |
---|
.. | .. |
---|
185 | 186 | t = sep + 1; |
---|
186 | 187 | } |
---|
187 | 188 | |
---|
188 | | - pthread_mutex_lock(&ui__lock); |
---|
189 | | - |
---|
190 | 189 | max_len += 2; |
---|
191 | | - nr_lines += 4; |
---|
| 190 | + nr_lines += 2; |
---|
| 191 | + if (exit_msg) |
---|
| 192 | + nr_lines += 2; |
---|
192 | 193 | y = SLtt_Screen_Rows / 2 - nr_lines / 2, |
---|
193 | 194 | x = SLtt_Screen_Cols / 2 - max_len / 2; |
---|
194 | 195 | |
---|
.. | .. |
---|
199 | 200 | SLsmg_write_string((char *)title); |
---|
200 | 201 | } |
---|
201 | 202 | SLsmg_gotorc(++y, x); |
---|
202 | | - nr_lines -= 2; |
---|
| 203 | + if (exit_msg) |
---|
| 204 | + nr_lines -= 2; |
---|
203 | 205 | max_len -= 2; |
---|
204 | 206 | SLsmg_write_wrapped_string((unsigned char *)text, y, x, |
---|
205 | 207 | nr_lines, max_len, 1); |
---|
206 | | - SLsmg_gotorc(y + nr_lines - 2, x); |
---|
207 | | - SLsmg_write_nstring((char *)" ", max_len); |
---|
208 | | - SLsmg_gotorc(y + nr_lines - 1, x); |
---|
209 | | - SLsmg_write_nstring((char *)exit_msg, max_len); |
---|
| 208 | + if (exit_msg) { |
---|
| 209 | + SLsmg_gotorc(y + nr_lines - 2, x); |
---|
| 210 | + SLsmg_write_nstring((char *)" ", max_len); |
---|
| 211 | + SLsmg_gotorc(y + nr_lines - 1, x); |
---|
| 212 | + SLsmg_write_nstring((char *)exit_msg, max_len); |
---|
| 213 | + } |
---|
| 214 | +} |
---|
| 215 | + |
---|
| 216 | +void ui__info_window(const char *title, const char *text) |
---|
| 217 | +{ |
---|
| 218 | + pthread_mutex_lock(&ui__lock); |
---|
| 219 | + __ui__info_window(title, text, NULL); |
---|
210 | 220 | SLsmg_refresh(); |
---|
211 | | - |
---|
212 | 221 | pthread_mutex_unlock(&ui__lock); |
---|
| 222 | +} |
---|
213 | 223 | |
---|
| 224 | +int ui__question_window(const char *title, const char *text, |
---|
| 225 | + const char *exit_msg, int delay_secs) |
---|
| 226 | +{ |
---|
| 227 | + pthread_mutex_lock(&ui__lock); |
---|
| 228 | + __ui__info_window(title, text, exit_msg); |
---|
| 229 | + SLsmg_refresh(); |
---|
| 230 | + pthread_mutex_unlock(&ui__lock); |
---|
214 | 231 | return ui__getch(delay_secs); |
---|
215 | 232 | } |
---|
216 | 233 | |
---|