]> git.ozlabs.org Git - petitboot/blobdiff - ui/ncurses/nc-menu.c
ui/ncurses: Allow text wrapping in select widgets
[petitboot] / ui / ncurses / nc-menu.c
index a5794f7a63608067a7de2839ea1bee342dcd6161..3f09d62385b4df4043e985d965347aad13c905c1 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "log/log.h"
 #include "talloc/talloc.h"
+#include "i18n/i18n.h"
 #include "ui/common/ui-system.h"
 #include "nc-cui.h"
 #include "nc-menu.h"
@@ -61,7 +62,6 @@ static int pmenu_post(struct nc_scr *scr)
        result = post_menu(menu->ncm);
 
        nc_scr_frame_draw(scr);
-       redrawwin(menu->scr.main_ncw);
        wrefresh(menu->scr.main_ncw);
 
        return result;
@@ -99,7 +99,7 @@ static const char *pmenu_item_label(struct pmenu_item *item, const char *name)
        /* if we have an invalid multibyte sequence, create an entirely
         * new name, indicating that we had invalid input */
        if (len == SIZE_MAX) {
-               name = talloc_asprintf(item, "!Invalid option %d\n",
+               name = talloc_asprintf(item, _("!Invalid option %d"),
                                ++invalid_idx);
                return name;
        }
@@ -253,6 +253,7 @@ struct pmenu_item *pmenu_find_device(struct pmenu *menu, struct device *dev,
        switch (dev->type) {
        case DEVICE_TYPE_OPTICAL:
        case DEVICE_TYPE_DISK:
+       case DEVICE_TYPE_USB:
                /* Find block info */
                for (i = 0; sys && i < sys->n_blockdevs; i++) {
                        bd = sys->blockdevs[i];
@@ -263,8 +264,7 @@ struct pmenu_item *pmenu_find_device(struct pmenu *menu, struct device *dev,
                }
                if (matched) {
                        snprintf(buf,sizeof(buf),"[%s: %s / %s]",
-                               dev->type == DEVICE_TYPE_DISK ?
-                               "Disk" : "CD/DVD",
+                               device_type_display_name(dev->type),
                                bd->name, bd->uuid);
                }
                break;
@@ -281,8 +281,8 @@ struct pmenu_item *pmenu_find_device(struct pmenu *menu, struct device *dev,
                if (matched) {
                        mac_str(intf->hwaddr, intf->hwaddr_size,
                                hwaddr, sizeof(hwaddr));
-                       snprintf(buf,sizeof(buf),"[Interface %s / %s]",
-                               intf->name, hwaddr);
+                       snprintf(buf,sizeof(buf),"[%s: %s / %s]",
+                               _("Network"), intf->name, hwaddr);
                }
                break;
 
@@ -293,8 +293,8 @@ struct pmenu_item *pmenu_find_device(struct pmenu *menu, struct device *dev,
        if (!matched) {
                pb_debug("%s: No matching device found for %s (%s)\n",
                        __func__,opt->device_id, dev->id);
-               snprintf(buf,sizeof(buf),"[Unknown Device: %s]",
-                       dev->id);
+               snprintf(buf, sizeof(buf), "[%s: %s]",
+                       _("Unknown Device"), dev->id);
        }
 
        dev_hdr = pmenu_item_create(menu, buf);
@@ -408,6 +408,9 @@ static void pmenu_process_key(struct nc_scr *scr, int key)
        case 'c':
                cui_show_config(cui_from_arg(scr->ui_ctx));
                break;
+       case 'l':
+               cui_show_lang(cui_from_arg(scr->ui_ctx));
+               break;
        case KEY_F(1):
        case 'h':
                if (menu->help_text)
@@ -491,6 +494,19 @@ int pmenu_remove(struct pmenu *menu, struct pmenu_item *item)
        return 0;
 }
 
+static int pmenu_destructor(void *ptr)
+{
+       struct pmenu *menu = ptr;
+       assert(menu->scr.sig == pb_pmenu_sig);
+       menu->scr.sig = pb_removed_sig;
+
+       unpost_menu(menu->ncm);
+       free_menu(menu->ncm);
+       delwin(menu->scr.sub_ncw);
+       delwin(menu->scr.main_ncw);
+       return 0;
+}
+
 /**
  * pmenu_init - Allocate and initialize a new menu instance.
  *
@@ -503,14 +519,13 @@ struct pmenu *pmenu_init(void *ui_ctx, unsigned int item_count,
        void (*on_exit)(struct pmenu *))
 {
        struct pmenu *menu = talloc_zero(ui_ctx, struct pmenu);
-
        if (!menu)
                return NULL;
 
-       /* note items array has a null terminator */
+       talloc_set_destructor(menu, pmenu_destructor);
 
+       /* note items array has a null terminator */
        menu->items = talloc_zero_array(menu, ITEM *, item_count + 1);
-
        if (!menu->items) {
                talloc_free(menu);
                return NULL;
@@ -554,19 +569,3 @@ int pmenu_setup(struct pmenu *menu)
        return 0;
 }
 
-/**
- * pmenu_delete - Delete a menu instance.
- *
- */
-
-void pmenu_delete(struct pmenu *menu)
-{
-       assert(menu->scr.sig == pb_pmenu_sig);
-       menu->scr.sig = pb_removed_sig;
-
-       unpost_menu(menu->ncm);
-       free_menu(menu->ncm);
-       delwin(menu->scr.sub_ncw);
-       delwin(menu->scr.main_ncw);
-       talloc_free(menu);
-}