* [PATCH] Menu: add box stype entry
@ 2010-09-05 15:23 Jean-Christophe PLAGNIOL-VILLARD
2010-09-05 16:03 ` [PATCH V2] Menu: add box style entry Jean-Christophe PLAGNIOL-VILLARD
0 siblings, 1 reply; 6+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2010-09-05 15:23 UTC (permalink / raw)
To: barebox
this will allow you to create a box style entry
via C API by specifying the type as
struct menu_entry me = {
.display "test",
.box_state = MENU_ENTRY_BOX,
.box_action = action_to_run,
}
and via shell
menu -e -a -m <menu> -c <command> [-R] [-b 0|1 -B <select action>] -d <description>
menu -e -a -m <menu> -u submenu -d [-b 0|1 -B <select action>] <description>
-b with 0 for not selected and 1 for selected
and -B for the command to run when changing state
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
commands/menu.c | 31 ++++++++++++++++++++++++-----
| 56 ++++++++++++++++++++++++++++++++++++++++++++++++++----
| 14 ++++++++++++-
3 files changed, 89 insertions(+), 12 deletions(-)
diff --git a/commands/menu.c b/commands/menu.c
index f734db3..e502709 100644
--- a/commands/menu.c
+++ b/commands/menu.c
@@ -48,11 +48,14 @@ struct cmd_menu {
char *command;
char *submenu;
int num;
+ menu_entry_type type;
+ int box_state;
+ char *box_command;
#endif
};
#if defined(CONFIG_CMD_MENU_MANAGEMENT)
-#define OPTS "m:earlc:d:RsSn:u:"
+#define OPTS "m:earlc:d:RsSn:u:b:B:"
#define is_entry(x) ((x)->entry)
#else
#define OPTS "m:ls"
@@ -61,8 +64,8 @@ struct cmd_menu {
#if defined(CONFIG_CMD_MENU_MANAGEMENT)
/*
- * menu -e -a -m <menu> -c <command> [-R] -d <description>
- * menu -e -a -m <menu> -u submenu -d <description>
+ * menu -e -a -m <menu> -c <command> [-R] [-b 0|1 -B <select action>] -d <description>
+ * menu -e -a -m <menu> -u submenu -d [-b 0|1 -B <select action>] <description>
*/
static int do_menu_entry_add(struct cmd_menu *cm)
{
@@ -82,10 +85,15 @@ static int do_menu_entry_add(struct cmd_menu *cm)
if (cm->submenu)
me = menu_add_submenu(m, cm->submenu, cm->description);
else
- me = menu_add_command_entry(m, cm->description, cm->command);
+ me = menu_add_command_entry(m, cm->description, cm->command,
+ cm->box_command);
if (!me)
return PTR_ERR(me);
+ me->type = cm->type;
+
+ me->box_state = cm->box_state > 0 ? 1 : 0;
+
me->non_re_ent = !cm->re_entrant;
return 0;
@@ -343,6 +351,13 @@ static int do_menu(struct command *cmdtp, int argc, char *argv[])
case 'n':
cm.num = simple_strtoul(optarg, NULL, 10);
break;
+ case 'b':
+ cm.type = MENU_ENTRY_BOX;
+ cm.box_state = simple_strtoul(optarg, NULL, 10);
+ break;
+ case 'B':
+ cm.command = optarg;
+ break;
#endif
default:
return 1;
@@ -412,11 +427,15 @@ static const __maybe_unused char cmd_menu_help[] =
"\n"
"Add an entry\n"
" (-R for do no exit the menu after executing the command)\n"
-" menu -e -a -m <menu> -c <command> [-R] -d <description>\n"
+" (-b for box style 1 for selected)\n"
+" (and -B for the command to run when we change the state)\n"
+" menu -e -a -m <menu> -c <command> [-R] [-b 0|1 -B <select action>] -d <description>\n"
"Add a submenu entry\n"
" (-R is not needed)\n"
-" menu -e -a -m <menu> -u <menu> -d <description>\n"
+" (-b for box style 1 for selected)\n"
+" (and -B for the command to run when we change the state)\n"
+" menu -e -a -m <menu> -u submenu -d [-b 0|1 -B <select action>] <description>\n"
"\n"
"Remove an entry\n"
" menu -e -r -m <name> -n <num>\n"
--git a/common/menu.c b/common/menu.c
index 7620d9e..0590c7e 100644
--- a/common/menu.c
+++ b/common/menu.c
@@ -150,10 +150,27 @@ void menu_entry_free(struct menu_entry *me)
static void print_menu_entry(struct menu *m, struct menu_entry *me, int reverse)
{
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 (reverse) {
+ if (me->type == MENU_ENTRY_BOX) {
+ if (me->box_state)
+ puts_reverse("[*]");
+ else
+ puts_reverse("[ ]");
+ } else {
+ printf_reverse(" ");
+ }
+ printf_reverse(" %d: %-*s", me->num, m->width, me->display);
+ } else {
+ if (me->type == MENU_ENTRY_BOX) {
+ if (me->box_state)
+ puts("[*]");
+ else
+ puts("[ ]");
+ } else {
+ puts(" ");
+ }
+ printf(" %d: %-*s", me->num, m->width, me->display);
+ }
}
int menu_set_selected_entry(struct menu *m, struct menu_entry* me)
@@ -254,6 +271,12 @@ int menu_show(struct menu *m)
}
print_menu_entry(m, m->selected, 1);
break;
+ case ' ':
+ m->selected->box_state = !m->selected->box_state;
+ if (m->selected->box_action)
+ m->selected->box_action(m, m->selected);
+ print_menu_entry(m, m->selected, 1);
+ break;
case '\n':
case '\r':
clear();
@@ -329,6 +352,7 @@ err_free:
struct action_entry {
char *command;
+ char *box_command;
struct menu_entry entry;
};
@@ -348,17 +372,35 @@ static void menu_action_command(struct menu *m, struct menu_entry *me)
udelay(1000000);
}
+static void menu_action_box_command(struct menu *m, struct menu_entry *me)
+{
+ struct action_entry *e = container_of(me, struct action_entry, entry);
+ int ret;
+ const char *s = getenv(e->box_command);
+
+ /* can be a command as boot */
+ if (!s)
+ s = e->box_command;
+
+ ret = run_command (s, 0);
+
+ if (ret < 0)
+ udelay(1000000);
+}
+
static void menu_command_free(struct menu_entry *me)
{
struct action_entry *e = container_of(me, struct action_entry, entry);
free(e->entry.display);
free(e->command);
+ free(e->box_command);
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, char* box_command)
{
struct action_entry *e = calloc(1, sizeof(*e));
int ret;
@@ -370,6 +412,10 @@ struct menu_entry *menu_add_command_entry(struct menu *m, char *display, char *c
e->entry.action = menu_action_command;
e->entry.free = menu_command_free;
e->entry.display = strdup(display);
+ if (box_command) {
+ e->box_command = strdup(box_command);
+ e->entry.box_action = menu_action_box_command;
+ }
if (!e->entry.display || !e->command) {
ret = -ENOMEM;
--git a/include/menu.h b/include/menu.h
index 22bfc23..f824894 100644
--- a/include/menu.h
+++ b/include/menu.h
@@ -28,6 +28,11 @@
struct menu;
+typedef enum {
+ MENU_ENTRY_NORMAL = 0,
+ MENU_ENTRY_BOX,
+} menu_entry_type;
+
struct menu_entry {
int num;
char *display;
@@ -35,6 +40,12 @@ struct menu_entry {
void (*free)(struct menu_entry *me);
int non_re_ent;
+ /* MENU_ENTRY_BOX */
+ int box_state;
+ void (*box_action)(struct menu *m, struct menu_entry *me);
+
+ menu_entry_type type;
+
struct list_head list;
};
@@ -66,7 +77,8 @@ static inline struct menu* menu_alloc(void)
return m;
}
struct menu_entry *menu_add_submenu(struct menu *parent, char *submenu, char *display);
-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, char* box_command);
void menu_free(struct menu *m);
int menu_add(struct menu* m);
void menu_remove(struct menu *m);
--
1.7.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH V2] Menu: add box style entry
2010-09-05 15:23 [PATCH] Menu: add box stype entry Jean-Christophe PLAGNIOL-VILLARD
@ 2010-09-05 16:03 ` Jean-Christophe PLAGNIOL-VILLARD
2010-09-16 10:53 ` Sascha Hauer
0 siblings, 1 reply; 6+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2010-09-05 16:03 UTC (permalink / raw)
To: barebox
this will allow you to create a box style entry
via C API by specifying the type as
struct menu_entry me = {
.display "test",
.box_state = MENU_ENTRY_BOX,
.box_action = action_to_run,
}
and via shell
menu -e -a -m <menu> -c <command> [-R] [-b 0|1 -B <select action>] -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 -B for the command to run when changing state
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
v2:
fix subject
fix shell doc as submenu does not need select action as the they will
simply do nothing if not selected
Best Regards,
J.
commands/menu.c | 34 +++++++++++++++++++++++++------
| 59 ++++++++++++++++++++++++++++++++++++++++++++++++++----
| 14 ++++++++++++-
3 files changed, 94 insertions(+), 13 deletions(-)
diff --git a/commands/menu.c b/commands/menu.c
index f734db3..0d49232 100644
--- a/commands/menu.c
+++ b/commands/menu.c
@@ -48,11 +48,14 @@ struct cmd_menu {
char *command;
char *submenu;
int num;
+ menu_entry_type type;
+ int box_state;
+ char *box_command;
#endif
};
#if defined(CONFIG_CMD_MENU_MANAGEMENT)
-#define OPTS "m:earlc:d:RsSn:u:"
+#define OPTS "m:earlc:d:RsSn:u:b:B:"
#define is_entry(x) ((x)->entry)
#else
#define OPTS "m:ls"
@@ -61,8 +64,8 @@ struct cmd_menu {
#if defined(CONFIG_CMD_MENU_MANAGEMENT)
/*
- * menu -e -a -m <menu> -c <command> [-R] -d <description>
- * menu -e -a -m <menu> -u submenu -d <description>
+ * menu -e -a -m <menu> -c <command> [-R] [-b 0|1 -B <select action>] -d <description>
+ * menu -e -a -m <menu> -u submenu -d [-b 0|1] <description>
*/
static int do_menu_entry_add(struct cmd_menu *cm)
{
@@ -82,11 +85,17 @@ static int do_menu_entry_add(struct cmd_menu *cm)
if (cm->submenu)
me = menu_add_submenu(m, cm->submenu, cm->description);
else
- me = menu_add_command_entry(m, cm->description, cm->command);
+ me = menu_add_command_entry(m, cm->description, cm->command,
+ cm->box_command);
if (!me)
return PTR_ERR(me);
- me->non_re_ent = !cm->re_entrant;
+ me->type = cm->type;
+
+ me->box_state = cm->box_state > 0 ? 1 : 0;
+
+ if (!cm->submenu)
+ me->non_re_ent = !cm->re_entrant;
return 0;
}
@@ -343,6 +352,13 @@ static int do_menu(struct command *cmdtp, int argc, char *argv[])
case 'n':
cm.num = simple_strtoul(optarg, NULL, 10);
break;
+ case 'b':
+ cm.type = MENU_ENTRY_BOX;
+ cm.box_state = simple_strtoul(optarg, NULL, 10);
+ break;
+ case 'B':
+ cm.command = optarg;
+ break;
#endif
default:
return 1;
@@ -412,11 +428,15 @@ static const __maybe_unused char cmd_menu_help[] =
"\n"
"Add an entry\n"
" (-R for do no exit the menu after executing the command)\n"
-" menu -e -a -m <menu> -c <command> [-R] -d <description>\n"
+" (-b for box style 1 for selected)\n"
+" (and -B for the command to run when we change the state)\n"
+" menu -e -a -m <menu> -c <command> [-R] [-b 0|1 -B <select action>] -d <description>\n"
"Add a submenu entry\n"
" (-R is not needed)\n"
-" menu -e -a -m <menu> -u <menu> -d <description>\n"
+" (-b for box style 1 for selected)\n"
+" (and -B is not needed)\n"
+" menu -e -a -m <menu> -u submenu -d [-b 0|1 -B <select action>] <description>\n"
"\n"
"Remove an entry\n"
" menu -e -r -m <name> -n <num>\n"
--git a/common/menu.c b/common/menu.c
index 7620d9e..82fea1d 100644
--- a/common/menu.c
+++ b/common/menu.c
@@ -150,10 +150,27 @@ void menu_entry_free(struct menu_entry *me)
static void print_menu_entry(struct menu *m, struct menu_entry *me, int reverse)
{
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 (reverse) {
+ if (me->type == MENU_ENTRY_BOX) {
+ if (me->box_state)
+ puts_reverse("[*]");
+ else
+ puts_reverse("[ ]");
+ } else {
+ printf_reverse(" ");
+ }
+ printf_reverse(" %d: %-*s", me->num, m->width, me->display);
+ } else {
+ if (me->type == MENU_ENTRY_BOX) {
+ if (me->box_state)
+ puts("[*]");
+ else
+ puts("[ ]");
+ } else {
+ puts(" ");
+ }
+ printf(" %d: %-*s", me->num, m->width, me->display);
+ }
}
int menu_set_selected_entry(struct menu *m, struct menu_entry* me)
@@ -254,6 +271,12 @@ int menu_show(struct menu *m)
}
print_menu_entry(m, m->selected, 1);
break;
+ case ' ':
+ m->selected->box_state = !m->selected->box_state;
+ if (m->selected->box_action)
+ m->selected->box_action(m, m->selected);
+ print_menu_entry(m, m->selected, 1);
+ break;
case '\n':
case '\r':
clear();
@@ -283,6 +306,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);
@@ -329,6 +355,7 @@ err_free:
struct action_entry {
char *command;
+ char *box_command;
struct menu_entry entry;
};
@@ -348,17 +375,35 @@ static void menu_action_command(struct menu *m, struct menu_entry *me)
udelay(1000000);
}
+static void menu_action_box_command(struct menu *m, struct menu_entry *me)
+{
+ struct action_entry *e = container_of(me, struct action_entry, entry);
+ int ret;
+ const char *s = getenv(e->box_command);
+
+ /* can be a command as boot */
+ if (!s)
+ s = e->box_command;
+
+ ret = run_command (s, 0);
+
+ if (ret < 0)
+ udelay(1000000);
+}
+
static void menu_command_free(struct menu_entry *me)
{
struct action_entry *e = container_of(me, struct action_entry, entry);
free(e->entry.display);
free(e->command);
+ free(e->box_command);
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, char* box_command)
{
struct action_entry *e = calloc(1, sizeof(*e));
int ret;
@@ -370,6 +415,10 @@ struct menu_entry *menu_add_command_entry(struct menu *m, char *display, char *c
e->entry.action = menu_action_command;
e->entry.free = menu_command_free;
e->entry.display = strdup(display);
+ if (box_command) {
+ e->box_command = strdup(box_command);
+ e->entry.box_action = menu_action_box_command;
+ }
if (!e->entry.display || !e->command) {
ret = -ENOMEM;
--git a/include/menu.h b/include/menu.h
index 22bfc23..f824894 100644
--- a/include/menu.h
+++ b/include/menu.h
@@ -28,6 +28,11 @@
struct menu;
+typedef enum {
+ MENU_ENTRY_NORMAL = 0,
+ MENU_ENTRY_BOX,
+} menu_entry_type;
+
struct menu_entry {
int num;
char *display;
@@ -35,6 +40,12 @@ struct menu_entry {
void (*free)(struct menu_entry *me);
int non_re_ent;
+ /* MENU_ENTRY_BOX */
+ int box_state;
+ void (*box_action)(struct menu *m, struct menu_entry *me);
+
+ menu_entry_type type;
+
struct list_head list;
};
@@ -66,7 +77,8 @@ static inline struct menu* menu_alloc(void)
return m;
}
struct menu_entry *menu_add_submenu(struct menu *parent, char *submenu, char *display);
-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, char* box_command);
void menu_free(struct menu *m);
int menu_add(struct menu* m);
void menu_remove(struct menu *m);
--
1.7.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH V2] Menu: add box style entry
2010-09-05 16:03 ` [PATCH V2] Menu: add box style entry Jean-Christophe PLAGNIOL-VILLARD
@ 2010-09-16 10:53 ` Sascha Hauer
2010-09-16 12:09 ` Jean-Christophe PLAGNIOL-VILLARD
0 siblings, 1 reply; 6+ messages in thread
From: Sascha Hauer @ 2010-09-16 10:53 UTC (permalink / raw)
To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox
On Sun, Sep 05, 2010 at 06:03:47PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> this will allow you to create a box style entry
>
> via C API by specifying the type as
>
> struct menu_entry me = {
> .display "test",
> .box_state = MENU_ENTRY_BOX,
> .box_action = action_to_run,
> }
>
> and via shell
> menu -e -a -m <menu> -c <command> [-R] [-b 0|1 -B <select action>] -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 -B for the command to run when changing state
>
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> ---
> v2:
>
> fix subject
>
> fix shell doc as submenu does not need select action as the they will
> simply do nothing if not selected
>
> Best Regards,
> J.
> commands/menu.c | 34 +++++++++++++++++++++++++------
> common/menu.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++----
> include/menu.h | 14 ++++++++++++-
> 3 files changed, 94 insertions(+), 13 deletions(-)
>
> diff --git a/commands/menu.c b/commands/menu.c
> index f734db3..0d49232 100644
> --- a/commands/menu.c
> +++ b/commands/menu.c
> @@ -48,11 +48,14 @@ struct cmd_menu {
> char *command;
> char *submenu;
> int num;
> + menu_entry_type type;
> + int box_state;
> + char *box_command;
> #endif
> };
>
> #if defined(CONFIG_CMD_MENU_MANAGEMENT)
> -#define OPTS "m:earlc:d:RsSn:u:"
> +#define OPTS "m:earlc:d:RsSn:u:b:B:"
> #define is_entry(x) ((x)->entry)
> #else
> #define OPTS "m:ls"
> @@ -61,8 +64,8 @@ struct cmd_menu {
>
> #if defined(CONFIG_CMD_MENU_MANAGEMENT)
> /*
> - * menu -e -a -m <menu> -c <command> [-R] -d <description>
> - * menu -e -a -m <menu> -u submenu -d <description>
> + * menu -e -a -m <menu> -c <command> [-R] [-b 0|1 -B <select action>] -d <description>
> + * menu -e -a -m <menu> -u submenu -d [-b 0|1] <description>
> */
> static int do_menu_entry_add(struct cmd_menu *cm)
> {
> @@ -82,11 +85,17 @@ static int do_menu_entry_add(struct cmd_menu *cm)
> if (cm->submenu)
> me = menu_add_submenu(m, cm->submenu, cm->description);
> else
> - me = menu_add_command_entry(m, cm->description, cm->command);
> + me = menu_add_command_entry(m, cm->description, cm->command,
> + cm->box_command);
> if (!me)
> return PTR_ERR(me);
>
> - me->non_re_ent = !cm->re_entrant;
> + me->type = cm->type;
> +
> + me->box_state = cm->box_state > 0 ? 1 : 0;
> +
> + if (!cm->submenu)
> + me->non_re_ent = !cm->re_entrant;
>
> return 0;
> }
> @@ -343,6 +352,13 @@ static int do_menu(struct command *cmdtp, int argc, char *argv[])
> case 'n':
> cm.num = simple_strtoul(optarg, NULL, 10);
> break;
> + case 'b':
> + cm.type = MENU_ENTRY_BOX;
> + cm.box_state = simple_strtoul(optarg, NULL, 10);
> + break;
> + case 'B':
> + cm.command = optarg;
> + break;
> #endif
> default:
> return 1;
> @@ -412,11 +428,15 @@ static const __maybe_unused char cmd_menu_help[] =
> "\n"
> "Add an entry\n"
> " (-R for do no exit the menu after executing the command)\n"
> -" menu -e -a -m <menu> -c <command> [-R] -d <description>\n"
> +" (-b for box style 1 for selected)\n"
> +" (and -B for the command to run when we change the state)\n"
> +" menu -e -a -m <menu> -c <command> [-R] [-b 0|1 -B <select action>] -d <description>\n"
>
> "Add a submenu entry\n"
> " (-R is not needed)\n"
> -" menu -e -a -m <menu> -u <menu> -d <description>\n"
> +" (-b for box style 1 for selected)\n"
> +" (and -B is not needed)\n"
> +" menu -e -a -m <menu> -u submenu -d [-b 0|1 -B <select action>] <description>\n"
> "\n"
> "Remove an entry\n"
> " menu -e -r -m <name> -n <num>\n"
> diff --git a/common/menu.c b/common/menu.c
> index 7620d9e..82fea1d 100644
> --- a/common/menu.c
> +++ b/common/menu.c
> @@ -150,10 +150,27 @@ void menu_entry_free(struct menu_entry *me)
> static void print_menu_entry(struct menu *m, struct menu_entry *me, int reverse)
> {
> 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 (reverse) {
> + if (me->type == MENU_ENTRY_BOX) {
> + if (me->box_state)
> + puts_reverse("[*]");
> + else
> + puts_reverse("[ ]");
> + } else {
> + printf_reverse(" ");
> + }
> + printf_reverse(" %d: %-*s", me->num, m->width, me->display);
> + } else {
> + if (me->type == MENU_ENTRY_BOX) {
> + if (me->box_state)
> + puts("[*]");
> + else
> + puts("[ ]");
> + } else {
> + puts(" ");
> + }
> + printf(" %d: %-*s", me->num, m->width, me->display);
> + }
I think this could look a bit simpler if we had a
static int printf_menu(int selected, const char *fmt, ...) function.
'selected' is a better name for the argument. with 'reverse' my first
thought was that it prints backwards...
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] 6+ messages in thread
* Re: [PATCH V2] Menu: add box style entry
2010-09-16 10:53 ` Sascha Hauer
@ 2010-09-16 12:09 ` Jean-Christophe PLAGNIOL-VILLARD
2010-09-16 13:55 ` Sascha Hauer
0 siblings, 1 reply; 6+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2010-09-16 12:09 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
> > + } else {
> > + puts(" ");
> > + }
> > + printf(" %d: %-*s", me->num, m->width, me->display);
> > + }
>
> I think this could look a bit simpler if we had a
> static int printf_menu(int selected, const char *fmt, ...) function.
> 'selected' is a better name for the argument. with 'reverse' my first
> thought was that it prints backwards...
sorry I do not follow
Best Regards,
J.
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH V2] Menu: add box style entry
2010-09-16 12:09 ` Jean-Christophe PLAGNIOL-VILLARD
@ 2010-09-16 13:55 ` Sascha Hauer
2010-09-16 16:00 ` Jean-Christophe PLAGNIOL-VILLARD
0 siblings, 1 reply; 6+ messages in thread
From: Sascha Hauer @ 2010-09-16 13:55 UTC (permalink / raw)
To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox
On Thu, Sep 16, 2010 at 02:09:56PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > > + } else {
> > > + puts(" ");
> > > + }
> > > + printf(" %d: %-*s", me->num, m->width, me->display);
> > > + }
> >
> > I think this could look a bit simpler if we had a
> > static int printf_menu(int selected, const char *fmt, ...) function.
> > 'selected' is a better name for the argument. with 'reverse' my first
> > thought was that it prints backwards...
> sorry I do not follow
The print_menu_entry would look simpler like this:
static void print_menu_entry(struct menu *m, struct menu_entry *me, int selected)
{
gotoXY(me->num + 1, 3);
if (selected)
printf("\e[7m");
if (me->type == MENU_ENTRY_BOX) {
if (me->box_state)
printf("[*]");
else
printf("[ ]");
} else {
printf(" ");
}
printf(" %d: %-*s", me->num, m->width, me->display);
if (selected)
printf("\e[m");
}
I was confused by the name of the printf_reverse macro. For me it was
not clear what it should do without looking at the macro definition.
Regards,
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] 6+ messages in thread
* Re: [PATCH V2] Menu: add box style entry
2010-09-16 13:55 ` Sascha Hauer
@ 2010-09-16 16:00 ` Jean-Christophe PLAGNIOL-VILLARD
0 siblings, 0 replies; 6+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2010-09-16 16:00 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
On 15:55 Thu 16 Sep , Sascha Hauer wrote:
> On Thu, Sep 16, 2010 at 02:09:56PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > > > + } else {
> > > > + puts(" ");
> > > > + }
> > > > + printf(" %d: %-*s", me->num, m->width, me->display);
> > > > + }
> > >
> > > I think this could look a bit simpler if we had a
> > > static int printf_menu(int selected, const char *fmt, ...) function.
> > > 'selected' is a better name for the argument. with 'reverse' my first
> > > thought was that it prints backwards...
> > sorry I do not follow
>
> The print_menu_entry would look simpler like this:
>
> static void print_menu_entry(struct menu *m, struct menu_entry *me, int selected)
> {
> gotoXY(me->num + 1, 3);
>
> if (selected)
> printf("\e[7m");
>
> if (me->type == MENU_ENTRY_BOX) {
> if (me->box_state)
> printf("[*]");
> else
> printf("[ ]");
> } else {
> printf(" ");
> }
>
> printf(" %d: %-*s", me->num, m->width, me->display);
>
> if (selected)
> printf("\e[m");
> }
>
> I was confused by the name of the printf_reverse macro. For me it was
> not clear what it should do without looking at the macro definition.
ok
Best Regards,
J.
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2010-09-16 16:01 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-05 15:23 [PATCH] Menu: add box stype entry Jean-Christophe PLAGNIOL-VILLARD
2010-09-05 16:03 ` [PATCH V2] Menu: add box style entry Jean-Christophe PLAGNIOL-VILLARD
2010-09-16 10:53 ` Sascha Hauer
2010-09-16 12:09 ` Jean-Christophe PLAGNIOL-VILLARD
2010-09-16 13:55 ` Sascha Hauer
2010-09-16 16:00 ` Jean-Christophe PLAGNIOL-VILLARD
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox