6 #include <sys/ttydefaults.h>
15 static void newt_form__set_exit_keys(newtComponent self
)
17 newtFormAddHotKey(self
, NEWT_KEY_LEFT
);
18 newtFormAddHotKey(self
, NEWT_KEY_ESCAPE
);
19 newtFormAddHotKey(self
, 'Q');
20 newtFormAddHotKey(self
, 'q');
21 newtFormAddHotKey(self
, CTRL('c'));
24 static newtComponent
newt_form__new(void)
26 newtComponent self
= newtForm(NULL
, NULL
, 0);
28 newt_form__set_exit_keys(self
);
32 int ui__popup_menu(int argc
, char * const argv
[])
34 struct newtExitStruct es
;
35 int i
, rc
= -1, max_len
= 5;
36 newtComponent listbox
, form
= newt_form__new();
41 listbox
= newtListbox(0, 0, argc
, NEWT_FLAG_RETURNEXIT
);
43 goto out_destroy_form
;
45 newtFormAddComponent(form
, listbox
);
47 for (i
= 0; i
< argc
; ++i
) {
48 int len
= strlen(argv
[i
]);
51 if (newtListboxAddEntry(listbox
, argv
[i
], (void *)(long)i
))
52 goto out_destroy_form
;
55 newtCenteredWindow(max_len
, argc
, NULL
);
56 newtFormRun(form
, &es
);
57 rc
= newtListboxGetCurrent(listbox
) - NULL
;
58 if (es
.reason
== NEWT_EXIT_HOTKEY
)
62 newtFormDestroy(form
);
66 int ui__help_window(const char *text
)
68 struct newtExitStruct es
;
69 newtComponent tb
, form
= newt_form__new();
71 int max_len
= 0, nr_lines
= 0;
79 const char *sep
= strchr(t
, '\n');
83 sep
= strchr(t
, '\0');
93 tb
= newtTextbox(0, 0, max_len
, nr_lines
, 0);
95 goto out_destroy_form
;
97 newtTextboxSetText(tb
, text
);
98 newtFormAddComponent(form
, tb
);
99 newtCenteredWindow(max_len
, nr_lines
, NULL
);
100 newtFormRun(form
, &es
);
104 newtFormDestroy(form
);
108 static const char yes
[] = "Yes", no
[] = "No",
109 warning_str
[] = "Warning!", ok
[] = "Ok";
111 bool ui__dialog_yesno(const char *msg
)
113 /* newtWinChoice should really be accepting const char pointers... */
114 return newtWinChoice(NULL
, (char *)yes
, (char *)no
, (char *)msg
) == 1;
117 void ui__warning(const char *format
, ...)
121 va_start(args
, format
);
122 if (use_browser
> 0) {
123 pthread_mutex_lock(&ui__lock
);
124 newtWinMessagev((char *)warning_str
, (char *)ok
,
125 (char *)format
, args
);
126 pthread_mutex_unlock(&ui__lock
);
128 vfprintf(stderr
, format
, args
);