Add UI option --dry-run
[petitboot] / ui / ncurses / nc-ked.c
index 3bdbd6c85a2dada2081067c77e765531ee9e1f87..806d3895767348a72d9620befcf2854bce1a2b96 100644 (file)
@@ -48,12 +48,15 @@ static struct ked *ked_from_arg(void *arg)
  * @req: An ncurses request or char to send to form_driver().
  */
 
-static void ked_move_cursor(struct ked *ked, int req)
+static int ked_move_cursor(struct ked *ked, int req)
 {
+       int result;
+
        wchgat(ked->scr.sub_ncw, 1, ked_attr_field_selected, 0, 0);
-       form_driver(ked->ncf, req);
+       result = form_driver(ked->ncf, req);
        wchgat(ked->scr.sub_ncw, 1, ked->attr_cursor, 0, 0);
        wrefresh(ked->scr.main_ncw);
+       return result;
 }
 
 /**
@@ -93,12 +96,15 @@ static void ked_insert_mode_tog(struct ked *ked)
  * @req: An ncurses request to send to form_driver().
  */
 
-static void ked_move_field(struct ked *ked, int req)
+static int ked_move_field(struct ked *ked, int req)
 {
+       int result;
+
        set_field_back(current_field(ked->ncf), ked_attr_field_normal);
-       form_driver(ked->ncf, req);
+       result = form_driver(ked->ncf, req);
        set_field_back(current_field(ked->ncf), ked_attr_field_selected);
        ked_move_cursor(ked, REQ_END_FIELD);
+       return result;
 }
 
 static int ked_post(struct nc_scr *scr)
@@ -143,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;
@@ -183,41 +190,33 @@ static struct pb_kexec_data *ked_prepare_data(struct ked *ked)
 static void ked_process_key(struct nc_scr *scr)
 {
        struct ked *ked = ked_from_scr(scr);
+       struct pb_kexec_data *kd;
 
        while (1) {
                int c = getch();
 
+               if (c == ERR)
+                       return;
+
+               /* DBGS("%d (%o)\n", c, c); */
+
                switch (c) {
                default:
                        ked_move_cursor(ked, c);
-               break;
-               case ERR:
-                       return;
+                       break;
 
                /* hot keys */
-               case 2: { /* CTRL-B */
-                       struct pb_kexec_data *kd;
-
-                       form_driver(ked->ncf, REQ_VALIDATION);
-                       kd = ked_prepare_data(ked);
-                       ked->on_exit(ked, ked_boot, kd);
-                       nc_flush_keys();
-                       return;
-               }
                case 27: /* ESC */
                        ked->on_exit(ked, ked_cancel, NULL);
                        nc_flush_keys();
                        return;
                case '\n':
-               case '\r': {
-                       struct pb_kexec_data *kd;
-
+               case '\r':
                        form_driver(ked->ncf, REQ_VALIDATION);
                        kd = ked_prepare_data(ked);
                        ked->on_exit(ked, ked_update, kd);
                        nc_flush_keys();
                        return;
-               }
 
                /* insert mode */
                case KEY_IC:
@@ -252,8 +251,8 @@ static void ked_process_key(struct nc_scr *scr)
                        ked_move_cursor(ked, REQ_RIGHT_CHAR);
                        break;
                case KEY_BACKSPACE:
-                       ked_move_cursor(ked, REQ_LEFT_CHAR);
-                       ked_move_cursor(ked, REQ_DEL_CHAR);
+                       if (ked_move_cursor(ked, REQ_LEFT_CHAR) == E_OK)
+                               ked_move_cursor(ked, REQ_DEL_CHAR);
                        break;
                case KEY_DC:
                        ked_move_cursor(ked, REQ_DEL_CHAR);
@@ -325,7 +324,7 @@ struct ked *ked_init(void *ui_ctx, const struct pb_kexec_data *kd,
 
        ked->scr.frame.title = talloc_strdup(ked, "Petitboot Option Editor");
        ked->scr.frame.help = talloc_strdup(ked,
-               "ESC=cancel, Enter=accept, Ctrl-b=boot");
+               "ESC=cancel, Enter=accept");
 
        ked->on_exit = on_exit;