6 #include <sys/ttydefaults.h>
14 static void newt_form__set_exit_keys(newtComponent self)
16 newtFormAddHotKey(self, NEWT_KEY_LEFT);
17 newtFormAddHotKey(self, NEWT_KEY_ESCAPE);
18 newtFormAddHotKey(self, 'Q');
19 newtFormAddHotKey(self, 'q');
20 newtFormAddHotKey(self, CTRL('c'));
23 static newtComponent newt_form__new(void)
25 newtComponent self = newtForm(NULL, NULL, 0);
27 newt_form__set_exit_keys(self);
31 int ui__popup_menu(int argc, char * const argv[])
33 struct newtExitStruct es;
34 int i, rc = -1, max_len = 5;
35 newtComponent listbox, form = newt_form__new();
40 listbox = newtListbox(0, 0, argc, NEWT_FLAG_RETURNEXIT);
42 goto out_destroy_form;
44 newtFormAddComponent(form, listbox);
46 for (i = 0; i < argc; ++i) {
47 int len = strlen(argv[i]);
50 if (newtListboxAddEntry(listbox, argv[i], (void *)(long)i))
51 goto out_destroy_form;
54 newtCenteredWindow(max_len, argc, NULL);
55 newtFormRun(form, &es);
56 rc = newtListboxGetCurrent(listbox) - NULL;
57 if (es.reason == NEWT_EXIT_HOTKEY)
61 newtFormDestroy(form);
65 int ui__help_window(const char *text)
67 struct newtExitStruct es;
68 newtComponent tb, form = newt_form__new();
70 int max_len = 0, nr_lines = 0;
78 const char *sep = strchr(t, '\n');
82 sep = strchr(t, '\0');
92 tb = newtTextbox(0, 0, max_len, nr_lines, 0);
94 goto out_destroy_form;
96 newtTextboxSetText(tb, text);
97 newtFormAddComponent(form, tb);
98 newtCenteredWindow(max_len, nr_lines, NULL);
99 newtFormRun(form, &es);
103 newtFormDestroy(form);
107 static const char yes[] = "Yes", no[] = "No";
109 bool ui__dialog_yesno(const char *msg)
111 /* newtWinChoice should really be accepting const char pointers... */
112 return newtWinChoice(NULL, (char *)yes, (char *)no, (char *)msg) == 1;