1 #include "../../util/util.h"
5 #include <sys/ttydefaults.h>
7 #include "../../util/cache.h"
8 #include "../../util/debug.h"
9 #include "../browser.h"
10 #include "../keysyms.h"
11 #include "../helpline.h"
14 #include "../libslang.h"
16 static void ui_browser__argv_write(struct ui_browser *browser,
20 bool current_entry = ui_browser__is_current_entry(browser, row);
22 ui_browser__set_color(browser, current_entry ? HE_COLORSET_SELECTED :
24 slsmg_write_nstring(*arg, browser->width);
27 static int popup_menu__run(struct ui_browser *menu)
31 if (ui_browser__show(menu, " ", "ESC: exit, ENTER|->: Select option") < 0)
35 key = ui_browser__run(menu, 0);
55 ui_browser__hide(menu);
59 int ui__popup_menu(int argc, char * const argv[])
61 struct ui_browser menu = {
62 .entries = (void *)argv,
63 .refresh = ui_browser__argv_refresh,
64 .seek = ui_browser__argv_seek,
65 .write = ui_browser__argv_write,
69 return popup_menu__run(&menu);
72 int ui_browser__input_window(const char *title, const char *text, char *input,
73 const char *exit_msg, int delay_secs)
76 int max_len = 60, nr_lines = 0;
82 const char *sep = strchr(t, '\n');
85 sep = strchr(t, '\0');
95 pthread_mutex_lock(&ui__lock);
99 y = SLtt_Screen_Rows / 2 - nr_lines / 2;
100 x = SLtt_Screen_Cols / 2 - max_len / 2;
103 SLsmg_draw_box(y, x++, nr_lines, max_len);
105 SLsmg_gotorc(y, x + 1);
106 SLsmg_write_string((char *)title);
108 SLsmg_gotorc(++y, x);
111 SLsmg_write_wrapped_string((unsigned char *)text, y, x,
112 nr_lines, max_len, 1);
116 SLsmg_gotorc(y + len - 1, x);
117 SLsmg_write_nstring((char *)" ", max_len);
119 SLsmg_draw_box(y++, x + 1, 3, max_len - 2);
121 SLsmg_gotorc(y + 3, x);
122 SLsmg_write_nstring((char *)exit_msg, max_len);
125 pthread_mutex_unlock(&ui__lock);
129 key = ui__getch(delay_secs);
130 while (key != K_TIMER && key != K_ENTER && key != K_ESC) {
131 pthread_mutex_lock(&ui__lock);
133 if (key == K_BKSPC) {
135 pthread_mutex_unlock(&ui__lock);
138 SLsmg_gotorc(y, x + --len);
139 SLsmg_write_char(' ');
142 SLsmg_gotorc(y, x + len++);
143 SLsmg_write_char(key);
147 pthread_mutex_unlock(&ui__lock);
149 /* XXX more graceful overflow handling needed */
150 if (len == sizeof(buf) - 1) {
151 ui_helpline__push("maximum size of symbol name reached!");
156 key = ui__getch(delay_secs);
160 strncpy(input, buf, len+1);
164 int ui__question_window(const char *title, const char *text,
165 const char *exit_msg, int delay_secs)
168 int max_len = 0, nr_lines = 0;
173 const char *sep = strchr(t, '\n');
177 sep = strchr(t, '\0');
187 pthread_mutex_lock(&ui__lock);
191 y = SLtt_Screen_Rows / 2 - nr_lines / 2,
192 x = SLtt_Screen_Cols / 2 - max_len / 2;
195 SLsmg_draw_box(y, x++, nr_lines, max_len);
197 SLsmg_gotorc(y, x + 1);
198 SLsmg_write_string((char *)title);
200 SLsmg_gotorc(++y, x);
203 SLsmg_write_wrapped_string((unsigned char *)text, y, x,
204 nr_lines, max_len, 1);
205 SLsmg_gotorc(y + nr_lines - 2, x);
206 SLsmg_write_nstring((char *)" ", max_len);
207 SLsmg_gotorc(y + nr_lines - 1, x);
208 SLsmg_write_nstring((char *)exit_msg, max_len);
211 pthread_mutex_unlock(&ui__lock);
213 return ui__getch(delay_secs);
216 int ui__help_window(const char *text)
218 return ui__question_window("Help", text, "Press any key...", 0);
221 int ui__dialog_yesno(const char *msg)
223 return ui__question_window(NULL, msg, "Enter: Yes, ESC: No", 0);
226 static int __ui__warning(const char *title, const char *format, va_list args)
230 if (vasprintf(&s, format, args) > 0) {
233 key = ui__question_window(title, s, "Press any key...", 0);
238 fprintf(stderr, "%s\n", title);
239 vfprintf(stderr, format, args);
243 static int perf_tui__error(const char *format, va_list args)
245 return __ui__warning("Error:", format, args);
248 static int perf_tui__warning(const char *format, va_list args)
250 return __ui__warning("Warning:", format, args);
253 struct perf_error_ops perf_tui_eops = {
254 .error = perf_tui__error,
255 .warning = perf_tui__warning,