Skip to content

Commit 1d1e2ca

Browse files
gobenjimichal42
authored andcommitted
menuconfig: Extend dialog_textbox so that it can return to a scrolled position
We can now display other UI elements (menus) "on top" of a textbox and then seemingly come back to it in the same state it was left. Signed-off-by: Benjamin Poirier <bpoirier@suse.de> Signed-off-by: Michal Marek <mmarek@suse.cz>
1 parent 537ddae commit 1d1e2ca

3 files changed

Lines changed: 28 additions & 6 deletions

File tree

‎scripts/kconfig/lxdialog/dialog.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ int dialog_yesno(const char *title, const char *prompt, int height, int width);
211211
int dialog_msgbox(const char *title, const char *prompt, int height,
212212
int width, int pause);
213213
int dialog_textbox(const char *title, const char *file, int height, int width,
214-
int *keys);
214+
int *keys, int *_vscroll, int *_hscroll);
215215
int dialog_menu(const char *title, const char *prompt,
216216
const void *selected, int *s_scroll);
217217
int dialog_checklist(const char *title, const char *prompt, int height,

‎scripts/kconfig/lxdialog/textbox.c‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ static void refresh_text_box(WINDOW *dialog, WINDOW *box, int boxh, int boxw,
5151
* keys is a null-terminated array
5252
*/
5353
int dialog_textbox(const char *title, const char *tbuf, int initial_height,
54-
int initial_width, int *keys)
54+
int initial_width, int *keys, int *_vscroll, int *_hscroll)
5555
{
5656
int i, x, y, cur_x, cur_y, key = 0;
5757
int height, width, boxh, boxw;
@@ -65,6 +65,15 @@ int dialog_textbox(const char *title, const char *tbuf, int initial_height,
6565
buf = tbuf;
6666
page = buf; /* page is pointer to start of page to be displayed */
6767

68+
if (_vscroll && *_vscroll) {
69+
begin_reached = 0;
70+
71+
for (i = 0; i < *_vscroll; i++)
72+
get_line();
73+
}
74+
if (_hscroll)
75+
hscroll = *_hscroll;
76+
6877
do_resize:
6978
getmaxyx(stdscr, height, width);
7079
if (height < 8 || width < 8)
@@ -275,6 +284,19 @@ int dialog_textbox(const char *title, const char *tbuf, int initial_height,
275284
}
276285
delwin(box);
277286
delwin(dialog);
287+
if (_vscroll) {
288+
const char *s;
289+
290+
s = buf;
291+
*_vscroll = 0;
292+
back_lines(page_length);
293+
while (s < page && (s = strchr(s, '\n'))) {
294+
(*_vscroll)++;
295+
s++;
296+
}
297+
}
298+
if (_hscroll)
299+
*_hscroll = hscroll;
278300
return key;
279301
}
280302

‎scripts/kconfig/mconf.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ static void conf_string(struct menu *menu);
280280
static void conf_load(void);
281281
static void conf_save(void);
282282
static int show_textbox_ext(const char *title, const char *text, int r, int c,
283-
int *keys);
283+
int *keys, int *vscroll, int *hscroll);
284284
static void show_textbox(const char *title, const char *text, int r, int c);
285285
static void show_helptext(const char *title, const char *text);
286286
static void show_help(struct menu *menu);
@@ -621,15 +621,15 @@ static void conf(struct menu *menu)
621621
}
622622

623623
static int show_textbox_ext(const char *title, const char *text, int r, int c,
624-
int *keys)
624+
int *keys, int *vscroll, int *hscroll)
625625
{
626626
dialog_clear();
627-
return dialog_textbox(title, text, r, c, keys);
627+
return dialog_textbox(title, text, r, c, keys, vscroll, hscroll);
628628
}
629629

630630
static void show_textbox(const char *title, const char *text, int r, int c)
631631
{
632-
show_textbox_ext(title, text, r, c, (int []) {0});
632+
show_textbox_ext(title, text, r, c, (int []) {0}, NULL, NULL);
633633
}
634634

635635
static void show_helptext(const char *title, const char *text)

0 commit comments

Comments
 (0)