6 #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 static void newt_form__set_exit_keys(newtComponent self)
61 newtFormAddHotKey(self, NEWT_KEY_LEFT);
62 newtFormAddHotKey(self, NEWT_KEY_ESCAPE);
63 newtFormAddHotKey(self, 'Q');
64 newtFormAddHotKey(self, 'q');
65 newtFormAddHotKey(self, CTRL('c'));
68 static newtComponent newt_form__new(void)
70 newtComponent self = newtForm(NULL, NULL, 0);
72 newt_form__set_exit_keys(self);
76 int ui__popup_menu(int argc, char * const argv[])
78 struct ui_browser menu = {
79 .entries = (void *)argv,
80 .refresh = ui_browser__argv_refresh,
81 .seek = ui_browser__argv_seek,
82 .write = ui_browser__argv_write,
86 return popup_menu__run(&menu);
89 int ui__help_window(const char *text)
91 struct newtExitStruct es;
92 newtComponent tb, form = newt_form__new();
94 int max_len = 0, nr_lines = 0;
102 const char *sep = strchr(t, '\n');
106 sep = strchr(t, '\0');
116 tb = newtTextbox(0, 0, max_len, nr_lines, 0);
118 goto out_destroy_form;
120 newtTextboxSetText(tb, text);
121 newtFormAddComponent(form, tb);
122 newtCenteredWindow(max_len, nr_lines, NULL);
123 newtFormRun(form, &es);
127 newtFormDestroy(form);
131 static const char yes[] = "Yes", no[] = "No",
132 warning_str[] = "Warning!", ok[] = "Ok";
134 bool ui__dialog_yesno(const char *msg)
136 /* newtWinChoice should really be accepting const char pointers... */
137 return newtWinChoice(NULL, (char *)yes, (char *)no, (char *)msg) == 1;
140 void ui__warning(const char *format, ...)
144 va_start(args, format);
145 if (use_browser > 0) {
146 pthread_mutex_lock(&ui__lock);
147 newtWinMessagev((char *)warning_str, (char *)ok,
148 (char *)format, args);
149 pthread_mutex_unlock(&ui__lock);
151 vfprintf(stderr, format, args);