From patchwork Wed Jul 8 00:11:54 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geoff Levand X-Patchwork-Id: 29564 Return-Path: X-Original-To: patchwork-incoming@bilbo.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from ozlabs.org (ozlabs.org [203.10.76.45]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "mx.ozlabs.org", Issuer "CA Cert Signing Authority" (verified OK)) by bilbo.ozlabs.org (Postfix) with ESMTPS id 28341B708B for ; Wed, 8 Jul 2009 10:23:18 +1000 (EST) Received: by ozlabs.org (Postfix) id A90A4DE624; Wed, 8 Jul 2009 10:20:49 +1000 (EST) Delivered-To: patchwork-incoming@ozlabs.org Received: from ozlabs.org (localhost [127.0.0.1]) by ozlabs.org (Postfix) with ESMTP id A61B4DE011 for ; Wed, 8 Jul 2009 10:20:49 +1000 (EST) X-Original-To: cbe-oss-dev@ozlabs.org Delivered-To: cbe-oss-dev@ozlabs.org Received: from hera.kernel.org (hera.kernel.org [140.211.167.34]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 2E2C7DDF8C; Wed, 8 Jul 2009 10:18:23 +1000 (EST) Received: from hera.kernel.org (IDENT:U2FsdGVkX1+J3tXGJ9v+R2cUqP4VNdGK9bPf11hshpA@localhost [127.0.0.1]) by hera.kernel.org (8.14.2/8.14.2) with ESMTP id n680IH3V026664 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 8 Jul 2009 00:18:17 GMT Received: (from geoff@localhost) by hera.kernel.org (8.14.2/8.13.1/Submit) id n680IGC9026663; Wed, 8 Jul 2009 00:18:16 GMT Message-Id: <20090708001136.291775560@am.sony.com> User-Agent: quilt/0.47-1 Date: Tue, 07 Jul 2009 17:11:54 -0700 From: Geoff Levand To: Jeremy Kerr In-Reply-To: <20090708001134.934244536@am.sony.com> References: <20090708001134.934244536@am.sony.com> Content-Disposition: inline; filename=nc-user-item.diff X-Virus-Scanned: ClamAV 0.93.3/9541/Tue Jul 7 17:31:53 2009 on hera.kernel.org X-Virus-Status: Clean X-Spam-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00, UNPARSEABLE_RELAY autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on hera.kernel.org X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.0 (hera.kernel.org [127.0.0.1]); Wed, 08 Jul 2009 00:18:17 +0000 (UTC) Cc: cbe-oss-dev@ozlabs.org Subject: [Cbe-oss-dev] [patch 20/31] petitboot: CUI add empty item X-BeenThere: cbe-oss-dev@ozlabs.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: Discussion about Open Source Software for the Cell Broadband Engine List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: cbe-oss-dev-bounces+patchwork-incoming=ozlabs.org@ozlabs.org Errors-To: cbe-oss-dev-bounces+patchwork-incoming=ozlabs.org@ozlabs.org Add a CUI hot-key 'o' that opens a new empty menu item. Signed-off-by: Geoff Levand --- ui/ncurses/nc-cui.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++---- ui/ncurses/nc-cui.h | 6 ++++- ui/ncurses/nc-ked.c | 5 ++-- ui/ncurses/nc-menu.c | 7 ++++-- ui/ncurses/nc-menu.h | 1 ui/ncurses/pb-cui.c | 6 +++-- ui/ncurses/ps3-cui.c | 9 +++++--- 7 files changed, 72 insertions(+), 14 deletions(-) --- a/ui/ncurses/nc-cui.c +++ b/ui/ncurses/nc-cui.c @@ -108,8 +108,8 @@ static int cui_run_kexec(struct pmenu_it assert(cui->current == &cui->main->scr); assert(cui->on_kexec); - pb_log("%s: %s\n", __func__, cod->dev->name, cod->opt->name); - nc_scr_status_printf(cui->current, "Booting %s...", cod->opt->name); + pb_log("%s: %s\n", __func__, cod->name); + nc_scr_status_printf(cui->current, "Booting %s...", cod->name); def_prog_mode(); @@ -150,7 +150,7 @@ static void cui_ked_on_exit(struct ked * talloc_free(cod->kd); cod->kd = kd; - pb_log("%s: updating opt '%s'\n", __func__, cod->opt->name); + pb_log("%s: updating opt '%s'\n", __func__, cod->name); pb_log(" image '%s'\n", cod->kd->image); pb_log(" initrd '%s'\n", cod->kd->initrd); pb_log(" args '%s'\n", cod->kd->args); @@ -267,6 +267,49 @@ static void cui_handle_resize(struct cui } /** + * cui_on_open - Open new item callback. + */ + +void cui_on_open(struct pmenu *menu) +{ + unsigned int insert_pt; + struct pmenu_item *i; + struct cui_opt_data *cod; + char *name; + + menu->scr.unpost(&menu->scr); + + /* This disconnects items array from menu. */ + + set_menu_items(menu->ncm, NULL); + + /* Insert new items at insert_pt. */ + + insert_pt = pmenu_grow(menu, 1); + i = pmenu_item_alloc(menu); + + name = talloc_asprintf(i, "User item %u:", insert_pt); + pmenu_item_setup(menu, i, insert_pt, name, NULL); + + i->on_edit = cui_ked_run; + i->on_execute = cui_run_kexec; + i->data = cod = talloc_zero(i, struct cui_opt_data); + + cod->kd = talloc_zero(i, struct pb_kexec_data); + cod->name = name; + + /* Re-attach the items array. */ + + set_menu_items(menu->ncm, menu->items); + + set_current_item(menu->ncm, i->nci); + menu->scr.post(&menu->scr); + pos_menu_cursor(menu->ncm); + + i->on_edit(i); +} + +/** * cui_device_add - Client device_add callback. * * Creates menu_items for all the device boot_options and inserts those @@ -332,6 +375,7 @@ static int cui_device_add(struct device cod->dev = dev; cod->opt = opt; cod->opt_hash = pb_opt_hash(dev, opt); + cod->name = opt->name; cod->kd = talloc(i, struct pb_kexec_data); cod->kd->image = talloc_strdup(cod->kd, opt->boot_image_file); @@ -340,7 +384,7 @@ static int cui_device_add(struct device insert_pt++; - pb_log("%s: adding opt '%s'\n", __func__, cod->opt->name); + pb_log("%s: adding opt '%s'\n", __func__, cod->name); pb_log(" image '%s'\n", cod->kd->image); pb_log(" initrd '%s'\n", cod->kd->initrd); pb_log(" args '%s'\n", cod->kd->args); --- a/ui/ncurses/nc-cui.h +++ b/ui/ncurses/nc-cui.h @@ -26,10 +26,13 @@ #include "nc-ked.h" struct cui_opt_data { + const char *name; + struct pb_kexec_data *kd; + + /* optional data */ const struct device *dev; const struct boot_option *opt; uint32_t opt_hash; - struct pb_kexec_data *kd; }; /** @@ -66,6 +69,7 @@ int cui_ked_run(struct pmenu_item *item) void cui_abort(struct cui *cui); void cui_resize(struct cui *cui); void cui_on_exit(struct pmenu *menu); +void cui_on_open(struct pmenu *menu); int cui_run_cmd(struct pmenu_item *item); static inline struct cui *cui_from_arg(void *arg) --- a/ui/ncurses/nc-ked.c +++ b/ui/ncurses/nc-ked.c @@ -149,9 +149,10 @@ static char *ked_chomp(char *s) for (; s < s_end; s++) if (*s != ' ' && *s != '\t') break; - start = s; - for (++s; s < s_end; s++) + start = end = s; + + for (; s < s_end; s++) if (*s != ' ' && *s != '\t') end = s; *(end + 1) = 0; --- a/ui/ncurses/nc-menu.c +++ b/ui/ncurses/nc-menu.c @@ -174,13 +174,16 @@ static void pmenu_process_key(struct nc_ case '\t': pmenu_move_cursor(menu, REQ_DOWN_ITEM); break; - case KEY_LEFT: - case 'E': case 'e': if (item->on_edit) item->on_edit(item); break; + case 'o': + DBGS("on_open: %p\n", menu->on_open); + if (menu->on_open) + menu->on_open(menu); + break; case '\n': case '\r': if (item->on_execute) --- a/ui/ncurses/nc-menu.h +++ b/ui/ncurses/nc-menu.h @@ -77,6 +77,7 @@ struct pmenu { unsigned int insert_pt; int (*hot_key)(struct pmenu *menu, struct pmenu_item *item, int c); void (*on_exit)(struct pmenu *menu); + void (*on_open)(struct pmenu *menu); }; struct pmenu *pmenu_init(void *ui_ctx, unsigned int item_count, --- a/ui/ncurses/pb-cui.c +++ b/ui/ncurses/pb-cui.c @@ -138,7 +138,7 @@ static int pb_kexec_cb(struct cui *cui, { struct pb_cui *pb = pb_from_cui(cui); - pb_log("%s: %s:%s\n", __func__, cod->dev->name, cod->opt->name); + pb_log("%s: %s\n", __func__, cod->name); assert(pb->cui->current == &pb->cui->main->scr); @@ -162,9 +162,11 @@ static struct pmenu *pb_mm_init(struct p return NULL; } + m->on_open = cui_on_open; + m->scr.frame.title = talloc_strdup(m, "Petitboot"); m->scr.frame.help = talloc_strdup(m, - "ESC=exit, Enter=accept, E,e=edit"); + "ESC=exit, Enter=accept, e=edit, o=open"); m->scr.frame.status = talloc_strdup(m, "Welcome to Petitboot"); i = pmenu_item_init(m, 0, "Exit to Shell", --- a/ui/ncurses/ps3-cui.c +++ b/ui/ncurses/ps3-cui.c @@ -199,11 +199,12 @@ static int ps3_kexec_cb(struct cui *cui, { struct ps3_cui *ps3 = ps3_from_cui(cui); - pb_log("%s: %s:%s\n", __func__, cod->dev->name, cod->opt->name); + pb_log("%s: %s\n", __func__, cod->name); assert(ps3->cui->current == &ps3->cui->main->scr); - if (cui->default_item != cod->opt_hash || ps3->dirty_values) { + if ((cod->opt_hash && cod->opt_hash != cui->default_item) + || ps3->dirty_values) { ps3->values.default_item = cod->opt_hash; ps3_flash_set_values(&ps3->values); } @@ -326,6 +327,8 @@ static struct pmenu *ps3_mm_init(struct } m->hot_key = ps3_hot_key; + m->on_open = cui_on_open; + #if defined(DEBUG) m->scr.frame.title = talloc_strdup(m, "Petitboot PS3 (ver " PACKAGE_VERSION ")"); @@ -333,7 +336,7 @@ static struct pmenu *ps3_mm_init(struct m->scr.frame.title = talloc_strdup(m, "Petitboot PS3"); #endif m->scr.frame.help = talloc_strdup(m, - "ESC=exit, Enter=accept, E,e=edit"); + "ESC=exit, Enter=accept, e=edit, o=open"); m->scr.frame.status = talloc_strdup(m, "Welcome to Petitboot"); i = pmenu_item_init(m, 0, "Boot GameOS",