6 #include <sys/ttydefaults.h>
14 newtComponent newt_form__new(void);
16 static void newt_form__set_exit_keys(newtComponent self)
18 newtFormAddHotKey(self, NEWT_KEY_LEFT);
19 newtFormAddHotKey(self, NEWT_KEY_ESCAPE);
20 newtFormAddHotKey(self, 'Q');
21 newtFormAddHotKey(self, 'q');
22 newtFormAddHotKey(self, CTRL('c'));
25 newtComponent newt_form__new(void)
27 newtComponent self = newtForm(NULL, NULL, 0);
29 newt_form__set_exit_keys(self);
33 int ui__popup_menu(int argc, char * const argv[])
35 struct newtExitStruct es;
36 int i, rc = -1, max_len = 5;
37 newtComponent listbox, form = newt_form__new();
42 listbox = newtListbox(0, 0, argc, NEWT_FLAG_RETURNEXIT);
44 goto out_destroy_form;
46 newtFormAddComponent(form, listbox);
48 for (i = 0; i < argc; ++i) {
49 int len = strlen(argv[i]);
52 if (newtListboxAddEntry(listbox, argv[i], (void *)(long)i))
53 goto out_destroy_form;
56 newtCenteredWindow(max_len, argc, NULL);
57 newtFormRun(form, &es);
58 rc = newtListboxGetCurrent(listbox) - NULL;
59 if (es.reason == NEWT_EXIT_HOTKEY)
63 newtFormDestroy(form);
67 int ui__help_window(const char *text)
69 struct newtExitStruct es;
70 newtComponent tb, form = newt_form__new();
72 int max_len = 0, nr_lines = 0;
80 const char *sep = strchr(t, '\n');
84 sep = strchr(t, '\0');
94 tb = newtTextbox(0, 0, max_len, nr_lines, 0);
96 goto out_destroy_form;
98 newtTextboxSetText(tb, text);
99 newtFormAddComponent(form, tb);
100 newtCenteredWindow(max_len, nr_lines, NULL);
101 newtFormRun(form, &es);
105 newtFormDestroy(form);
109 bool ui__dialog_yesno(const char *msg)
111 /* newtWinChoice should really be accepting const char pointers... */
112 char yes[] = "Yes", no[] = "No";
113 return newtWinChoice(NULL, yes, no, (char *)msg) == 1;