Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

kconfig: nconf: Add search jump feature

Menuconfig has a feature where you can "press the key in the (#) prefix
to jump directly to that location. You will be returned to the current
search results after exiting this new menu."

This commit adds this feature to nconfig, with almost identical code.

Signed-off-by: Jesse Taube <Mr.Bossman075@gmail.com>
Acked-by: Randy Dunlap <rdunlap@infradead.org>
Tested-by: Randy Dunlap <rdunlap@infradead.org>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>

authored by

Jesse Taube and committed by
Masahiro Yamada
1ba67cd3 01e89a4a

+140 -15
+103 -10
scripts/kconfig/nconf.c
··· 220 220 "Location:\n" 221 221 " -> Bus options (PCI, PCMCIA, EISA, ISA)\n" 222 222 " -> PCI support (PCI [ = y])\n" 223 - " -> PCI access mode (<choice> [ = y])\n" 223 + "(1) -> PCI access mode (<choice> [ = y])\n" 224 224 "Selects: LIBCRC32\n" 225 225 "Selected by: BAR\n" 226 226 "-----------------------------------------------------------------\n" ··· 231 231 "o The 'Depends on:' line lists symbols that need to be defined for\n" 232 232 " this symbol to be visible and selectable in the menu.\n" 233 233 "o The 'Location:' lines tell, where in the menu structure this symbol\n" 234 - " is located. A location followed by a [ = y] indicates that this is\n" 235 - " a selectable menu item, and the current value is displayed inside\n" 236 - " brackets.\n" 234 + " is located.\n" 235 + " A location followed by a [ = y] indicates that this is\n" 236 + " a selectable menu item, and the current value is displayed inside\n" 237 + " brackets.\n" 238 + " Press the key in the (#) prefix to jump directly to that\n" 239 + " location. You will be returned to the current search results\n" 240 + " after exiting this new menu.\n" 237 241 "o The 'Selects:' line tells, what symbol will be automatically selected\n" 238 242 " if this symbol is selected (y or m).\n" 239 243 "o The 'Selected by' line tells what symbol has selected this symbol.\n" ··· 279 275 280 276 static char *dialog_input_result; 281 277 static int dialog_input_result_len; 278 + static int jump_key_char; 282 279 280 + static void selected_conf(struct menu *menu, struct menu *active_menu); 283 281 static void conf(struct menu *menu); 284 282 static void conf_choice(struct menu *menu); 285 283 static void conf_string(struct menu *menu); ··· 691 685 return 0; 692 686 } 693 687 688 + struct search_data { 689 + struct list_head *head; 690 + struct menu *target; 691 + }; 692 + 693 + static int next_jump_key(int key) 694 + { 695 + if (key < '1' || key > '9') 696 + return '1'; 697 + 698 + key++; 699 + 700 + if (key > '9') 701 + key = '1'; 702 + 703 + return key; 704 + } 705 + 706 + static int handle_search_keys(int key, size_t start, size_t end, void *_data) 707 + { 708 + struct search_data *data = _data; 709 + struct jump_key *pos; 710 + int index = 0; 711 + 712 + if (key < '1' || key > '9') 713 + return 0; 714 + 715 + list_for_each_entry(pos, data->head, entries) { 716 + index = next_jump_key(index); 717 + 718 + if (pos->offset < start) 719 + continue; 720 + 721 + if (pos->offset >= end) 722 + break; 723 + 724 + if (key == index) { 725 + data->target = pos->target; 726 + return 1; 727 + } 728 + } 729 + 730 + return 0; 731 + } 732 + 733 + int get_jump_key_char(void) 734 + { 735 + jump_key_char = next_jump_key(jump_key_char); 736 + 737 + return jump_key_char; 738 + } 694 739 695 740 static void search_conf(void) 696 741 { ··· 749 692 struct gstr res; 750 693 struct gstr title; 751 694 char *dialog_input; 752 - int dres; 695 + int dres, vscroll = 0, hscroll = 0; 696 + bool again; 753 697 754 698 title = str_new(); 755 699 str_printf( &title, "Enter (sub)string or regexp to search for " ··· 779 721 dialog_input += strlen(CONFIG_); 780 722 781 723 sym_arr = sym_re_search(dialog_input); 782 - res = get_relations_str(sym_arr, NULL); 724 + 725 + do { 726 + LIST_HEAD(head); 727 + struct search_data data = { 728 + .head = &head, 729 + .target = NULL, 730 + }; 731 + jump_key_char = 0; 732 + res = get_relations_str(sym_arr, &head); 733 + dres = show_scroll_win_ext(main_window, 734 + "Search Results", str_get(&res), 735 + &vscroll, &hscroll, 736 + handle_search_keys, &data); 737 + again = false; 738 + if (dres >= '1' && dres <= '9') { 739 + assert(data.target != NULL); 740 + selected_conf(data.target->parent, data.target); 741 + again = true; 742 + } 743 + str_free(&res); 744 + } while (again); 783 745 free(sym_arr); 784 - show_scroll_win(main_window, 785 - "Search Results", str_get(&res)); 786 - str_free(&res); 787 746 str_free(&title); 788 747 } 789 748 ··· 1138 1063 1139 1064 static void conf(struct menu *menu) 1140 1065 { 1066 + selected_conf(menu, NULL); 1067 + } 1068 + 1069 + static void selected_conf(struct menu *menu, struct menu *active_menu) 1070 + { 1141 1071 struct menu *submenu = NULL; 1142 1072 struct symbol *sym; 1143 - int res; 1073 + int i, res; 1144 1074 int current_index = 0; 1145 1075 int last_top_row = 0; 1146 1076 struct match_state match_state = { ··· 1160 1080 build_conf(menu); 1161 1081 if (!child_count) 1162 1082 break; 1083 + 1084 + if (active_menu != NULL) { 1085 + for (i = 0; i < items_num; i++) { 1086 + struct mitem *mcur; 1087 + 1088 + mcur = (struct mitem *) item_userptr(curses_menu_items[i]); 1089 + if ((struct menu *) mcur->usrptr == active_menu) { 1090 + current_index = i; 1091 + break; 1092 + } 1093 + } 1094 + active_menu = NULL; 1095 + } 1163 1096 1164 1097 show_menu(menu_get_prompt(menu), menu_instructions, 1165 1098 current_index, &last_top_row);
+32 -5
scripts/kconfig/nconf.gui.c
··· 497 497 refresh(); 498 498 } 499 499 500 - /* layman's scrollable window... */ 501 500 void show_scroll_win(WINDOW *main_window, 502 501 const char *title, 503 502 const char *text) 503 + { 504 + (void)show_scroll_win_ext(main_window, title, (char *)text, NULL, NULL, NULL, NULL); 505 + } 506 + 507 + /* layman's scrollable window... */ 508 + int show_scroll_win_ext(WINDOW *main_window, const char *title, char *text, 509 + int *vscroll, int *hscroll, 510 + extra_key_cb_fn extra_key_cb, void *data) 504 511 { 505 512 int res; 506 513 int total_lines = get_line_no(text); ··· 521 514 WINDOW *win; 522 515 WINDOW *pad; 523 516 PANEL *panel; 517 + bool done = false; 518 + 519 + if (hscroll) 520 + start_x = *hscroll; 521 + if (vscroll) 522 + start_y = *vscroll; 524 523 525 524 getmaxyx(stdscr, lines, columns); 526 525 ··· 562 549 panel = new_panel(win); 563 550 564 551 /* handle scrolling */ 565 - do { 566 - 552 + while (!done) { 567 553 copywin(pad, win, start_y, start_x, 2, 2, text_lines, 568 554 text_cols, 0); 569 555 print_in_middle(win, ··· 605 593 case 'l': 606 594 start_x++; 607 595 break; 596 + default: 597 + if (extra_key_cb) { 598 + size_t start = (get_line(text, start_y) - text); 599 + size_t end = (get_line(text, start_y + text_lines) - text); 600 + 601 + if (extra_key_cb(res, start, end, data)) { 602 + done = true; 603 + break; 604 + } 605 + } 608 606 } 609 - if (res == 10 || res == 27 || res == 'q' || 607 + if (res == 0 || res == 10 || res == 27 || res == 'q' || 610 608 res == KEY_F(F_HELP) || res == KEY_F(F_BACK) || 611 609 res == KEY_F(F_EXIT)) 612 610 break; ··· 628 606 start_x = 0; 629 607 if (start_x >= total_cols-text_cols) 630 608 start_x = total_cols-text_cols; 631 - } while (res); 609 + } 632 610 611 + if (hscroll) 612 + *hscroll = start_x; 613 + if (vscroll) 614 + *vscroll = start_y; 633 615 del_panel(panel); 634 616 delwin(win); 635 617 refresh_all_windows(main_window); 618 + return res; 636 619 }
+5
scripts/kconfig/nconf.h
··· 67 67 68 68 void set_colors(void); 69 69 70 + typedef int (*extra_key_cb_fn)(int, size_t, size_t, void *); 71 + 70 72 /* this changes the windows attributes !!! */ 71 73 void print_in_middle(WINDOW *win, int y, int width, const char *str, int attrs); 72 74 int get_line_length(const char *line); ··· 80 78 const char *title, const char *prompt, 81 79 const char *init, char **resultp, int *result_len); 82 80 void refresh_all_windows(WINDOW *main_window); 81 + int show_scroll_win_ext(WINDOW *main_window, const char *title, char *text, 82 + int *vscroll, int *hscroll, 83 + extra_key_cb_fn extra_key_cb, void *data); 83 84 void show_scroll_win(WINDOW *main_window, 84 85 const char *title, 85 86 const char *text);