* [PATCH 2/3] kconfig and lxdialog, kernel 2.6.13.4
@ 2005-10-27 16:07 Fao, Sean
2005-10-27 21:20 ` Roman Zippel
0 siblings, 1 reply; 3+ messages in thread
From: Fao, Sean @ 2005-10-27 16:07 UTC (permalink / raw)
To: linux-kernel, zippel
This patch is a functionality modification to lxdialog to add support
for an "Abort" button in *addition* to the standard "Yes" and "No"
buttons on the "yesno" dialog. The intended purpose of this patch is to
give users the ability to abort their last requested action.
Signed-off-by: Sean E. Fao <sean.fao@capitalgenomix.com>
diff -up linux-2.6.13.4/scripts/lxdialog/dialog.h
linux/scripts/lxdialog/dialog.h
--- linux-2.6.13.4/scripts/lxdialog/dialog.h 2005-10-27
09:21:46.000000000 -0500
+++ linux/scripts/lxdialog/dialog.h 2005-10-26 16:03:24.000000000 -0500
@@ -123,6 +123,12 @@
/* number of attributes */
#define ATTRIBUTE_COUNT 29
+/* enum types */
+typedef enum {
+ YESNO,
+ YESNOABORT
+} BUTTONTYPE;
+
/*
* Global variables
*/
@@ -151,7 +157,8 @@ void draw_box(WINDOW * win, int y, int x
void draw_shadow(WINDOW * win, int y, int x, int height, int width);
int first_alpha(const char *string, const char *exempt);
-int dialog_yesno(const char *title, const char *prompt, int height, int
width);
+int dialog_yesnoabort(const char *title, const char *prompt, int height,
+ int width, BUTTONTYPE button_t);
int 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);
diff -up linux-2.6.13.4/scripts/lxdialog/lxdialog.c
linux/scripts/lxdialog/lxdialog.c
--- linux-2.6.13.4/scripts/lxdialog/lxdialog.c 2005-10-27
09:21:45.000000000 -0500
+++ linux/scripts/lxdialog/lxdialog.c 2005-10-26 16:04:54.000000000 -0500
@@ -31,7 +31,8 @@ struct Mode {
jumperFn *jumper;
};
-jumperFn j_menu, j_checklist, j_radiolist, j_yesno, j_textbox, j_inputbox;
+jumperFn j_menu, j_checklist, j_radiolist, j_yesno, j_yesnoabort,
j_textbox,
+ j_inputbox;
jumperFn j_msgbox, j_infobox;
static struct Mode modes[] = {
@@ -39,6 +40,7 @@ static struct Mode modes[] = {
{"--checklist", 9, 0, 3, j_checklist},
{"--radiolist", 9, 0, 3, j_radiolist},
{"--yesno", 5, 5, 1, j_yesno},
+ {"--yesnoabort", 5, 5, 1, j_yesnoabort},
{"--textbox", 5, 5, 1, j_textbox},
{"--inputbox", 5, 6, 1, j_inputbox},
{"--msgbox", 5, 5, 1, j_msgbox},
@@ -150,12 +152,13 @@ static void Usage(const char *name)
\n\
\nBox options:\
\n\
-\n --menu <text> <height> <width> <menu height> <tag1> <item1>...\
-\n --checklist <text> <height> <width> <list height> <tag1> <item1>
<status1>...\
-\n --radiolist <text> <height> <width> <list height> <tag1> <item1>
<status1>...\
-\n --textbox <file> <height> <width>\
-\n --inputbox <text> <height> <width> [<init>]\
-\n --yesno <text> <height> <width>\
+\n --menu <text> <height> <width> <menu height> <tag1> <item1>...\
+\n --checklist <text> <height> <width> <list height> <tag1> <item1>
<status1>...\
+\n --radiolist <text> <height> <width> <list height> <tag1> <item1>
<status1>...\
+\n --textbox <file> <height> <width>\
+\n --inputbox <text> <height> <width> [<init>]\
+\n --yesno <text> <height> <width>\
+\n --yesnoabort <text> <height> <width>\
\n", name, name);
exit(-1);
}
@@ -189,7 +192,12 @@ int j_textbox(const char *t, int ac, con
int j_yesno(const char *t, int ac, const char *const *av)
{
- return dialog_yesno(t, av[2], atoi(av[3]), atoi(av[4]));
+ return dialog_yesnoabort(t, av[2], atoi(av[3]), atoi(av[4]), YESNO);
+}
+
+int j_yesnoabort(const char *t, int ac, const char *const *av)
+{
+ return dialog_yesnoabort(t, av[2], atoi(av[3]), atoi(av[4]),
YESNOABORT);
}
int j_inputbox(const char *t, int ac, const char *const *av)
diff -up linux-2.6.13.4/scripts/lxdialog/yesno.c
linux/scripts/lxdialog/yesno.c
--- linux-2.6.13.4/scripts/lxdialog/yesno.c 2005-10-27
09:21:45.000000000 -0500
+++ linux/scripts/lxdialog/yesno.c 2005-10-26 19:18:25.000000000 -0500
@@ -24,22 +24,26 @@
/*
* Display termination buttons
*/
-static void print_buttons(WINDOW * dialog, int height, int width, int
selected)
+static void print_buttons(WINDOW * dialog, int height, int width, int
selected,
+ BUTTONTYPE btn_t)
{
- int x = width / 2 - 10;
+ int x = width / (btn_t == YESNO ? 2 : 3) - 10;
int y = height - 2;
print_button(dialog, " Yes ", y, x, selected == 0);
print_button(dialog, " No ", y, x + 13, selected == 1);
+ if (btn_t == YESNOABORT)
+ print_button(dialog, " Abort ", y, x + 26, selected == 2);
wmove(dialog, y, x + 1 + 13 * selected);
wrefresh(dialog);
}
/*
- * Display a dialog box with two buttons - Yes and No
+ * Display a dialog box with specified button types
*/
-int dialog_yesno(const char *title, const char *prompt, int height, int
width)
+int dialog_yesnoabort(const char *title, const char *prompt, int height,
+ int width, BUTTONTYPE btn_t)
{
int i, x, y, key = 0, button = 0;
WINDOW *dialog;
@@ -79,7 +83,7 @@ int dialog_yesno(const char *title, cons
wattrset(dialog, dialog_attr);
print_autowrap(dialog, prompt, width - 2, 1, 3);
- print_buttons(dialog, height, width, 0);
+ print_buttons(dialog, height, width, 0, btn_t);
while (key != ESC) {
key = wgetch(dialog);
@@ -92,14 +96,22 @@ int dialog_yesno(const char *title, cons
case 'n':
delwin(dialog);
return 1;
-
+ case 'A':
+ case 'a':
+ if (btn_t == YESNOABORT)
+ {
+ delwin(dialog);
+ return 2;
+ }
+ break;
case TAB:
case KEY_LEFT:
case KEY_RIGHT:
+ /* Selections available are based on # of buttons on dialog */
button = ((key == KEY_LEFT ? --button : ++button) < 0)
- ? 1 : (button > 1 ? 0 : button);
+ ? (btn_t + 1) : (button > (btn_t + 1) ? 0 : button);
- print_buttons(dialog, height, width, button);
+ print_buttons(dialog, height, width, button, btn_t);
wrefresh(dialog);
break;
case ' ':
--
Sean
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH 2/3] kconfig and lxdialog, kernel 2.6.13.4 2005-10-27 16:07 [PATCH 2/3] kconfig and lxdialog, kernel 2.6.13.4 Fao, Sean @ 2005-10-27 21:20 ` Roman Zippel 2005-11-03 18:55 ` [PATCH 2/3] kconfig and lxdialog, kernel 2.6.14 sean.fao 0 siblings, 1 reply; 3+ messages in thread From: Roman Zippel @ 2005-10-27 21:20 UTC (permalink / raw) To: Fao, Sean; +Cc: linux-kernel Hi, On Thu, 27 Oct 2005, Fao, Sean wrote: BTW your patch is white space damaged and wordwrapped. > @@ -92,14 +96,22 @@ int dialog_yesno(const char *title, cons > case 'n': > delwin(dialog); > return 1; > - > + case 'A': > + case 'a': > + if (btn_t == YESNOABORT) > + { > + delwin(dialog); > + return 2; > + } > + break; Actually it's already possible to abort the dialog by pressing Esc. I don't mind the abort button, but please match the Esc behaviour and return -1. bye, Roman ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 2/3] kconfig and lxdialog, kernel 2.6.14 2005-10-27 21:20 ` Roman Zippel @ 2005-11-03 18:55 ` sean.fao 0 siblings, 0 replies; 3+ messages in thread From: sean.fao @ 2005-11-03 18:55 UTC (permalink / raw) To: Roman Zippel; +Cc: linux-kernel [-- Attachment #1: lxdialog.patch --] [-- Type: text/plain, Size: 7129 bytes --] On Thu, Oct 27, 2005 at 11:20:31PM +0200, Roman Zippel wrote: > > @@ -92,14 +96,22 @@ int dialog_yesno(const char *title, cons > > case 'n': > > delwin(dialog); > > return 1; > > - > > + case 'A': > > + case 'a': > > + if (btn_t == YESNOABORT) > > + { > > + delwin(dialog); > > + return 2; > > + } > > + break; > > Actually it's already possible to abort the dialog by pressing Esc. I > don't mind the abort button, but please match the Esc behaviour and return > -1. Advise taken. Personally, I don't like "magic numbers", so I'd prefer to return an enumerated type (DIALOG_RESULT), if you don't mind. Signed-off-by: Sean Fao <sean.fao@capitalgenomix.com> --- diff -up linux-2.6.14/scripts/lxdialog/dialog.h linux/scripts/lxdialog/dialog.h --- linux-2.6.14/scripts/lxdialog/dialog.h 2005-11-03 10:59:40.000000000 -0500 +++ linux/scripts/lxdialog/dialog.h 2005-11-03 10:48:51.000000000 -0500 @@ -123,6 +123,19 @@ /* number of attributes */ #define ATTRIBUTE_COUNT 29 +/* enum types */ +typedef enum { + YESNO, + YESNOABORT +} BUTTONTYPE; + +typedef enum +{ + ABORT = -1, + YES, + NO +} DIALOG_RESULT; + /* * Global variables */ @@ -151,7 +164,8 @@ void draw_box(WINDOW * win, int y, int x void draw_shadow(WINDOW * win, int y, int x, int height, int width); int first_alpha(const char *string, const char *exempt); -int dialog_yesno(const char *title, const char *prompt, int height, int width); +int dialog_yesnoabort(const char *title, const char *prompt, int height, + int width, BUTTONTYPE button_t); int 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); diff -up linux-2.6.14/scripts/lxdialog/lxdialog.c linux/scripts/lxdialog/lxdialog.c --- linux-2.6.14/scripts/lxdialog/lxdialog.c 2005-11-03 10:59:38.000000000 -0500 +++ linux/scripts/lxdialog/lxdialog.c 2005-11-03 10:48:51.000000000 -0500 @@ -31,7 +31,8 @@ struct Mode { jumperFn *jumper; }; -jumperFn j_menu, j_checklist, j_radiolist, j_yesno, j_textbox, j_inputbox; +jumperFn j_menu, j_checklist, j_radiolist, j_yesno, j_yesnoabort, j_textbox, + j_inputbox; jumperFn j_msgbox, j_infobox; static struct Mode modes[] = { @@ -39,6 +40,7 @@ static struct Mode modes[] = { {"--checklist", 9, 0, 3, j_checklist}, {"--radiolist", 9, 0, 3, j_radiolist}, {"--yesno", 5, 5, 1, j_yesno}, + {"--yesnoabort", 5, 5, 1, j_yesnoabort}, {"--textbox", 5, 5, 1, j_textbox}, {"--inputbox", 5, 6, 1, j_inputbox}, {"--msgbox", 5, 5, 1, j_msgbox}, @@ -150,12 +152,13 @@ static void Usage(const char *name) \n\ \nBox options:\ \n\ -\n --menu <text> <height> <width> <menu height> <tag1> <item1>...\ -\n --checklist <text> <height> <width> <list height> <tag1> <item1> <status1>...\ -\n --radiolist <text> <height> <width> <list height> <tag1> <item1> <status1>...\ -\n --textbox <file> <height> <width>\ -\n --inputbox <text> <height> <width> [<init>]\ -\n --yesno <text> <height> <width>\ +\n --menu <text> <height> <width> <menu height> <tag1> <item1>...\ +\n --checklist <text> <height> <width> <list height> <tag1> <item1> <status1>...\ +\n --radiolist <text> <height> <width> <list height> <tag1> <item1> <status1>...\ +\n --textbox <file> <height> <width>\ +\n --inputbox <text> <height> <width> [<init>]\ +\n --yesno <text> <height> <width>\ +\n --yesnoabort <text> <height> <width>\ \n", name, name); exit(-1); } @@ -189,7 +192,12 @@ int j_textbox(const char *t, int ac, con int j_yesno(const char *t, int ac, const char *const *av) { - return dialog_yesno(t, av[2], atoi(av[3]), atoi(av[4])); + return dialog_yesnoabort(t, av[2], atoi(av[3]), atoi(av[4]), YESNO); +} + +int j_yesnoabort(const char *t, int ac, const char *const *av) +{ + return dialog_yesnoabort(t, av[2], atoi(av[3]), atoi(av[4]), YESNOABORT); } int j_inputbox(const char *t, int ac, const char *const *av) diff -up linux-2.6.14/scripts/lxdialog/menubox.c linux/scripts/lxdialog/menubox.c --- linux-2.6.14/scripts/lxdialog/menubox.c 2005-11-03 10:59:38.000000000 -0500 +++ linux/scripts/lxdialog/menubox.c 2005-11-03 10:48:56.000000000 -0500 @@ -222,7 +222,7 @@ dialog_menu(const char *title, const cha /* * Find length of longest item in order to center menu. - * Set 'choice' to default item. + * Set 'choice' to default item. */ item_x = 0; for (i = 0; i < item_no; i++) { Only in linux/scripts/lxdialog/: menubox.c.orig diff -up linux-2.6.14/scripts/lxdialog/yesno.c linux/scripts/lxdialog/yesno.c --- linux-2.6.14/scripts/lxdialog/yesno.c 2005-11-03 10:59:38.000000000 -0500 +++ linux/scripts/lxdialog/yesno.c 2005-11-03 10:48:56.000000000 -0500 @@ -24,22 +24,31 @@ /* * Display termination buttons */ -static void print_buttons(WINDOW * dialog, int height, int width, int selected) +static void print_buttons(WINDOW * dialog, int height, int width, int selected, + BUTTONTYPE btn_t) { - int x = width / 2 - 10; + int x; int y = height - 2; + if (btn_t == YESNO) + x = width / 2 - 10; + else + x = width / 3 - 7; + print_button(dialog, " Yes ", y, x, selected == 0); print_button(dialog, " No ", y, x + 13, selected == 1); + if (btn_t == YESNOABORT) + print_button(dialog, " Abort ", y, x + 26, selected == 2); wmove(dialog, y, x + 1 + 13 * selected); wrefresh(dialog); } /* - * Display a dialog box with two buttons - Yes and No + * Display a dialog box with specified button types */ -int dialog_yesno(const char *title, const char *prompt, int height, int width) +int dialog_yesnoabort(const char *title, const char *prompt, int height, + int width, BUTTONTYPE btn_t) { int i, x, y, key = 0, button = 0; WINDOW *dialog; @@ -79,7 +88,7 @@ int dialog_yesno(const char *title, cons wattrset(dialog, dialog_attr); print_autowrap(dialog, prompt, width - 2, 1, 3); - print_buttons(dialog, height, width, 0); + print_buttons(dialog, height, width, 0, btn_t); while (key != ESC) { key = wgetch(dialog); @@ -87,19 +96,27 @@ int dialog_yesno(const char *title, cons case 'Y': case 'y': delwin(dialog); - return 0; + return YES; case 'N': case 'n': delwin(dialog); - return 1; - + return NO; + case 'A': + case 'a': + if (btn_t == YESNOABORT) + { + delwin(dialog); + return ABORT; + } + break; case TAB: case KEY_LEFT: case KEY_RIGHT: + /* Selections available are based on # of buttons on dialog */ button = ((key == KEY_LEFT ? --button : ++button) < 0) - ? 1 : (button > 1 ? 0 : button); + ? (btn_t + 1) : (button > (btn_t + 1) ? 0 : button); - print_buttons(dialog, height, width, button); + print_buttons(dialog, height, width, button, btn_t); wrefresh(dialog); break; case ' ': @@ -112,5 +129,5 @@ int dialog_yesno(const char *title, cons } delwin(dialog); - return -1; /* ESC pressed */ + return ABORT; /* ESC pressed */ } ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2005-11-03 18:54 UTC | newest] Thread overview: 3+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2005-10-27 16:07 [PATCH 2/3] kconfig and lxdialog, kernel 2.6.13.4 Fao, Sean 2005-10-27 21:20 ` Roman Zippel 2005-11-03 18:55 ` [PATCH 2/3] kconfig and lxdialog, kernel 2.6.14 sean.fao
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.