X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=ui%2Fncurses%2Fnc-boot-editor.c;h=ac07156d72805ed51df295ac5fdb1b7d81561a07;hb=649de37c20f56749ff02c751656787bf2c3d0024;hp=79ca3a74269e7311140cb56de183d0152ac487e7;hpb=c4b4ebc4c61b7f374582c621aec846aba3795954;p=petitboot diff --git a/ui/ncurses/nc-boot-editor.c b/ui/ncurses/nc-boot-editor.c index 79ca3a7..ac07156 100644 --- a/ui/ncurses/nc-boot-editor.c +++ b/ui/ncurses/nc-boot-editor.c @@ -16,9 +16,9 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#if defined(HAVE_CONFIG_H) #include "config.h" - -#define _GNU_SOURCE +#endif #include #include @@ -33,6 +33,11 @@ struct boot_editor { struct cui *cui; void *data; struct pmenu_item *item; + enum { + STATE_EDIT, + STATE_CANCEL, + STATE_SAVE, + } state; void (*on_exit)(struct cui *cui, struct pmenu_item *item, struct pb_boot_data *bd); @@ -131,7 +136,7 @@ static char *conditional_prefix(struct pb_boot_data *ctx, if (!value || !*value) return NULL; - sep = NULL; + sep = ""; if (!prefix) prefix = ""; else if (prefix[strlen(prefix)] != '/') @@ -183,19 +188,30 @@ static struct pb_boot_data *boot_editor_prepare_data( static void boot_editor_process_key(struct nc_scr *scr, int key) { struct boot_editor *boot_editor = boot_editor_from_scr(scr); + struct pmenu_item *item; + struct pb_boot_data *bd; bool handled; handled = widgetset_process_key(boot_editor->widgetset, key); - if (handled) { + if (handled) pad_refresh(boot_editor); - return; - } - switch (key) { - case 'x': - case 27: /* ESC */ - boot_editor->on_exit(boot_editor->cui, NULL, NULL); - nc_flush_keys(); + else if (key == 'x' || key == 27) + boot_editor->state = STATE_CANCEL; + + item = NULL; + bd = NULL; + + switch (boot_editor->state) { + case STATE_SAVE: + item = boot_editor->item; + bd = boot_editor_prepare_data(boot_editor); + /* fall through */ + case STATE_CANCEL: + boot_editor->on_exit(boot_editor->cui, item, bd); + break; + default: + break; } } @@ -215,16 +231,13 @@ static int boot_editor_destructor(void *arg) static void ok_click(void *arg) { struct boot_editor *boot_editor = arg; - struct pb_boot_data *bd; - - bd = boot_editor_prepare_data(boot_editor); - boot_editor->on_exit(boot_editor->cui, boot_editor->item, bd); + boot_editor->state = STATE_SAVE; } static void cancel_click(void *arg) { struct boot_editor *boot_editor = arg; - boot_editor->on_exit(boot_editor->cui, NULL, NULL); + boot_editor->state = STATE_CANCEL; } static int layout_pair(struct boot_editor *boot_editor, int y, @@ -412,7 +425,7 @@ static void boot_editor_setup_widgets(struct boot_editor *boot_editor, widgetset_set_widget_focus(boot_editor->widgetset, boot_editor_widget_focus, boot_editor); - boot_editor->widgets.device_l = widget_new_label(set, 0, 0, "device:"); + boot_editor->widgets.device_l = widget_new_label(set, 0, 0, "Device:"); boot_editor->widgets.device_f = widget_new_select(set, 0, 0, field_size); widget_select_on_change(boot_editor->widgets.device_f, @@ -420,20 +433,24 @@ static void boot_editor_setup_widgets(struct boot_editor *boot_editor, boot_editor_populate_device_select(boot_editor, sysinfo); - boot_editor->widgets.image_l = widget_new_label(set, 0, 0, "image:"); + boot_editor->widgets.image_l = widget_new_label(set, 0, 0, + "Kernel:"); boot_editor->widgets.image_f = widget_new_textbox(set, 0, 0, field_size, boot_editor->image); - boot_editor->widgets.initrd_l = widget_new_label(set, 0, 0, "initrd:"); + boot_editor->widgets.initrd_l = widget_new_label(set, 0, 0, + "Initrd:"); boot_editor->widgets.initrd_f = widget_new_textbox(set, 0, 0, field_size, boot_editor->initrd); - boot_editor->widgets.dtb_l = widget_new_label(set, 0, 0, "dtb:"); + boot_editor->widgets.dtb_l = widget_new_label(set, 0, 0, + "Device tree:"); boot_editor->widgets.dtb_f = widget_new_textbox(set, 0, 0, field_size, boot_editor->dtb); - boot_editor->widgets.args_l = widget_new_label(set, 0, 0, "args:"); + boot_editor->widgets.args_l = widget_new_label(set, 0, 0, + "Boot arguments:"); boot_editor->widgets.args_f = widget_new_textbox(set, 0, 0, field_size, boot_editor->args); @@ -461,6 +478,8 @@ void boot_editor_update(struct boot_editor *boot_editor, boot_editor_populate_device_select(boot_editor, sysinfo); + boot_editor_layout_widgets(boot_editor); + widgetset_post(boot_editor->widgetset); pad_refresh(boot_editor); @@ -484,9 +503,10 @@ struct boot_editor *boot_editor_init(struct cui *cui, boot_editor->cui = cui; boot_editor->item = item; boot_editor->on_exit = on_exit; + boot_editor->state = STATE_EDIT; boot_editor->label_x = 1; - boot_editor->field_x = 9; + boot_editor->field_x = 17; nc_scr_init(&boot_editor->scr, pb_boot_editor_sig, 0, cui, boot_editor_process_key, @@ -497,6 +517,7 @@ struct boot_editor *boot_editor_init(struct cui *cui, boot_editor->scr.frame.rtitle = NULL; boot_editor->scr.frame.help = talloc_strdup(boot_editor, "Enter=accept"); + nc_scr_frame_draw(&boot_editor->scr); if (item) { struct pb_boot_data *bd = cod_from_item(item)->bd; @@ -517,6 +538,7 @@ struct boot_editor *boot_editor_init(struct cui *cui, boot_editor_setup_widgets(boot_editor, sysinfo); boot_editor_layout_widgets(boot_editor); + wrefresh(boot_editor->scr.main_ncw); return boot_editor; }