Skip to content

Commit 95ac9b3

Browse files
gobenjimichal42
authored andcommitted
menuconfig: Assign jump keys per-page instead of globally
At the moment, keys 1-9 are assigned to the first 9 search results. This patch makes them assigned to the first 9 results per-page instead. We are much less likely to run out of keys that way. Signed-off-by: Benjamin Poirier <bpoirier@suse.de> Signed-off-by: Michal Marek <mmarek@suse.cz>
1 parent 1a374ae commit 95ac9b3

File tree

6 files changed

+149
-73
lines changed

6 files changed

+149
-73
lines changed

scripts/kconfig/expr.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ extern "C" {
1212

1313
#include <assert.h>
1414
#include <stdio.h>
15+
#include <sys/queue.h>
1516
#ifndef __cplusplus
1617
#include <stdbool.h>
1718
#endif
@@ -173,6 +174,14 @@ struct menu {
173174
#define MENU_CHANGED 0x0001
174175
#define MENU_ROOT 0x0002
175176

177+
struct jump_key {
178+
CIRCLEQ_ENTRY(jump_key) entries;
179+
size_t offset;
180+
struct menu *target;
181+
int index;
182+
};
183+
CIRCLEQ_HEAD(jk_head, jump_key);
184+
176185
#define JUMP_NB 9
177186

178187
extern struct file *file_list;

scripts/kconfig/lkc_proto.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ P(menu_get_root_menu,struct menu *,(struct menu *menu));
2121
P(menu_get_parent_menu,struct menu *,(struct menu *menu));
2222
P(menu_has_help,bool,(struct menu *menu));
2323
P(menu_get_help,const char *,(struct menu *menu));
24-
P(get_symbol_str, int, (struct gstr *r, struct symbol *sym, struct menu
25-
**jumps, int jump_nb));
26-
P(get_relations_str, struct gstr, (struct symbol **sym_arr, struct menu
27-
**jumps));
24+
P(get_symbol_str, void, (struct gstr *r, struct symbol *sym, struct jk_head
25+
*head));
26+
P(get_relations_str, struct gstr, (struct symbol **sym_arr, struct jk_head
27+
*head));
2828
P(menu_get_ext_help,void,(struct menu *menu, struct gstr *help));
2929

3030
/* symbol.c */

scripts/kconfig/lxdialog/dialog.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,13 @@ int first_alpha(const char *string, const char *exempt);
210210
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);
213-
int dialog_textbox(const char *title, const char *file, int height, int width,
214-
int *keys, int *_vscroll, int *_hscroll);
213+
214+
215+
typedef void (*update_text_fn)(char *buf, size_t start, size_t end, void
216+
*_data);
217+
int dialog_textbox(const char *title, char *tbuf, int initial_height,
218+
int initial_width, int *keys, int *_vscroll, int *_hscroll,
219+
update_text_fn update_text, void *data);
215220
int dialog_menu(const char *title, const char *prompt,
216221
const void *selected, int *s_scroll);
217222
int dialog_checklist(const char *title, const char *prompt, int height,

scripts/kconfig/lxdialog/textbox.c

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,25 @@
2222
#include "dialog.h"
2323

2424
static void back_lines(int n);
25-
static void print_page(WINDOW * win, int height, int width);
26-
static void print_line(WINDOW * win, int row, int width);
25+
static void print_page(WINDOW *win, int height, int width, update_text_fn
26+
update_text, void *data);
27+
static void print_line(WINDOW *win, int row, int width);
2728
static char *get_line(void);
2829
static void print_position(WINDOW * win);
2930

3031
static int hscroll;
3132
static int begin_reached, end_reached, page_length;
32-
static const char *buf;
33-
static const char *page;
33+
static char *buf;
34+
static char *page;
3435

3536
/*
3637
* refresh window content
3738
*/
3839
static void refresh_text_box(WINDOW *dialog, WINDOW *box, int boxh, int boxw,
39-
int cur_y, int cur_x)
40+
int cur_y, int cur_x, update_text_fn update_text,
41+
void *data)
4042
{
41-
print_page(box, boxh, boxw);
43+
print_page(box, boxh, boxw, update_text, data);
4244
print_position(dialog);
4345
wmove(dialog, cur_y, cur_x); /* Restore cursor position */
4446
wrefresh(dialog);
@@ -49,9 +51,11 @@ static void refresh_text_box(WINDOW *dialog, WINDOW *box, int boxh, int boxw,
4951
* Display text from a file in a dialog box.
5052
*
5153
* keys is a null-terminated array
54+
* update_text() may not add or remove any '\n' or '\0' in tbuf
5255
*/
53-
int dialog_textbox(const char *title, const char *tbuf, int initial_height,
54-
int initial_width, int *keys, int *_vscroll, int *_hscroll)
56+
int dialog_textbox(const char *title, char *tbuf, int initial_height,
57+
int initial_width, int *keys, int *_vscroll, int *_hscroll,
58+
update_text_fn update_text, void *data)
5559
{
5660
int i, x, y, cur_x, cur_y, key = 0;
5761
int height, width, boxh, boxw;
@@ -131,7 +135,8 @@ int dialog_textbox(const char *title, const char *tbuf, int initial_height,
131135

132136
/* Print first page of text */
133137
attr_clear(box, boxh, boxw, dlg.dialog.atr);
134-
refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x);
138+
refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x, update_text,
139+
data);
135140

136141
while (!done) {
137142
key = wgetch(dialog);
@@ -150,7 +155,8 @@ int dialog_textbox(const char *title, const char *tbuf, int initial_height,
150155
begin_reached = 1;
151156
page = buf;
152157
refresh_text_box(dialog, box, boxh, boxw,
153-
cur_y, cur_x);
158+
cur_y, cur_x, update_text,
159+
data);
154160
}
155161
break;
156162
case 'G': /* Last page */
@@ -160,8 +166,8 @@ int dialog_textbox(const char *title, const char *tbuf, int initial_height,
160166
/* point to last char in buf */
161167
page = buf + strlen(buf);
162168
back_lines(boxh);
163-
refresh_text_box(dialog, box, boxh, boxw,
164-
cur_y, cur_x);
169+
refresh_text_box(dialog, box, boxh, boxw, cur_y,
170+
cur_x, update_text, data);
165171
break;
166172
case 'K': /* Previous line */
167173
case 'k':
@@ -171,7 +177,7 @@ int dialog_textbox(const char *title, const char *tbuf, int initial_height,
171177

172178
back_lines(page_length + 1);
173179
refresh_text_box(dialog, box, boxh, boxw, cur_y,
174-
cur_x);
180+
cur_x, update_text, data);
175181
break;
176182
case 'B': /* Previous page */
177183
case 'b':
@@ -180,8 +186,8 @@ int dialog_textbox(const char *title, const char *tbuf, int initial_height,
180186
if (begin_reached)
181187
break;
182188
back_lines(page_length + boxh);
183-
refresh_text_box(dialog, box, boxh, boxw,
184-
cur_y, cur_x);
189+
refresh_text_box(dialog, box, boxh, boxw, cur_y,
190+
cur_x, update_text, data);
185191
break;
186192
case 'J': /* Next line */
187193
case 'j':
@@ -191,7 +197,7 @@ int dialog_textbox(const char *title, const char *tbuf, int initial_height,
191197

192198
back_lines(page_length - 1);
193199
refresh_text_box(dialog, box, boxh, boxw, cur_y,
194-
cur_x);
200+
cur_x, update_text, data);
195201
break;
196202
case KEY_NPAGE: /* Next page */
197203
case ' ':
@@ -200,8 +206,8 @@ int dialog_textbox(const char *title, const char *tbuf, int initial_height,
200206
break;
201207

202208
begin_reached = 0;
203-
refresh_text_box(dialog, box, boxh, boxw,
204-
cur_y, cur_x);
209+
refresh_text_box(dialog, box, boxh, boxw, cur_y,
210+
cur_x, update_text, data);
205211
break;
206212
case '0': /* Beginning of line */
207213
case 'H': /* Scroll left */
@@ -216,8 +222,8 @@ int dialog_textbox(const char *title, const char *tbuf, int initial_height,
216222
hscroll--;
217223
/* Reprint current page to scroll horizontally */
218224
back_lines(page_length);
219-
refresh_text_box(dialog, box, boxh, boxw,
220-
cur_y, cur_x);
225+
refresh_text_box(dialog, box, boxh, boxw, cur_y,
226+
cur_x, update_text, data);
221227
break;
222228
case 'L': /* Scroll right */
223229
case 'l':
@@ -227,8 +233,8 @@ int dialog_textbox(const char *title, const char *tbuf, int initial_height,
227233
hscroll++;
228234
/* Reprint current page to scroll horizontally */
229235
back_lines(page_length);
230-
refresh_text_box(dialog, box, boxh, boxw,
231-
cur_y, cur_x);
236+
refresh_text_box(dialog, box, boxh, boxw, cur_y,
237+
cur_x, update_text, data);
232238
break;
233239
case KEY_ESC:
234240
if (on_key_esc(dialog) == KEY_ESC)
@@ -301,12 +307,23 @@ static void back_lines(int n)
301307
}
302308

303309
/*
304-
* Print a new page of text. Called by dialog_textbox().
310+
* Print a new page of text.
305311
*/
306-
static void print_page(WINDOW * win, int height, int width)
312+
static void print_page(WINDOW *win, int height, int width, update_text_fn
313+
update_text, void *data)
307314
{
308315
int i, passed_end = 0;
309316

317+
if (update_text) {
318+
char *end;
319+
320+
for (i = 0; i < height; i++)
321+
get_line();
322+
end = page;
323+
back_lines(height);
324+
update_text(buf, page - buf, end - buf, data);
325+
}
326+
310327
page_length = 0;
311328
for (i = 0; i < height; i++) {
312329
print_line(win, i, width);
@@ -319,7 +336,7 @@ static void print_page(WINDOW * win, int height, int width)
319336
}
320337

321338
/*
322-
* Print a new line of text. Called by dialog_textbox() and print_page().
339+
* Print a new line of text.
323340
*/
324341
static void print_line(WINDOW * win, int row, int width)
325342
{

scripts/kconfig/mconf.c

Lines changed: 59 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,9 @@ static void conf_choice(struct menu *menu);
286286
static void conf_string(struct menu *menu);
287287
static void conf_load(void);
288288
static void conf_save(void);
289-
static int show_textbox_ext(const char *title, const char *text, int r, int c,
290-
int *keys, int *vscroll, int *hscroll);
289+
static int show_textbox_ext(const char *title, char *text, int r, int c,
290+
int *keys, int *vscroll, int *hscroll,
291+
update_text_fn update_text, void *data);
291292
static void show_textbox(const char *title, const char *text, int r, int c);
292293
static void show_helptext(const char *title, const char *text);
293294
static void show_help(struct menu *menu);
@@ -310,6 +311,39 @@ static void set_config_filename(const char *config_filename)
310311
}
311312

312313

314+
struct search_data {
315+
struct jk_head *head;
316+
struct menu **targets;
317+
int *keys;
318+
};
319+
320+
static void update_text(char *buf, size_t start, size_t end, void *_data)
321+
{
322+
struct search_data *data = _data;
323+
struct jump_key *pos;
324+
int k = 0;
325+
326+
CIRCLEQ_FOREACH(pos, data->head, entries) {
327+
if (pos->offset >= start && pos->offset < end) {
328+
char header[4];
329+
330+
if (k < JUMP_NB) {
331+
int key = '0' + (pos->index % JUMP_NB) + 1;
332+
333+
sprintf(header, "(%c)", key);
334+
data->keys[k] = key;
335+
data->targets[k] = pos->target;
336+
k++;
337+
} else {
338+
sprintf(header, " ");
339+
}
340+
341+
memcpy(buf + pos->offset, header, sizeof(header) - 1);
342+
}
343+
}
344+
data->keys[k] = 0;
345+
}
346+
313347
static void search_conf(void)
314348
{
315349
struct symbol **sym_arr;
@@ -341,18 +375,24 @@ static void search_conf(void)
341375

342376
sym_arr = sym_re_search(dialog_input);
343377
do {
344-
struct menu *jumps[JUMP_NB] = {0};
345-
int keys[JUMP_NB + 1] = {0}, i;
346-
347-
res = get_relations_str(sym_arr, jumps);
348-
for (i = 0; i < JUMP_NB && jumps[i]; i++)
349-
keys[i] = '1' + i;
350-
dres = show_textbox_ext(_("Search Results"), str_get(&res), 0,
351-
0, keys, &vscroll, &hscroll);
378+
struct jk_head head = CIRCLEQ_HEAD_INITIALIZER(head);
379+
struct menu *targets[JUMP_NB];
380+
int keys[JUMP_NB + 1], i;
381+
struct search_data data = {
382+
.head = &head,
383+
.targets = targets,
384+
.keys = keys,
385+
};
386+
387+
res = get_relations_str(sym_arr, &head);
388+
dres = show_textbox_ext(_("Search Results"), (char *)
389+
str_get(&res), 0, 0, keys, &vscroll,
390+
&hscroll, &update_text, (void *)
391+
&data);
352392
again = false;
353-
for (i = 0; i < JUMP_NB && jumps[i]; i++)
393+
for (i = 0; i < JUMP_NB && keys[i]; i++)
354394
if (dres == keys[i]) {
355-
conf(jumps[i]->parent, jumps[i]);
395+
conf(targets[i]->parent, targets[i]);
356396
again = true;
357397
}
358398
str_free(&res);
@@ -642,16 +682,19 @@ static void conf(struct menu *menu, struct menu *active_menu)
642682
}
643683
}
644684

645-
static int show_textbox_ext(const char *title, const char *text, int r, int c,
646-
int *keys, int *vscroll, int *hscroll)
685+
static int show_textbox_ext(const char *title, char *text, int r, int c, int
686+
*keys, int *vscroll, int *hscroll, update_text_fn
687+
update_text, void *data)
647688
{
648689
dialog_clear();
649-
return dialog_textbox(title, text, r, c, keys, vscroll, hscroll);
690+
return dialog_textbox(title, text, r, c, keys, vscroll, hscroll,
691+
update_text, data);
650692
}
651693

652694
static void show_textbox(const char *title, const char *text, int r, int c)
653695
{
654-
show_textbox_ext(title, text, r, c, (int []) {0}, NULL, NULL);
696+
show_textbox_ext(title, (char *) text, r, c, (int []) {0}, NULL, NULL,
697+
NULL, NULL);
655698
}
656699

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

0 commit comments

Comments
 (0)