5 #include <sys/ttydefaults.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');
97 y = SLtt_Screen_Rows / 2 - nr_lines / 2;
98 x = SLtt_Screen_Cols / 2 - max_len / 2;
101 SLsmg_draw_box(y, x++, nr_lines, max_len);
103 SLsmg_gotorc(y, x + 1);
104 SLsmg_write_string((char *)title);
106 SLsmg_gotorc(++y, x);
109 SLsmg_write_wrapped_string((unsigned char *)text, y, x,
110 nr_lines, max_len, 1);
113 SLsmg_draw_box(y - 1, x + 1, 3, max_len - 2);
115 SLsmg_gotorc(y + 3, x);
116 SLsmg_write_nstring((char *)exit_msg, max_len);
121 key = ui__getch(delay_secs);
122 while (key != K_TIMER && key != K_ENTER && key != K_ESC) {
123 if (key == K_BKSPC) {
126 SLsmg_gotorc(y, x + --len);
127 SLsmg_write_char(' ');
130 SLsmg_gotorc(y, x + len++);
131 SLsmg_write_char(key);
135 /* XXX more graceful overflow handling needed */
136 if (len == sizeof(buf) - 1) {
137 ui_helpline__push("maximum size of symbol name reached!");
142 key = ui__getch(delay_secs);
146 strncpy(input, buf, len+1);
150 int ui__question_window(const char *title, const char *text,
151 const char *exit_msg, int delay_secs)
154 int max_len = 0, nr_lines = 0;
159 const char *sep = strchr(t, '\n');
163 sep = strchr(t, '\0');
175 y = SLtt_Screen_Rows / 2 - nr_lines / 2,
176 x = SLtt_Screen_Cols / 2 - max_len / 2;
179 SLsmg_draw_box(y, x++, nr_lines, max_len);
181 SLsmg_gotorc(y, x + 1);
182 SLsmg_write_string((char *)title);
184 SLsmg_gotorc(++y, x);
187 SLsmg_write_wrapped_string((unsigned char *)text, y, x,
188 nr_lines, max_len, 1);
189 SLsmg_gotorc(y + nr_lines - 2, x);
190 SLsmg_write_nstring((char *)" ", max_len);
191 SLsmg_gotorc(y + nr_lines - 1, x);
192 SLsmg_write_nstring((char *)exit_msg, max_len);
194 return ui__getch(delay_secs);
197 int ui__help_window(const char *text)
199 return ui__question_window("Help", text, "Press any key...", 0);
202 int ui__dialog_yesno(const char *msg)
204 return ui__question_window(NULL, msg, "Enter: Yes, ESC: No", 0);
207 int __ui__warning(const char *title, const char *format, va_list args)
211 if (use_browser > 0 && vasprintf(&s, format, args) > 0) {
214 pthread_mutex_lock(&ui__lock);
215 key = ui__question_window(title, s, "Press any key...", 0);
216 pthread_mutex_unlock(&ui__lock);
221 fprintf(stderr, "%s:\n", title);
222 vfprintf(stderr, format, args);
226 int ui__warning(const char *format, ...)
231 va_start(args, format);
232 key = __ui__warning("Warning", format, args);
237 int ui__error(const char *format, ...)
242 va_start(args, format);
243 key = __ui__warning("Error", format, args);