menuconfig: Extend dialog_textbox so that it can exit on arbitrary keypresses
The caller will be able to perform actions based on hotkeys in the displayed text. Signed-off-by: Benjamin Poirier <bpoirier@suse.de> Signed-off-by: Michal Marek <mmarek@suse.cz>
This commit is contained in:
parent
b9d29abd98
commit
537ddae75c
|
@ -210,7 +210,8 @@ int first_alpha(const char *string, const char *exempt);
|
||||||
int dialog_yesno(const char *title, const char *prompt, int height, int width);
|
int dialog_yesno(const char *title, const char *prompt, int height, int width);
|
||||||
int dialog_msgbox(const char *title, const char *prompt, int height,
|
int dialog_msgbox(const char *title, const char *prompt, int height,
|
||||||
int width, int pause);
|
int width, int pause);
|
||||||
int dialog_textbox(const char *title, const char *file, int height, int width);
|
int dialog_textbox(const char *title, const char *file, int height, int width,
|
||||||
|
int *keys);
|
||||||
int dialog_menu(const char *title, const char *prompt,
|
int dialog_menu(const char *title, const char *prompt,
|
||||||
const void *selected, int *s_scroll);
|
const void *selected, int *s_scroll);
|
||||||
int dialog_checklist(const char *title, const char *prompt, int height,
|
int dialog_checklist(const char *title, const char *prompt, int height,
|
||||||
|
|
|
@ -47,14 +47,16 @@ static void refresh_text_box(WINDOW *dialog, WINDOW *box, int boxh, int boxw,
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Display text from a file in a dialog box.
|
* Display text from a file in a dialog box.
|
||||||
|
*
|
||||||
|
* keys is a null-terminated array
|
||||||
*/
|
*/
|
||||||
int dialog_textbox(const char *title, const char *tbuf,
|
int dialog_textbox(const char *title, const char *tbuf, int initial_height,
|
||||||
int initial_height, int initial_width)
|
int initial_width, int *keys)
|
||||||
{
|
{
|
||||||
int i, x, y, cur_x, cur_y, key = 0;
|
int i, x, y, cur_x, cur_y, key = 0;
|
||||||
int height, width, boxh, boxw;
|
int height, width, boxh, boxw;
|
||||||
int passed_end;
|
|
||||||
WINDOW *dialog, *box;
|
WINDOW *dialog, *box;
|
||||||
|
bool done = false;
|
||||||
|
|
||||||
begin_reached = 1;
|
begin_reached = 1;
|
||||||
end_reached = 0;
|
end_reached = 0;
|
||||||
|
@ -122,7 +124,7 @@ do_resize:
|
||||||
attr_clear(box, boxh, boxw, dlg.dialog.atr);
|
attr_clear(box, boxh, boxw, dlg.dialog.atr);
|
||||||
refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x);
|
refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x);
|
||||||
|
|
||||||
while ((key != KEY_ESC) && (key != '\n')) {
|
while (!done) {
|
||||||
key = wgetch(dialog);
|
key = wgetch(dialog);
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case 'E': /* Exit */
|
case 'E': /* Exit */
|
||||||
|
@ -130,9 +132,9 @@ do_resize:
|
||||||
case 'X':
|
case 'X':
|
||||||
case 'x':
|
case 'x':
|
||||||
case 'q':
|
case 'q':
|
||||||
delwin(box);
|
case '\n':
|
||||||
delwin(dialog);
|
done = true;
|
||||||
return 0;
|
break;
|
||||||
case 'g': /* First page */
|
case 'g': /* First page */
|
||||||
case KEY_HOME:
|
case KEY_HOME:
|
||||||
if (!begin_reached) {
|
if (!begin_reached) {
|
||||||
|
@ -156,6 +158,8 @@ do_resize:
|
||||||
case 'k':
|
case 'k':
|
||||||
case KEY_UP:
|
case KEY_UP:
|
||||||
if (!begin_reached) {
|
if (!begin_reached) {
|
||||||
|
int passed_end = 0;
|
||||||
|
|
||||||
back_lines(page_length + 1);
|
back_lines(page_length + 1);
|
||||||
|
|
||||||
/* We don't call print_page() here but use
|
/* We don't call print_page() here but use
|
||||||
|
@ -169,7 +173,6 @@ do_resize:
|
||||||
wscrl(box, -1); /* Scroll box region down one line */
|
wscrl(box, -1); /* Scroll box region down one line */
|
||||||
scrollok(box, FALSE);
|
scrollok(box, FALSE);
|
||||||
page_length = 0;
|
page_length = 0;
|
||||||
passed_end = 0;
|
|
||||||
for (i = 0; i < boxh; i++) {
|
for (i = 0; i < boxh; i++) {
|
||||||
if (!i) {
|
if (!i) {
|
||||||
/* print first line of page */
|
/* print first line of page */
|
||||||
|
@ -252,7 +255,8 @@ do_resize:
|
||||||
cur_y, cur_x);
|
cur_y, cur_x);
|
||||||
break;
|
break;
|
||||||
case KEY_ESC:
|
case KEY_ESC:
|
||||||
key = on_key_esc(dialog);
|
if (on_key_esc(dialog) == KEY_ESC)
|
||||||
|
done = true;
|
||||||
break;
|
break;
|
||||||
case KEY_RESIZE:
|
case KEY_RESIZE:
|
||||||
back_lines(height);
|
back_lines(height);
|
||||||
|
@ -260,11 +264,18 @@ do_resize:
|
||||||
delwin(dialog);
|
delwin(dialog);
|
||||||
on_key_resize();
|
on_key_resize();
|
||||||
goto do_resize;
|
goto do_resize;
|
||||||
|
default:
|
||||||
|
for (i = 0; keys[i]; i++) {
|
||||||
|
if (key == keys[i]) {
|
||||||
|
done = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delwin(box);
|
delwin(box);
|
||||||
delwin(dialog);
|
delwin(dialog);
|
||||||
return key; /* ESC pressed */
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -279,6 +279,8 @@ static void conf_choice(struct menu *menu);
|
||||||
static void conf_string(struct menu *menu);
|
static void conf_string(struct menu *menu);
|
||||||
static void conf_load(void);
|
static void conf_load(void);
|
||||||
static void conf_save(void);
|
static void conf_save(void);
|
||||||
|
static int show_textbox_ext(const char *title, const char *text, int r, int c,
|
||||||
|
int *keys);
|
||||||
static void show_textbox(const char *title, const char *text, int r, int c);
|
static void show_textbox(const char *title, const char *text, int r, int c);
|
||||||
static void show_helptext(const char *title, const char *text);
|
static void show_helptext(const char *title, const char *text);
|
||||||
static void show_help(struct menu *menu);
|
static void show_help(struct menu *menu);
|
||||||
|
@ -618,10 +620,16 @@ static void conf(struct menu *menu)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void show_textbox(const char *title, const char *text, int r, int c)
|
static int show_textbox_ext(const char *title, const char *text, int r, int c,
|
||||||
|
int *keys)
|
||||||
{
|
{
|
||||||
dialog_clear();
|
dialog_clear();
|
||||||
dialog_textbox(title, text, r, c);
|
return dialog_textbox(title, text, r, c, keys);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void show_textbox(const char *title, const char *text, int r, int c)
|
||||||
|
{
|
||||||
|
show_textbox_ext(title, text, r, c, (int []) {0});
|
||||||
}
|
}
|
||||||
|
|
||||||
static void show_helptext(const char *title, const char *text)
|
static void show_helptext(const char *title, const char *text)
|
||||||
|
|
Loading…
Reference in New Issue