kconfig/lxdialog: make lxdialof a built-in
Dedided to take another stamp on an old TODO item of making lxdialog a built-in. Following patch is first step to do so.
The patch makes it a built-in - but with two open issues that I yet have to address.
It is loosly based on a patch from Petr Baudis <[email protected]>:
http://www.uwsg.iu.edu/hypermail/linux/kernel/0211.2/1978.html
The diffstat tells a nice story even if you ignore the three deleted files. (lxdialog.c msgbox.c and lxdialog/Makefile).
I will not claim that the lxdialog files became readable by this but they are now less unreadable compared to before.
Comments welcome of course.
I will during the weekend try to address the resize issue. The double ESC ESC thing I dunno how to fix.
Sam
Quoted 1 line
From
34a1fd9aa089e814e8ba3e0a99ac9bd10d220032Mon Sep 17 00:00:00 2001
From: Sam Ravnborg <[email protected]>
Date: Thu, 27 Jul 2006 22:10:27 +0200
Subject: [PATCH] kconfig/menuconfig: lxdialog is now built-in
lxdialog was previously called as an external program causing screen to flicker when used. With this patch lxdialog is now built-in. It is loosly based om previous work by: Petr Baudis <[email protected]>
Following is a list of changes:
o Moved build of dialog routings to kconfig Makefile
o menubox + checklist uses a new item list to hold all menu items
o in util.c implmented helper function to deal with item list
o menubox now uses parameters to save scroll state (avoids temp file)
o textbox now get text to be displayed as parameter and not a file
o make sure to properly delete subwin's before main windows
o killed unused files: lxdialog.c msgbox.c
o modified return value for ESC to match direct calling
o in a few places the code has been adjusted to 80 char wide
o in textbox a small refactoring was made to make code remotely readable
o in mconf removed all unused stuff (functions/variables)
Following is a list of know short comings:
a) pressing ESC twice will be interpreted as two ESC presses
b) resize does not work. menuconfig needs to be restarted to be adjusted
--- scripts/kconfig/Makefile | 23 +- scripts/kconfig/lxdialog/Makefile | 21 - scripts/kconfig/lxdialog/checklist.c | 136 ++++------ scripts/kconfig/lxdialog/dialog.h | 50 +++- scripts/kconfig/lxdialog/inputbox.c | 2 scripts/kconfig/lxdialog/lxdialog.c | 204 -------------- scripts/kconfig/lxdialog/menubox.c | 95 +++---- scripts/kconfig/lxdialog/msgbox.c | 72 ----- scripts/kconfig/lxdialog/textbox.c | 298 +++++---------------- scripts/kconfig/lxdialog/util.c | 133 +++++++++ scripts/kconfig/lxdialog/yesno.c | 2 scripts/kconfig/mconf.c | 480 ++++++++++------------------------ 12 files changed, 499 insertions(+), 1017 deletions(-)
scripts/kconfig/Makefile +21 -2
@@ -11,7 +11,6 @@ gconfig: $(obj)/gconf $< arch/$(ARCH)/Kconfig menuconfig: $(obj)/mconf - $(Q)$(MAKE) $(build)=scripts/kconfig/lxdialog $< arch/$(ARCH)/Kconfig config: $(obj)/conf
@@ -80,6 +79,23 @@ help: @echo ' allyesconfig - New config where all options are accepted with yes' @echo ' allnoconfig - New config where all options are answered with no' +# lxdialog stuff +check-lxdialog := $(srctree)/$(src)/lxdialog/check-lxdialog.sh + +# Use reursively expanded variables so we do not call gcc unless +# we really need to do so. (Do not call gcc as part of make mrproper) +HOST_EXTRACFLAGS = $(shell $(CONFIG_SHELL) $(check-lxdialog) -ccflags) +HOST_LOADLIBES = $(shell $(CONFIG_SHELL) $(check-lxdialog) -ldflags $(HOSTCC)) + +HOST_EXTRACFLAGS += -DLOCALE + +PHONY += $(obj)/dochecklxdialog +$(obj)/dochecklxdialog: + $(Q)$(CONFIG_SHELL) $(check-lxdialog) -check $(HOSTCC) $(HOST_LOADLIBES) + +always := dochecklxdialog + + # =========================================================================== # Shared Makefile for the various kconfig executables: # conf: Used for defconfig, oldconfig and related targets
@@ -91,9 +107,12 @@ # gconf: Used for the gconfig target # Based on GTK which needs to be installed to compile it # object files used by all kconfig flavours +lxdialog := lxdialog/checklist.o lxdialog/util.o lxdialog/inputbox.o +lxdialog += lxdialog/textbox.o lxdialog/yesno.o lxdialog/menubox.o + hostprogs-y := conf mconf qconf gconf kxgettext conf-objs := conf.o zconf.tab.o -mconf-objs := mconf.o zconf.tab.o +mconf-objs := mconf.o zconf.tab.o $(lxdialog) kxgettext-objs := kxgettext.o zconf.tab.o ifeq ($(MAKECMDGOALS),xconfig)
scripts/kconfig/lxdialog/Makefile deleted +0 -21
@@ -1,21 +0,0 @@ -# Makefile to build lxdialog package -# - -check-lxdialog := $(srctree)/$(src)/check-lxdialog.sh - -# Use reursively expanded variables so we do not call gcc unless -# we really need to do so. (Do not call gcc as part of make mrproper) -HOST_EXTRACFLAGS = $(shell $(CONFIG_SHELL) $(check-lxdialog) -ccflags) -HOST_LOADLIBES = $(shell $(CONFIG_SHELL) $(check-lxdialog) -ldflags $(HOSTCC)) - -HOST_EXTRACFLAGS += -DLOCALE - -PHONY += dochecklxdialog -$(obj)/dochecklxdialog: - $(Q)$(CONFIG_SHELL) $(check-lxdialog) -check $(HOSTCC) $(HOST_LOADLIBES) - -hostprogs-y := lxdialog -always := $(hostprogs-y) dochecklxdialog - -lxdialog-objs := checklist.o menubox.o textbox.o yesno.o inputbox.o \ - util.o lxdialog.o msgbox.o
scripts/kconfig/lxdialog/checklist.c +55 -81
237 lines not on this page · raw message
scripts/kconfig/lxdialog/dialog.h +45 -5
67 lines not on this page · raw message
scripts/kconfig/lxdialog/inputbox.c +1 -1
@@ -222,5 +222,5 @@ int dialog_inputbox(const char *title, c }delwin (dialog); -return -1 ;/* ESC pressed */ +return 255 ;/* ESC pressed */ }
scripts/kconfig/lxdialog/lxdialog.c deleted +0 -204
204 lines not on this page · raw message
scripts/kconfig/lxdialog/menubox.c +40 -55
173 lines not on this page · raw message
scripts/kconfig/lxdialog/msgbox.c deleted +0 -72
72 lines not on this page · raw message
scripts/kconfig/lxdialog/textbox.c +64 -234
428 lines not on this page · raw message
scripts/kconfig/lxdialog/util.c +131 -2
147 lines not on this page · raw message
scripts/kconfig/lxdialog/yesno.c +1 -1
@@ -99,5 +99,5 @@ int dialog_yesno(const char *title, cons }delwin (dialog); -return -1 ;/* ESC pressed */ +return 255 ;/* ESC pressed */ }
scripts/kconfig/mconf.c +141 -339
720 lines not on this page · raw message
Signature · 1 line
1.4.1.rc2.gfc04
Hi,
Quoted 4 lines · Sam Ravnborg
Dedided to take another stamp on an old TODO item of making lxdialog a built-in. Following patch is first step to do so.
The patch makes it a built-in - but with two open issues that I yet have to address.
Looks good. :)
There is a NULL pointer problem with empty menus, item_cur is NULL and a select or exit will cause a segfault in item_set_selected().
Quoted 1 line
I will during the weekend try to address the resize issue.
Wasn't it working at some point?
Anyway, it doesn't has to be overly complex either, e.g. if you delay it to the next key event, it's fine too. The signal handler would just set a flag and when wgetch returns, the display is reinitialized.
Quoted 1 line
The double ESC ESC thing I dunno how to fix.
I think the easiest would be to just ignore the first ESC, it matches the documented behaviour and e.g. mc has the same behaviour. The delay of the single ESC makes it a bit annoying/confusing to use, so that sticking to the double ESC is IMO safer.
I played with it a little and below is an example, which implements this behaviour for the menu window.
bye, Roman
scripts/kconfig/lxdialog/menubox.c +8 -0
@@ -265,6 +265,14 @@ int dialog_menu(const char *title, constwhile (key !=ESC ) { key =wgetch (menu); +if (key ==ESC ) { +notimeout (menu, TRUE); +keypad (menu, FALSE); + key =wgetch (menu); +notimeout (menu, FALSE); +keypad (menu, TRUE); + } +if (key <256 &&isalpha (key)) key =tolower (key);
Quoted 4 lines · Roman Zippel
Hi,
On Thu, 27 Jul 2006, Sam Ravnborg wrote:
Quoted 8 lines
Quoted 4 lines
Dedided to take another stamp on an old TODO item of making lxdialog a built-in. Following patch is first step to do so.
The patch makes it a built-in - but with two open issues that I yet have to address.Looks good. :)
There is a NULL pointer problem with empty menus,item_curis NULL and a select or exit will cause a segfault initem_set_selected().
Fixed. Introduced a dummy variable "item_nil" that item_cur points to in the empty case. So no need for special cases all over.
Quoted 7 lines
Quoted 2 lines
I will during the weekend try to address the resize issue.
Wasn't it working at some point?
Anyway, it doesn't has to be overly complex either, e.g. if you delay it to the next key event, it's fine too. The signal handler would just set a flag and when wgetch returns, the display is reinitialized.
My experiments so far tells me that a resize generates KEY_RESIZE so it is a simple matter of handling KEY_RESIZE correct in the different dialog_* functions - and no signal handler needed. Thats looks like the approach taken in the dialog package too.
Quoted 9 lines
Quoted 2 lines
The double ESC ESC thing I dunno how to fix.
I think the easiest would be to just ignore the first ESC, it matches the documented behaviour and e.g. mc has the same behaviour. The delay of the single ESC makes it a bit annoying/confusing to use, so that sticking to the double ESC is IMO safer.
I played with it a little and below is an example, which implements this behaviour for the menu window.
Thanks - will implment this for all the dialog_* functions.
Sam
Quoted 10 lines · Sam Ravnborg
Quoted 8 lines
Quoted 1 line
The double ESC ESC thing I dunno how to fix.
I think the easiest would be to just ignore the first ESC, it matches the documented behaviour and e.g. mc has the same behaviour. The delay of the single ESC makes it a bit annoying/confusing to use, so that sticking to the double ESC is IMO safer.
I played with it a little and below is an example, which implements this behaviour for the menu window.Thanks - will implment this for all the dialog_* functions.
I don't like "double ESC" idea at all.
I am a Midnight Commander user and I use "old ESC mode" where single ESC works after a delay.
I patched mc to look at KEYBOARD_KEY_TIMEOUT_US environment variable so that delay is configurable (instead of hardcoded 0.5 second one). Will push the patch to mc-devel.
25 millisecond timeout works just fine on local ttys, serial lines, and over ssh. So I am setting KEYBOARD_KEY_TIMEOUT_US=25000. --
vda
Quoted 9 lines · Denis Vlasenko
I don't like "double ESC" idea at all.
I am a Midnight Commander user and I use "old ESC mode" where single ESC works after a delay.
I patched mc to look at
KEYBOARD_KEY_TIMEOUT_USenvironment variable so that delay is configurable (instead of hardcoded 0.5 second one). Will push the patch to mc-devel.
How did you tell ncurses to change timeout value? notimeout() and wnotimeout() did not work out when I tried it. Delay was still ~.5 seconds.
Any help aprpeciated.
Sam
My try:
scripts/kconfig/lxdialog/menubox.c +2 -0
@@ -198,6 +198,7 @@ int dialog_menu(const char *title, const dialog =newwin (height, width, y, x);keypad (dialog, TRUE); +wtimeout (dialog,25 );draw_box (dialog,0 ,0 , height, width, dialog_attr, border_attr);wattrset (dialog, border_attr);
@@ -221,6 +222,7 @@ int dialog_menu(const char *title, const menu =subwin (dialog, menu_height, menu_width, y + box_y +1 , x + box_x +1 );keypad (menu, TRUE); +wtimeout (menu,25 );/* draw a box around the menu items */ draw_box(dialog, box_y, box_x, menu_height + 2, menu_width + 2,
scripts/kconfig/lxdialog/util.c +1 -1
@@ -142,7 +142,7 @@ void init_dialog(void)keypad (stdscr, TRUE);cbreak ();noecho (); - +timeout (25 );if (use_colors)/* Set up colors */ color_setup ();
Hi,
Quoted 4 lines · Denis Vlasenko
I don't like "double ESC" idea at all.
I am a Midnight Commander user and I use "old ESC mode" where single ESC works after a delay.
As you noticed this is not the default mode in mc either.
Quoted 3 lines
I patched mc to look at
KEYBOARD_KEY_TIMEOUT_USenvironment variable so that delay is configurable (instead of hardcoded 0.5 second one). Will push the patch to mc-devel.
If you want to make it an _option_ for menuconfig, please go ahead.
bye, Roman
Quoted 8 lines · Roman Zippel
Quoted 1 line
The double ESC ESC thing I dunno how to fix.
I think the easiest would be to just ignore the first ESC, it matches the documented behaviour and e.g. mc has the same behaviour. The delay of the single ESC makes it a bit annoying/confusing to use, so that sticking to the double ESC is IMO safer.
I played with it a little and below is an example, which implements this behaviour for the menu window.
It became a bit more complicated to support ESC-space resulting in space. That makes sense since one press ESC - wonder what is going on and then press space (for example).
It does not support ESC-left (or any other key that generate meta chars).
Sam
Quoted 1 line
From
0d9076ae65ffa0a1d7bbaf8cf0b16ac1eac63b6eMon Sep 17 00:00:00 2001
From: Sam Ravnborg <[email protected]>
Date: Fri, 28 Jul 2006 23:57:48 +0200
Subject: [PATCH] kconfig/lxdialog: let <ESC><ESC> behave as expected
<ESC><ESC> is used to step one back in the dialogs.
When lxdialog became built-in pressing <ESC> once would cause one step back and pressing <ESC><ESC> would cause two steps back.
This patch - based on concept from Roman Zippel <[email protected]> - makes one <ESC> a noop and pressing <ESC><ESC> will cause one step backward.
In addition the final yes/no dialog now has the option to go back to the the kernel configuration. So if you get too far out you can now go back to configuring the kernel without saving and starting all over again.
--- scripts/kconfig/lxdialog/checklist.c | 10 ++++++---- scripts/kconfig/lxdialog/dialog.h | 4 +++- scripts/kconfig/lxdialog/inputbox.c | 10 ++++++---- scripts/kconfig/lxdialog/menubox.c | 10 ++++++---- scripts/kconfig/lxdialog/textbox.c | 7 ++++--- scripts/kconfig/lxdialog/util.c | 33 +++++++++++++++++++++++++++++++++ scripts/kconfig/lxdialog/yesno.c | 7 ++++--- scripts/kconfig/mconf.c | 25 ++++++++++++++----------- 8 files changed, 76 insertions(+), 30 deletions(-)
scripts/kconfig/lxdialog/checklist.c +6 -4
@@ -192,7 +192,7 @@ int dialog_checklist(const char *title,wnoutrefresh (list);doupdate (); -while (key !=ESC ) { +while (key !=KEY_ESC ) { key =wgetch (dialog);for (i =0 ; i < max_choice; i++) {
@@ -298,8 +298,10 @@ int dialog_checklist(const char *title,break ;case 'X' :case 'x' : - key =ESC ; -case ESC : + key =KEY_ESC ; +break ; +case KEY_ESC : + key =on_key_esc (dialog);break ; }
@@ -308,5 +310,5 @@ int dialog_checklist(const char *title, }delwin (list);delwin (dialog); -return 255 ;/* ESC pressed */ +return key;/* ESC pressed */ }
scripts/kconfig/lxdialog/dialog.h +3 -1
@@ -48,7 +48,7 @@ #endif#define TR (params) _tracef params -#define ESC 27 +#define KEY_ESC 27#define TAB 9#define MAX_LEN 2048#define BUF_SIZE (10*1024)
@@ -179,6 +179,8 @@ #define item_foreach() \for (item_cur = item_head ? item_head: item_cur; \ item_cur && (item_cur != &item_nil); item_cur = item_cur->next) +/* generic key handlers */ +int on_key_esc(WINDOW *win);void init_dialog (const char *backtitle);void reset_dialog (void );
scripts/kconfig/lxdialog/inputbox.c +6 -4
@@ -106,7 +106,7 @@ int dialog_inputbox(const char *title, cwrefresh (dialog); -while (key !=ESC ) { +while (key !=KEY_ESC ) { key =wgetch (dialog);if (button ==-1 ) {/* Input box selected */
@@ -215,12 +215,14 @@ int dialog_inputbox(const char *title, creturn (button ==-1 ?0 : button);case 'X' :case 'x' : - key =ESC ; -case ESC : + key =KEY_ESC ; +break ; +case KEY_ESC : + key =on_key_esc (dialog);break ; } }delwin (dialog); -return 255 ;/* ESC pressed */ +return KEY_ESC ;/* ESC pressed */ }
scripts/kconfig/lxdialog/menubox.c +6 -4
@@ -263,7 +263,7 @@ int dialog_menu(const char *title, constwmove (menu, choice, item_x +1 );wrefresh (menu); -while (key !=ESC ) { +while (key !=KEY_ESC ) { key =wgetch (menu);if (key <256 &&isalpha (key))
@@ -402,12 +402,14 @@ int dialog_menu(const char *title, constreturn button;case 'e' :case 'x' : - key =ESC ; -case ESC : + key =KEY_ESC ; +break ; +case KEY_ESC : + key =on_key_esc (menu);break ; } }delwin (menu);delwin (dialog); -return 255 ;/* ESC pressed */ +return key;/* ESC pressed */ }
scripts/kconfig/lxdialog/textbox.c +4 -3
@@ -92,7 +92,7 @@ int dialog_textbox(const char *title, cowmove (dialog, cur_y, cur_x);/* Restore cursor position */ wrefresh (dialog); -while ((key !=ESC ) && (key !='\n' )) { +while ((key !=KEY_ESC ) && (key !='\n' )) { key =wgetch (dialog);switch (key) {case 'E' :/* Exit */
@@ -228,13 +228,14 @@ int dialog_textbox(const char *title, cowmove (dialog, cur_y, cur_x);wrefresh (dialog);break ; -case ESC : +case KEY_ESC : + key =on_key_esc (dialog);break ; } }delwin (text);delwin (dialog); -return 255 ;/* ESC pressed */ +return key;/* ESC pressed */ }/*
scripts/kconfig/lxdialog/util.c +33 -0
@@ -477,6 +477,39 @@ int first_alpha(const char *string, consreturn 0 ; } +/* +* ncurses uses ESC to detect escaped char sequences. This resutl in +* a small timeout before ESC is actually delivered to the application. +* lxdialog suggest <ESC> <ESC> which is correctly translated to two +* times esc. But then we need to ignore the second esc to avoid stepping +* out one menu too much. Filter away all escaped key sequences since +* keypad(FALSE) turn off ncurses support for escape sequences - and thats +* needed to make notimeout() do as expected. +*/ +int on_key_esc (WINDOW *win) +{ +int key; +int key2; +int key3; + +nodelay (win, TRUE); +keypad (win, FALSE); + key =wgetch (win); + key2 =wgetch (win); +do { + key3 =wgetch (win); + }while (key3 !=ERR ); +nodelay (win, FALSE); +keypad (win, TRUE); +if (key ==KEY_ESC && key2 ==ERR ) +return KEY_ESC ; +else if (key !=ERR && key !=KEY_ESC && key2 ==ERR ) +ungetch (key); + +return -1 ; +} + +struct dialog_list *item_cur;struct dialog_list item_nil;struct dialog_list *item_head;
scripts/kconfig/lxdialog/yesno.c +4 -3
@@ -69,7 +69,7 @@ int dialog_yesno(const char *title, consprint_buttons (dialog, height, width,0 ); -while (key !=ESC ) { +while (key !=KEY_ESC ) { key =wgetch (dialog);switch (key) {case 'Y' :
@@ -93,11 +93,12 @@ int dialog_yesno(const char *title, conscase '\n' :delwin (dialog);return button; -case ESC : +case KEY_ESC : + key =on_key_esc (dialog);break ; } }delwin (dialog); -return 255 ;/* ESC pressed */ +return key;/* ESC pressed */ }
scripts/kconfig/mconf.c +14 -11
@@ -608,7 +608,7 @@ static void conf(struct menu *menu)_ (menu_instructions), rows, cols, rows -10 , active_menu, &s_scroll); -if (res ==1 || res ==255 ) +if (res ==1 || res ==KEY_ESC )break ;if (!item_activate_selected ())continue ;
@@ -754,7 +754,7 @@ static void conf_choice(struct menu *men }else show_help (menu);break ; -case 255 : +case KEY_ESC :return ; } }
@@ -794,7 +794,7 @@ static void conf_string(struct menu *mencase 1 :show_help (menu);break ; -case 255 : +case KEY_ESC :return ; } }
@@ -819,7 +819,7 @@ static void conf_load(void)case 1 :show_helptext (_ ("Load Alternate Configuration" ), load_config_help);break ; -case 255 : +case KEY_ESC :return ; } }
@@ -843,7 +843,7 @@ static void conf_save(void)case 1 :show_helptext (_ ("Save Alternate Configuration" ), save_config_help);break ; -case 255 : +case KEY_ESC :return ; } }
@@ -883,12 +883,15 @@ int main(int ac, char **av)init_wsize ();reset_dialog ();init_dialog (menu_backtitle); -conf (&rootmenu); -reset_dialog (); - res =dialog_yesno (NULL , -_ ("Do you wish to save your " -"new kernel configuration?" ), -5 ,60 ); +do { +conf (&rootmenu); +reset_dialog (); + res =dialog_yesno (NULL , +_ ("Do you wish to save your " +"new kernel configuration?\n" +"<ESC><ESC> to continue." ), +6 ,60 ); + }while (res ==KEY_ESC );end_dialog ();if (res ==0 ) {if (conf_write (NULL )) {
Signature · 1 line
1.4.1.rc2.gfc04
Quoted 3 lines
Quoted 2 lines
I will during the weekend try to address the resize issue.
Here is my take on the resize support. textbox.c were hit by a little refactoring in same go. I can split it in two patches if requested.
make menuconfig looks sensible and I have now pushed all patches out to:git://git.kernel.org/pub/scm/linux/kernel/git/sam/lxdialog.git
It will show up in next -mm for wider testing.
Comments welcome!
Sam
Quoted 1 line
From
466ac6aa895d1c25964f9fef4502bb9b1cab6dd9Mon Sep 17 00:00:00 2001
From: Sam Ravnborg <[email protected]>
Date: Sat, 29 Jul 2006 22:48:57 +0200
Subject: [PATCH] kconfig/lxdialog: support resize
In all dialogs now properly catch KEY_RESIZE and take proper action. In mconf try to behave sensibly when a dialog routine returns -ERRDISPLAYTOOSMALL.
The original check for a screnn size of 80x19 is kept for now. It may make sense to remove it later, but thats anyway what much text is adjusted for.
--- scripts/kconfig/lxdialog/checklist.c | 11 +++ scripts/kconfig/lxdialog/dialog.h | 8 +- scripts/kconfig/lxdialog/inputbox.c | 20 ++++- scripts/kconfig/lxdialog/menubox.c | 25 +++++- scripts/kconfig/lxdialog/textbox.c | 140 ++++++++++++++++++++-------------- scripts/kconfig/lxdialog/util.c | 6 + scripts/kconfig/lxdialog/yesno.c | 10 ++ scripts/kconfig/mconf.c | 12 ++- 8 files changed, 161 insertions(+), 71 deletions(-)
scripts/kconfig/lxdialog/checklist.c +11 -0
@@ -125,6 +125,12 @@ int dialog_checklist(const char *title, } } +do_resize: +if (getmaxy (stdscr) < (height +6 )) +return -ERRDISPLAYTOOSMALL ; +if (getmaxx (stdscr) < (width +6 )) +return -ERRDISPLAYTOOSMALL ; + max_choice =MIN (list_height,item_count ());/* center dialog box on screen */
@@ -303,6 +309,11 @@ int dialog_checklist(const char *title,case KEY_ESC : key =on_key_esc (dialog);break ; +case KEY_RESIZE : +delwin (list); +delwin (dialog); +on_key_resize (); + goto do_resize; }/* Now, update everything... */
scripts/kconfig/lxdialog/dialog.h +6 -2
@@ -86,6 +86,9 @@ #ifndef ACS_DARROW#define ACS_DARROW 'v'#endif +/* error return codes */ +#define ERRDISPLAYTOOSMALL (KEY_MAX + 1) +/* * Color definitions */
@@ -181,6 +184,7 @@ #define item_foreach() \/* generic key handlers */ int on_key_esc (WINDOW *win); +int on_key_resize (void );void init_dialog (const char *backtitle);void reset_dialog (void );
@@ -199,8 +203,8 @@ int dialog_yesno(const char *title, consint dialog_msgbox (const char *title,const char *prompt,int height,int width,int pause);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 void *selected,int *s_scroll); +int dialog_menu (const char *title,const char *prompt, +const void *selected,int *s_scroll);int dialog_checklist (const char *title,const char *prompt,int height,int width,int list_height);extern char dialog_input_result[];
scripts/kconfig/lxdialog/inputbox.c +15 -5
@@ -49,6 +49,17 @@ int dialog_inputbox(const char *title, cchar *instr = dialog_input_result;WINDOW *dialog; +if (!init) + instr[0 ] ='\0' ; +else +strcpy (instr, init); + +do_resize: +if (getmaxy (stdscr) <= (height -2 )) +return -ERRDISPLAYTOOSMALL ; +if (getmaxx (stdscr) <= (width -2 )) +return -ERRDISPLAYTOOSMALL ; +/* center dialog box on screen */ x = (COLS - width) /2 ; y = (LINES - height) /2 ;
@@ -86,11 +97,6 @@ int dialog_inputbox(const char *title, cwmove (dialog, box_y, box_x);wattrset (dialog, dlg.inputbox.atr); -if (!init) - instr[0 ] ='\0' ; -else -strcpy (instr, init); - input_x =strlen (instr);if (input_x >= box_width) {
@@ -220,6 +226,10 @@ int dialog_inputbox(const char *title, ccase KEY_ESC : key =on_key_esc (dialog);break ; +case KEY_RESIZE : +delwin (dialog); +on_key_resize (); + goto do_resize; } }
scripts/kconfig/lxdialog/menubox.c +22 -3
@@ -179,14 +179,25 @@ static void do_scroll(WINDOW *win, int */* * Display a menu for choosing among a number of options */ -int dialog_menu (const char *title,const char *prompt,int height,int width, -int menu_height,const void *selected,int *s_scroll) +int dialog_menu (const char *title,const char *prompt, +const void *selected,int *s_scroll) {int i, j, x, y, box_x, box_y; +int height, width, menu_height;int key =0 , button =0 , scroll =0 , choice =0 ;int first_item =0 , max_choice;WINDOW *dialog, *menu; +do_resize: + height =getmaxy (stdscr); + width =getmaxx (stdscr); +if (height <15 || width <65 ) +return -ERRDISPLAYTOOSMALL ; + + height -=4 ; + width -=5 ; + menu_height = height -10 ; + max_choice =MIN (menu_height,item_count ());/* center dialog box on screen */
@@ -226,7 +237,10 @@ int dialog_menu(const char *title, constdraw_box (dialog, box_y, box_x, menu_height +2 , menu_width +2 , dlg.menubox_border.atr, dlg.menubox.atr); - item_x = (menu_width -70 ) /2 ; +if (menu_width >=80 ) + item_x = (menu_width -70 ) /2 ; +else + item_x =4 ;/* Set choice to default item */ item_foreach ()
@@ -407,6 +421,11 @@ int dialog_menu(const char *title, constcase KEY_ESC : key =on_key_esc (menu);break ; +case KEY_RESIZE : +on_key_resize (); +delwin (menu); +delwin (dialog); + goto do_resize; } }delwin (menu);
scripts/kconfig/lxdialog/textbox.c +83 -57
257 lines not on this page · raw message
scripts/kconfig/lxdialog/util.c +6 -0
@@ -509,6 +509,12 @@ int on_key_esc(WINDOW *win)return -1 ; } +/* redraw screen in new size */ +int on_key_resize (void ) +{ +dialog_clear (); +return KEY_RESIZE ; +}struct dialog_list *item_cur;struct dialog_list item_nil;
scripts/kconfig/lxdialog/yesno.c +10 -0
@@ -44,6 +44,12 @@ int dialog_yesno(const char *title, consint i, x, y, key =0 , button =0 ;WINDOW *dialog; +do_resize: +if (getmaxy (stdscr) < (height +4 )) +return -ERRDISPLAYTOOSMALL ; +if (getmaxx (stdscr) < (width +4 )) +return -ERRDISPLAYTOOSMALL ; +/* center dialog box on screen */ x = (COLS - width) /2 ; y = (LINES - height) /2 ;
@@ -96,6 +102,10 @@ int dialog_yesno(const char *title, conscase KEY_ESC : key =on_key_esc (dialog);break ; +case KEY_RESIZE : +delwin (dialog); +on_key_resize (); + goto do_resize; } }
scripts/kconfig/mconf.c +8 -4
@@ -606,9 +606,8 @@ static void conf(struct menu *menu)reset_dialog (); res =dialog_menu (prompt ? prompt :_ ("Main Menu" ),_ (menu_instructions), - rows, cols, rows -10 , active_menu, &s_scroll); -if (res ==1 || res ==KEY_ESC ) +if (res ==1 || res ==KEY_ESC || res == -ERRDISPLAYTOOSMALL )break ;if (!item_activate_selected ())continue ;
@@ -617,7 +616,10 @@ static void conf(struct menu *menu) submenu =item_data (); active_menu =item_data (); - sym = submenu->sym; +if (submenu) + sym = submenu->sym; +else + sym =NULL ;switch (res) {case 0 :
@@ -683,7 +685,7 @@ static void conf(struct menu *menu)static void show_textbox (const char *title,const char *text,int r,int c) {reset_dialog (); -dialog_textbox (title, text, r ? r : rows, c ? c : cols); +dialog_textbox (title, text, r, c); }static void show_helptext (const char *title,const char *text)
@@ -756,6 +758,8 @@ static void conf_choice(struct menu *menbreak ;case KEY_ESC :return ; +case -ERRDISPLAYTOOSMALL : +return ; } } }
Signature · 1 line
1.4.1.rc2.gfc04