* [PATCH 1/2] menu: add support to do not display the entry number
@ 2012-05-27 13:57 Jean-Christophe PLAGNIOL-VILLARD
2012-05-27 13:57 ` [PATCH 2/2] menu: add support for disable entry Jean-Christophe PLAGNIOL-VILLARD
2012-06-01 6:34 ` [PATCH 1/2] menu: add support to do not display the entry number Sascha Hauer
0 siblings, 2 replies; 5+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-05-27 13:57 UTC (permalink / raw)
To: barebox
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
commands/menu.c | 10 ++++++++--
| 3 ++-
| 2 ++
3 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/commands/menu.c b/commands/menu.c
index 8833d74..6f74105 100644
--- a/commands/menu.c
+++ b/commands/menu.c
@@ -43,6 +43,7 @@ struct cmd_menu {
menu_action action;
char *description;
int auto_select;
+ int not_display_num;
#if defined(CONFIG_CMD_MENU_MANAGEMENT)
int entry;
int re_entrant;
@@ -55,10 +56,10 @@ struct cmd_menu {
};
#if defined(CONFIG_CMD_MENU_MANAGEMENT)
-#define OPTS "m:earlc:d:RsSn:u:A:b:B:"
+#define OPTS "m:earlNc:d:RsSn:u:A:b:B:"
#define is_entry(x) ((x)->entry)
#else
-#define OPTS "m:lsA:d:"
+#define OPTS "m:lsA:d:N"
#define is_entry(x) (0)
#endif
@@ -233,6 +234,7 @@ static int do_menu_show(struct cmd_menu *cm)
if (!m)
return -EINVAL;
+ m->display_num = !cm->not_display_num;
if (cm->auto_select != -EINVAL) {
menu_set_auto_select(m, cm->auto_select);
@@ -340,6 +342,9 @@ static int do_menu(int argc, char *argv[])
case 'd':
cm.description = optarg;
break;
+ case 'N':
+ cm.not_display_num = 1;
+ break;
#if defined(CONFIG_CMD_MENU_MANAGEMENT)
case 'e':
cm.entry = 1;
@@ -416,6 +421,7 @@ static const __maybe_unused char cmd_menu_help[] =
" -m menu\n"
" -l list\n"
" -s show\n"
+" -N do not display number\n"
#if defined(CONFIG_CMD_MENU_MANAGEMENT)
"Advanced\n"
" -e menu entry\n"
--git a/common/menu.c b/common/menu.c
index 070170e..12812a5 100644
--- a/common/menu.c
+++ b/common/menu.c
@@ -178,7 +178,8 @@ static void print_menu_entry(struct menu *m, struct menu_entry *me,
process_escape_sequence(me->display, m->display_buffer,
m->display_buffer_size);
- printf(" %d: ", me->num);
+ if (m->display_num)
+ printf(" %d: ", me->num);
if (selected)
puts("\e[7m");
if (IS_ENABLED(CONFIG_SHELL_HUSH))
--git a/include/menu.h b/include/menu.h
index 74abcfb..5a7e8ca 100644
--- a/include/menu.h
+++ b/include/menu.h
@@ -56,6 +56,8 @@ struct menu {
int auto_select;
char *auto_display;
+ int display_num;
+
struct list_head list;
struct list_head entries;
--
1.7.9.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 2/2] menu: add support for disable entry
2012-05-27 13:57 [PATCH 1/2] menu: add support to do not display the entry number Jean-Christophe PLAGNIOL-VILLARD
@ 2012-05-27 13:57 ` Jean-Christophe PLAGNIOL-VILLARD
2012-05-29 8:35 ` Sascha Hauer
2012-06-01 6:34 ` [PATCH 1/2] menu: add support to do not display the entry number Sascha Hauer
1 sibling, 1 reply; 5+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-05-27 13:57 UTC (permalink / raw)
To: barebox
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
.../arm/boards/at91sam9m10g45ek/env/bin/boot_board | 2 +
commands/menu.c | 15 +++++-
| 44 +++++++++++++------
| 1 +
4 files changed, 45 insertions(+), 17 deletions(-)
diff --git a/arch/arm/boards/at91sam9m10g45ek/env/bin/boot_board b/arch/arm/boards/at91sam9m10g45ek/env/bin/boot_board
index cf6cc56..3cdef8b 100644
--- a/arch/arm/boards/at91sam9m10g45ek/env/bin/boot_board
+++ b/arch/arm/boards/at91sam9m10g45ek/env/bin/boot_board
@@ -13,10 +13,12 @@ fi
menu -r -m boot
menu -a -m boot -d "\e[1;36mWelcome on Barebox Boot Sequence\e[0m"
+menu -e -a -m boot -D -d "\e[1;36mBoot \e[0m"
menu -e -a -m boot -c 'menu_boot' -d "boot (default) "
menu -e -a -m boot -c 'menu_boot -m nand' -d "boot from nand "
menu -e -a -m boot -c 'menu_boot -k nfs -r net' -d "boot from nfs (kernel nfs) "
menu -e -a -m boot -c 'menu_boot -k tftp -r net' -d "boot from nfs (kernel tftp)"
+menu -e -a -m boot -D -d "\e[1;36mCommand \e[0m"
menu -e -a -m boot -c 'clear' -d "\e[2;33mshell \e[0m"
menu -e -a -m boot -u update -d "update "
menu -e -a -m boot -c reset -d "\e[1;31mreset \e[0m"
diff --git a/commands/menu.c b/commands/menu.c
index 6f74105..c877a90 100644
--- a/commands/menu.c
+++ b/commands/menu.c
@@ -56,7 +56,7 @@ struct cmd_menu {
};
#if defined(CONFIG_CMD_MENU_MANAGEMENT)
-#define OPTS "m:earlNc:d:RsSn:u:A:b:B:"
+#define OPTS "m:earlNc:d:RsSn:u:A:b:B:D"
#define is_entry(x) ((x)->entry)
#else
#define OPTS "m:lsA:d:N"
@@ -65,7 +65,7 @@ struct cmd_menu {
#if defined(CONFIG_CMD_MENU_MANAGEMENT)
/*
- * menu -e -a -m <menu> -c <command> [-R] [-b 0|1 ] -d <description>
+ * menu -e -a -m <menu> -c <command> [-R] [-b 0|1 ] [-D] -d <description>
* menu -e -a -m <menu> -u submenu -d [-b 0|1] <description>
*/
static int do_menu_entry_add(struct cmd_menu *cm)
@@ -73,8 +73,13 @@ static int do_menu_entry_add(struct cmd_menu *cm)
struct menu_entry *me;
struct menu *m;
- if (!cm->menu || (!cm->command && !cm->submenu) || !cm->description)
+ if (!cm->menu || !cm->description)
+ return -EINVAL;
+
+ if (cm->type != MENU_ENTRY_DISABLE && !cm->command && !cm->submenu) {
+ eprintf("Menu '%s' not found\n", cm->menu);
return -EINVAL;
+ }
m = menu_get_by_name(cm->menu);
@@ -374,6 +379,9 @@ static int do_menu(int argc, char *argv[])
cm.type = MENU_ENTRY_BOX;
cm.box_state = simple_strtoul(optarg, NULL, 10);
break;
+ case 'D':
+ cm.type = MENU_ENTRY_DISABLE;
+ break;
case 'B':
cm.command = optarg;
break;
@@ -450,6 +458,7 @@ static const __maybe_unused char cmd_menu_help[] =
"Add an entry\n"
" (-R for do no exit the menu after executing the command)\n"
" (-b for box style 1 for selected)\n"
+" (-D for disabel style command is not needed)\n"
" (and optional -c for the command to run when we change the state)\n"
" menu -e -a -m <menu> -c <command> [-R] [-b 0|1] -d <description>\n"
--git a/common/menu.c b/common/menu.c
index 12812a5..313603a 100644
--- a/common/menu.c
+++ b/common/menu.c
@@ -156,7 +156,8 @@ void menu_entry_free(struct menu_entry *me)
if (!me)
return;
- me->free(me);
+ if (me->free)
+ me->free(me);
}
EXPORT_SYMBOL(menu_entry_free);
@@ -165,12 +166,17 @@ static void print_menu_entry(struct menu *m, struct menu_entry *me,
{
gotoXY(me->num + 1, 3);
- if (me->type == MENU_ENTRY_BOX) {
+ switch (me->type) {
+ case MENU_ENTRY_BOX:
if (me->box_state)
puts("[*]");
else
puts("[ ]");
- } else {
+ break;
+ case MENU_ENTRY_DISABLE:
+ puts(" - ");
+ break;
+ default:
puts(" ");
}
@@ -195,7 +201,7 @@ int menu_set_selected_entry(struct menu *m, struct menu_entry* me)
{
struct menu_entry* tmp;
- if (!m || !me)
+ if (!m || !me || me->type == MENU_ENTRY_DISABLE)
return -EINVAL;
list_for_each_entry(tmp, &m->entries, list) {
@@ -215,7 +221,7 @@ int menu_set_selected(struct menu *m, int num)
me = menu_entry_get_by_num(m, num);
- if (!me)
+ if (!me || me->type == MENU_ENTRY_DISABLE)
return -EINVAL;
m->selected = me;
@@ -260,8 +266,10 @@ static void print_menu(struct menu *m)
}
if (!m->selected) {
- m->selected = list_first_entry(&m->entries,
- struct menu_entry, list);
+ list_for_each_entry(me, &m->entries, list) {
+ if (me->type != MENU_ENTRY_DISABLE)
+ m->selected = me;
+ }
}
print_menu_entry(m, m->selected, 1);
@@ -351,6 +359,7 @@ int menu_show(struct menu *m)
ch = getc();
m->auto_select = -1;
+redo:
switch(ch) {
case 0x1b:
@@ -368,6 +377,8 @@ int menu_show(struct menu *m)
m->selected = list_entry(m->selected->list.prev, struct menu_entry,
list);
}
+ if (m->selected->type == MENU_ENTRY_DISABLE)
+ goto redo;
print_menu_entry(m, m->selected, 1);
break;
case 'B': /* down */
@@ -379,6 +390,8 @@ int menu_show(struct menu *m)
m->selected = list_entry(m->selected->list.next, struct menu_entry,
list);
}
+ if (m->selected->type == MENU_ENTRY_DISABLE)
+ goto redo;
print_menu_entry(m, m->selected, 1);
break;
case ' ':
@@ -513,21 +526,24 @@ struct menu_entry *menu_add_command_entry(struct menu *m, char *display,
char *command, menu_entry_type type)
{
struct action_entry *e = calloc(1, sizeof(*e));
- int ret;
+ int ret = -ENOMEM;
if (!e)
return ERR_PTR(-ENOMEM);
- e->command = strdup(command);
- e->entry.action = menu_action_command;
- e->entry.free = menu_command_free;
+ if (type != MENU_ENTRY_DISABLE) {
+ e->command = strdup(command);
+ e->entry.action = menu_action_command;
+ e->entry.free = menu_command_free;
+
+ if (!e->command)
+ goto err_free;
+ }
e->entry.type = type;
e->entry.display = strdup(display);
- if (!e->entry.display || !e->command) {
- ret = -ENOMEM;
+ if (!e->entry.display)
goto err_free;
- }
ret = menu_add_entry(m, &e->entry);
if (ret)
--git a/include/menu.h b/include/menu.h
index 5a7e8ca..cd4a323 100644
--- a/include/menu.h
+++ b/include/menu.h
@@ -31,6 +31,7 @@ struct menu;
typedef enum {
MENU_ENTRY_NORMAL = 0,
MENU_ENTRY_BOX,
+ MENU_ENTRY_DISABLE,
} menu_entry_type;
struct menu_entry {
--
1.7.9.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] menu: add support for disable entry
2012-05-27 13:57 ` [PATCH 2/2] menu: add support for disable entry Jean-Christophe PLAGNIOL-VILLARD
@ 2012-05-29 8:35 ` Sascha Hauer
2012-05-29 10:35 ` Jean-Christophe PLAGNIOL-VILLARD
0 siblings, 1 reply; 5+ messages in thread
From: Sascha Hauer @ 2012-05-29 8:35 UTC (permalink / raw)
To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox
On Sun, May 27, 2012 at 03:57:13PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> ---
> .../arm/boards/at91sam9m10g45ek/env/bin/boot_board | 2 +
> commands/menu.c | 15 +++++-
> common/menu.c | 44 +++++++++++++------
> include/menu.h | 1 +
> 4 files changed, 45 insertions(+), 17 deletions(-)
>
> @@ -450,6 +458,7 @@ static const __maybe_unused char cmd_menu_help[] =
> "Add an entry\n"
> " (-R for do no exit the menu after executing the command)\n"
> " (-b for box style 1 for selected)\n"
> +" (-D for disabel style command is not needed)\n"
s/disabel/disable/
Better talk about comment lines instead? If I understand this patch
correctly that's what it does.
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] menu: add support for disable entry
2012-05-29 8:35 ` Sascha Hauer
@ 2012-05-29 10:35 ` Jean-Christophe PLAGNIOL-VILLARD
0 siblings, 0 replies; 5+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-05-29 10:35 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
On 10:35 Tue 29 May , Sascha Hauer wrote:
> On Sun, May 27, 2012 at 03:57:13PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> > ---
> > .../arm/boards/at91sam9m10g45ek/env/bin/boot_board | 2 +
> > commands/menu.c | 15 +++++-
> > common/menu.c | 44 +++++++++++++------
> > include/menu.h | 1 +
> > 4 files changed, 45 insertions(+), 17 deletions(-)
> >
> > @@ -450,6 +458,7 @@ static const __maybe_unused char cmd_menu_help[] =
> > "Add an entry\n"
> > " (-R for do no exit the menu after executing the command)\n"
> > " (-b for box style 1 for selected)\n"
> > +" (-D for disabel style command is not needed)\n"
>
> s/disabel/disable/
>
> Better talk about comment lines instead? If I understand this patch
> correctly that's what it does.
yes and no as I get in mind to beable to change the type of the menu_entry at
runtime
Best Regards,
J.
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] menu: add support to do not display the entry number
2012-05-27 13:57 [PATCH 1/2] menu: add support to do not display the entry number Jean-Christophe PLAGNIOL-VILLARD
2012-05-27 13:57 ` [PATCH 2/2] menu: add support for disable entry Jean-Christophe PLAGNIOL-VILLARD
@ 2012-06-01 6:34 ` Sascha Hauer
1 sibling, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2012-06-01 6:34 UTC (permalink / raw)
To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox
On Sun, May 27, 2012 at 03:57:12PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> ---
> @@ -416,6 +421,7 @@ static const __maybe_unused char cmd_menu_help[] =
> " -m menu\n"
> " -l list\n"
> " -s show\n"
> +" -N do not display number\n"
'do not number menu entries'?
Sascha
> #if defined(CONFIG_CMD_MENU_MANAGEMENT)
> "Advanced\n"
> " -e menu entry\n"
> diff --git a/common/menu.c b/common/menu.c
> index 070170e..12812a5 100644
> --- a/common/menu.c
> +++ b/common/menu.c
> @@ -178,7 +178,8 @@ static void print_menu_entry(struct menu *m, struct menu_entry *me,
> process_escape_sequence(me->display, m->display_buffer,
> m->display_buffer_size);
>
> - printf(" %d: ", me->num);
> + if (m->display_num)
> + printf(" %d: ", me->num);
> if (selected)
> puts("\e[7m");
> if (IS_ENABLED(CONFIG_SHELL_HUSH))
> diff --git a/include/menu.h b/include/menu.h
> index 74abcfb..5a7e8ca 100644
> --- a/include/menu.h
> +++ b/include/menu.h
> @@ -56,6 +56,8 @@ struct menu {
> int auto_select;
> char *auto_display;
>
> + int display_num;
> +
> struct list_head list;
> struct list_head entries;
>
> --
> 1.7.9.1
>
>
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
>
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2012-06-01 6:34 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-27 13:57 [PATCH 1/2] menu: add support to do not display the entry number Jean-Christophe PLAGNIOL-VILLARD
2012-05-27 13:57 ` [PATCH 2/2] menu: add support for disable entry Jean-Christophe PLAGNIOL-VILLARD
2012-05-29 8:35 ` Sascha Hauer
2012-05-29 10:35 ` Jean-Christophe PLAGNIOL-VILLARD
2012-06-01 6:34 ` [PATCH 1/2] menu: add support to do not display the entry number Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox