summaryrefslogtreecommitdiffstats
path: root/common/menu.c
diff options
context:
space:
mode:
authorJean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>2010-09-17 15:45:54 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2010-09-20 08:58:53 +0200
commita47575911dfc360a95ae41585694c27aeb082f0a (patch)
treed23e59bc2ff53a3ff6a39964777ae75927fbb98c /common/menu.c
parent7923392c561136bd7ac3d9e28cc61c18be3a8b3f (diff)
downloadbarebox-a47575911dfc360a95ae41585694c27aeb082f0a.tar.gz
barebox-a47575911dfc360a95ae41585694c27aeb082f0a.tar.xz
Menu: add box style entry
this will allow you to create a box style entry via C API by specifying the type as struct menu_entry me = { .display "test", .type = MENU_ENTRY_BOX, .box_state = 1, .action = action_to_run, } and via shell menu -e -a -m <menu> -c <command> [-R] [-b 0|1] -d <description> menu -e -a -m <menu> -u submenu -d [-b 0|1] <description> -b with 0 for not selected and 1 for selected and -c for the command to run when changing state Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common/menu.c')
-rw-r--r--common/menu.c38
1 files changed, 32 insertions, 6 deletions
diff --git a/common/menu.c b/common/menu.c
index d15f85a6b7..8e3cb9b094 100644
--- a/common/menu.c
+++ b/common/menu.c
@@ -149,13 +149,26 @@ void menu_entry_free(struct menu_entry *me)
me->free(me);
}
-static void print_menu_entry(struct menu *m, struct menu_entry *me, int reverse)
+static void print_menu_entry(struct menu *m, struct menu_entry *me,
+ int selected)
{
gotoXY(me->num + 1, 3);
- if (reverse)
- printf_reverse("%d: %-*s", me->num, m->width, me->display);
- else
- printf("%d: %-*s", me->num, m->width, me->display);
+ if (selected)
+ printf("\e[7m");
+
+ if (me->type == MENU_ENTRY_BOX) {
+ if (me->box_state)
+ puts("[*]");
+ else
+ puts("[ ]");
+ } else {
+ puts(" ");
+ }
+
+ printf(" %d: %-*s", me->num, m->width, me->display);
+
+ if (selected)
+ printf("\e[m");
}
int menu_set_selected_entry(struct menu *m, struct menu_entry* me)
@@ -306,6 +319,14 @@ int menu_show(struct menu *m)
}
print_menu_entry(m, m->selected, 1);
break;
+ case ' ':
+ if (m->selected->type != MENU_ENTRY_BOX)
+ break;
+ m->selected->box_state = !m->selected->box_state;
+ if (m->selected->action)
+ m->selected->action(m, m->selected);
+ print_menu_entry(m, m->selected, 1);
+ break;
case '\n':
case '\r':
clear();
@@ -335,6 +356,9 @@ static void menu_action_show(struct menu *m, struct menu_entry *me)
struct submenu *s = container_of(me, struct submenu, entry);
struct menu *sm;
+ if (me->type == MENU_ENTRY_BOX && !me->box_state)
+ return;
+
sm = menu_get_by_name(s->submenu);
if (sm)
menu_show(sm);
@@ -410,7 +434,8 @@ static void menu_command_free(struct menu_entry *me)
free(e);
}
-struct menu_entry *menu_add_command_entry(struct menu *m, char *display, char *command)
+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;
@@ -421,6 +446,7 @@ struct menu_entry *menu_add_command_entry(struct menu *m, char *display, char *c
e->command = strdup(command);
e->entry.action = menu_action_command;
e->entry.free = menu_command_free;
+ e->entry.type = type;
e->entry.display = strdup(display);
if (!e->entry.display || !e->command) {