From: Sascha Hauer <s.hauer@pengutronix.de>
To: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 1/1] menu: export box state to menu_box_state when using a command
Date: Fri, 1 Jun 2012 08:33:07 +0200 [thread overview]
Message-ID: <20120601063307.GF30400@pengutronix.de> (raw)
In-Reply-To: <1338114992-13130-1-git-send-email-plagnioj@jcrosoft.com>
On Sun, May 27, 2012 at 12:36:32PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> this will allow to have different action based on the box state in shell
>
> as example
> menu -e -a -m boot -c 'export test=${menu_box_state}' -R -b 1 -d "yes/no"
>
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> ---
> common/menu.c | 5 +++++
> 1 files changed, 5 insertions(+), 0 deletions(-)
>
> diff --git a/common/menu.c b/common/menu.c
> index 6c530b6..070170e 100644
> --- a/common/menu.c
> +++ b/common/menu.c
> @@ -483,6 +483,11 @@ static void menu_action_command(struct menu *m, struct menu_entry *me)
> int ret;
> const char *s = getenv(e->command);
>
> + if (me->type == MENU_ENTRY_BOX)
> + export_env_ull("menu_box_state", me->box_state);
> + else
> + setenv("menu_box_state", "");
> +
> /* can be a command as boot */
> if (!s)
> s = e->command;
I suggest the following instead. It will cleanup the menu box state
right after executing the command and also it will call the box action
only when it actually has changed.
8<-----------------------------------------------------
menu: export menu box entry state to shell
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
| 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
--git a/common/menu.c b/common/menu.c
index 6c530b6..68c16ee 100644
--- a/common/menu.c
+++ b/common/menu.c
@@ -384,14 +384,19 @@ int menu_show(struct menu *m)
if (m->selected->type != MENU_ENTRY_BOX)
break;
m->selected->box_state = !m->selected->box_state;
- if (m->selected->action)
+ if (m->selected->action) {
+ export_env_ull("menu_box_state", me->box_state);
m->selected->action(m, m->selected);
+ setenv("menu_box_state", "");
+ }
print_menu_entry(m, m->selected, 1);
break;
case KEY_ENTER:
if (ch_previous == KEY_RETURN)
break;
case KEY_RETURN:
+ if (m->selected->type == MENU_ENTRY_BOX)
+ break;
if (ch_previous == KEY_ENTER)
break;
clear();
--
1.7.10
--
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
prev parent reply other threads:[~2012-06-01 6:33 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-27 10:36 Jean-Christophe PLAGNIOL-VILLARD
2012-06-01 6:33 ` Sascha Hauer [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120601063307.GF30400@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=plagnioj@jcrosoft.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox