Direct use of lxdialog routines by menuconfig
PATCH 1/1 Direct use of lxdialog routines by menuconfig
Hello,
this patch (against 2.5.46) cleans up interaction between kconfig's mconf
(menuconfig frontend) and lxdialog. Its commandline interface (called imaginatively lxdialog) no longer exists, instead a .so is packed from the lxdialog objects and the relevant functions are called directly from mconf.
In practice, this means that drawing on the screen is done with _MUCH_ less
overhead now (we can still do better, maybe I will make few more patches in future; the difference won't be very big anymore though, I suppose), the screen updates are better optimalized as ncurses aren't reset everytime you display something, that also implies that the ugly screen flickering is done. As a cute side-effect, the dialogs are now rendered on the top of the menu or help panel.
Note that this patch depends on my previous patch (subj. "Possibility to
sanely link against off-directory .so"; if you can't see the mail anymore, fetch it from http://pasky.ji.cz/~pasky/dev/kernel/kbuild_smartso.patch - it's tiny). This patch also unfortunately conflicts with the singlemenu patch - I'm probably going to wait for what's going to be included first and then rediff the later ;-).
It appears to work fine for me, and the change should cause overall
improvement of the configuration process. Please test, comment, apply ;-).
scripts/kconfig/Makefile | 1 scripts/kconfig/mconf.c | 379 ++++++++++++++----------------------------- scripts/lxdialog/Makefile | 10 - scripts/lxdialog/checklist.c | 34 +-- scripts/lxdialog/dialog.h | 28 ++- scripts/lxdialog/lxdialog.c | 226 ------------------------- scripts/lxdialog/menubox.c | 59 ++---- scripts/lxdialog/textbox.c | 2 scripts/lxdialog/util.c | 18 +- 9 files changed, 213 insertions(+), 544 deletions(-)
Kind regards,
Petr Baudis
scripts/kconfig/Makefile +1 -0
@@ -14,6 +14,7 @@ host-progs := conf mconf qconf conf-objs := conf.o libkconfig.so mconf-objs := mconf.o libkconfig.so +mconf-linkobjs := ../lxdialog/liblxdialog.so qconf-objs := kconfig_load.o qconf-cxxobjs := qconf.o
scripts/kconfig/mconf.c +128 -251
617 lines not on this page · raw message
scripts/lxdialog/Makefile +6 -4
@@ -15,12 +15,14 @@ endif endif -host-progs := lxdialog +liblxdialog-objs := checklist.o menubox.o textbox.o yesno.o inputbox.o \ + util.o msgbox.o -lxdialog-objs := checklist.o menubox.o textbox.o yesno.o inputbox.o \ - util.o lxdialog.o msgbox.o +clean-files := liblxdialog.so -EXTRA_TARGETS := lxdialog +host-cshlib-extra := liblxdialog.so + +EXTRA_TARGETS := liblxdialog.so first_rule: ncurses
scripts/lxdialog/checklist.c +14 -20
@@ -118,7 +118,8 @@*/ int dialog_checklist (const char *title,const char *prompt,int height,int width, -int list_height,int item_no,const char *const * items,int flag) +int list_height,int item_no,struct dialog_list_item ** items, +int flag) {int i, x, y, box_x, box_y;
@@ -137,7 +138,7 @@/* Initializes status */ for (i =0 ; i < item_no; i++) { - status[i] = !strcasecmp (items[i *3 +2 ],"on" ); + status[i] = items[i]->selected;if (!choice && status[i]) choice = i; }
@@ -195,7 +196,7 @@/* Find length of longest item in order to center checklist */ check_x =0 ;for (i =0 ; i < item_no; i++) - check_x =MAX (check_x, +strlen (items[i *3 +1 ]) +4 ); + check_x =MAX (check_x, +strlen (items[i]->name) +4 ); check_x = (list_width - check_x) /2 ; item_x = check_x +4 ;
@@ -207,7 +208,7 @@/* Print the list */ for (i =0 ; i < max_choice; i++) { -print_item (list, items[(scroll+i) *3 +1 ], +print_item (list, items[scroll + i]->name, status[i+scroll], i, i == choice); }
@@ -224,7 +225,7 @@ key =wgetch (dialog);for (i =0 ; i < max_choice; i++) -if (toupper (key) ==toupper (items[(scroll+i)*3 +1 ][0 ])) +if (toupper (key) ==toupper (items[scroll + i]->name[0 ]))break ;
@@ -237,14 +238,14 @@/* Scroll list down */ if (list_height >1 ) {/* De-highlight current first item */ -print_item (list, items[scroll *3 +1 ], +print_item (list, items[scroll]->name, status[scroll],0 , FALSE);scrollok (list, TRUE);wscrl (list,-1 );scrollok (list, FALSE); } scroll--; -print_item (list, items[scroll *3 +1 ], +print_item (list, items[scroll]->name, status[scroll],0 , TRUE);wnoutrefresh (list);
@@ -263,7 +264,7 @@/* Scroll list up */ if (list_height >1 ) {/* De-highlight current last item before scrolling up */ -print_item (list, items[(scroll + max_choice -1 ) *3 +1 ], +print_item (list, items[scroll + max_choice -1 ]->name, status[scroll + max_choice -1 ], max_choice -1 , FALSE);scrollok (list, TRUE);
@@ -271,7 +272,7 @@scrollok (list, FALSE); } scroll++; -print_item (list, items[(scroll + max_choice -1 ) *3 +1 ], +print_item (list, items[scroll + max_choice -1 ]->name, status[scroll + max_choice -1 ], max_choice -1 , TRUE);wnoutrefresh (list);
@@ -287,11 +288,11 @@ }if (i != choice) {/* De-highlight current item */ -print_item (list, items[(scroll + choice) *3 +1 ], +print_item (list, items[scroll + choice]->name, status[scroll + choice], choice, FALSE);/* Highlight new item */ choice = i; -print_item (list, items[(scroll + choice) *3 +1 ], +print_item (list, items[scroll + choice]->name, status[scroll + choice], choice, TRUE);wnoutrefresh (list);wrefresh (dialog);
@@ -330,7 +331,7 @@ status[i] =0 ; status[scroll + choice] =1 ;for (i =0 ; i < max_choice; i++) -print_item (list, items[(scroll + i) *3 +1 ], +print_item (list, items[scroll + i]->name, status[scroll + i], i, i == choice); } }
@@ -338,14 +339,7 @@wrefresh (dialog);for (i =0 ; i < item_no; i++) { -if (status[i]) { -if (flag ==FLAG_CHECK ) { -fprintf (stderr,"\"%s\" " , items[i *3 ]); - }else { -fprintf (stderr,"%s" , items[i *3 ]); - } - - } + items[i]->selected = status[i]; } }delwin (dialog);
scripts/lxdialog/dialog.h +20 -8
@@ -26,6 +26,7 @@#include <stdlib.h> #include <string.h> +#ifdef CURSES_LOC #include CURSES_LOC /*
@@ -125,29 +126,35 @@* Global variables */ extern bool use_colors; -extern bool use_shadow;extern chtype attributes[]; +#endif + +extern char *backtitle; -extern const char *backtitle; +struct dialog_list_item { +char *name; +int namelen; +char *tag; +int selected;/* Set to 1 by dialog_*() function. */ +};/* * Function prototypes */ -extern void create_rc (const char *filename); -extern int parse_rc (void ); -void init_dialog (void );void end_dialog (void ); -void attr_clear (WINDOW * win,int height,int width,chtype attr);void dialog_clear (void ); +#ifdef CURSES_LOC +void attr_clear (WINDOW * win,int height,int width,chtype attr);void color_setup (void );void print_autowrap (WINDOW * win,const char *prompt,int width,int y,int x);void print_button (WINDOW * win,const char *label,int y,int x,int selected);void draw_box (WINDOW * win,int y,int x,int height,int width,chtype box,chtype border);void draw_shadow (WINDOW * win,int y,int x,int height,int width); +#endif int first_alpha (const char *string,const char *exempt);int dialog_yesno (const char *title,const char *prompt,int height,int width);
@@ -156,14 +163,17 @@int dialog_textbox (const char *title,const char *file,int height,int width);int dialog_menu (const char *title,const char *prompt,int height,int width,int menu_height,const char *choice,int item_no, -const char *const * items); +struct dialog_list_item ** items);int dialog_checklist (const char *title,const char *prompt,int height,int width,int list_height,int item_no, -const char *const * items,int flag); +struct dialog_list_item ** items,int flag);extern unsigned char dialog_input_result[];int dialog_inputbox (const char *title,const char *prompt,int height,int width,const char *init); +struct dialog_list_item *first_sel_item (int item_no, +struct dialog_list_item ** items); +/* * This is the base for fictitious keys, which activate * the buttons.
@@ -173,7 +183,9 @@* -- the lowercase are used to signal mouse-enter events (M_EVENT + 'o') * -- uppercase chars are used to invoke the button (M_EVENT + 'O') */ +#ifdef CURSES_LOC #define M_EVENT (KEY_MAX+1) +#endif /*
scripts/lxdialog/lxdialog.c +0 -226
226 lines not on this page · raw message
scripts/lxdialog/menubox.c +26 -33
148 lines not on this page · raw message
scripts/lxdialog/textbox.c +1 -1
@@ -317,7 +317,7 @@delwin (dialog);free (buf);close (fd); -return -1 ;/* ESC pressed */ +return 1 ;/* ESC pressed */ }/*
scripts/lxdialog/util.c +17 -1
@@ -25,7 +25,7 @@/* use colors by default? */ bool use_colors =1 ; -const char *backtitle =NULL ; +char *backtitle =NULL ;const char *dialog_result;
@@ -356,4 +356,20 @@ }return 0 ; +} + +/* +* Get the first selected item in the dialog_list_item list. +*/ +struct dialog_list_item * +first_sel_item (int item_no,struct dialog_list_item ** items) +{ +int i; + +for (i =0 ; i < item_no; i++) { +if (items[i]->selected) +return items[i]; + } + +return NULL ; }