]> git.ozlabs.org Git - petitboot/blobdiff - ui/ncurses/nc-config.c
ui/ncurses: List available consoles in nc-config
[petitboot] / ui / ncurses / nc-config.c
index e7451bb5dc08fda57d54cd9a73e9bbcd32a60711..24aac2b6e8d6f7fc61e2e271104e9802b9225e6d 100644 (file)
@@ -33,7 +33,7 @@
 #include "nc-config.h"
 #include "nc-widgets.h"
 
-#define N_FIELDS       37
+#define N_FIELDS       42
 
 extern struct help_text config_help_text;
 
@@ -69,6 +69,8 @@ struct config_screen {
        bool                    ipmi_override;
 
        struct {
+               struct nc_widget_label          *autoboot_l;
+               struct nc_widget_select         *autoboot_f;
                struct nc_widget_label          *boot_order_l;
                struct nc_widget_subset         *boot_order_f;
                struct nc_widget_label          *boot_empty_l;
@@ -106,6 +108,9 @@ struct config_screen {
 
                struct nc_widget_label          *allow_write_l;
                struct nc_widget_select         *allow_write_f;
+               struct nc_widget_label          *boot_tty_l;
+               struct nc_widget_select         *boot_tty_f;
+               struct nc_widget_label          *current_tty_l;
 
                struct nc_widget_label          *safe_mode;
                struct nc_widget_button         *ok_b;
@@ -191,11 +196,11 @@ static int screen_process_form(struct config_screen *screen)
        const struct system_info *sysinfo = screen->cui->sysinfo;
        enum net_conf_type net_conf_type;
        struct interface_config *iface;
+       bool allow_write, autoboot;
        char *str, *end;
        struct config *config;
        int i, n_boot_opts, rc, idx;
-       unsigned int *order;
-       bool allow_write;
+       unsigned int *order, tty;
        char mac[20];
 
        config = config_copy(screen, screen->cui->config);
@@ -206,7 +211,8 @@ static int screen_process_form(struct config_screen *screen)
        n_boot_opts = widget_subset_get_order(config, &order,
                                              screen->widgets.boot_order_f);
 
-       config->autoboot_enabled = n_boot_opts > 0;
+       autoboot = widget_select_get_value(screen->widgets.autoboot_f);
+       config->autoboot_enabled = autoboot && n_boot_opts;
 
        config->n_autoboot_opts = n_boot_opts;
        config->autoboot_opts = talloc_array(config, struct autoboot_option,
@@ -330,6 +336,19 @@ static int screen_process_form(struct config_screen *screen)
        if (allow_write != config->allow_writes)
                config->allow_writes = allow_write;
 
+       if (config->n_tty) {
+               tty = widget_select_get_value(screen->widgets.boot_tty_f);
+               if (!config->boot_tty) {
+                       config->boot_tty = talloc_strdup(config,
+                                                       config->tty_list[tty]);
+               } else if (strncmp(config->boot_tty, config->tty_list[tty],
+                               strlen(config->boot_tty)) != 0) {
+                       talloc_free(config->boot_tty);
+                       config->boot_tty = talloc_strdup(config,
+                                                       config->tty_list[tty]);
+               }
+       }
+
        config->safe_mode = false;
        rc = cui_send_config(screen->cui, config);
        talloc_free(config);
@@ -387,41 +406,59 @@ static void config_screen_layout_widgets(struct config_screen *screen)
        help_x = screen->field_x + 2 +
                widget_width(widget_textbox_base(screen->widgets.dns_f));
 
-       wl = widget_label_base(screen->widgets.boot_order_l);
+       wl = widget_label_base(screen->widgets.autoboot_l);
        widget_set_visible(wl, true);
        widget_move(wl, y, screen->label_x);
 
+       wf = widget_select_base(screen->widgets.autoboot_f);
+       widget_move(wf, y, screen->field_x);
+       y += widget_height(wf);
+
+       show = screen->autoboot_enabled;
+
+       if (show)
+               y += 1;
+
+       wl = widget_label_base(screen->widgets.boot_order_l);
+       widget_set_visible(wl, show);
+       widget_move(wl, y, screen->label_x);
+
        wf = widget_subset_base(screen->widgets.boot_order_f);
        widget_move(wf, y, screen->field_x);
        wl = widget_label_base(screen->widgets.boot_empty_l);
        widget_move(wl, y, screen->field_x);
 
        if (widget_subset_height(screen->widgets.boot_order_f)) {
-               widget_set_visible(wf, true);
                widget_set_visible(wl, false);
-               y += widget_height(wf);
+               widget_set_visible(wf, show);
+               y += show ? widget_height(wf) : 0;
        } else {
-               widget_set_visible(wl, true);
+               widget_set_visible(wl, show);
                widget_set_visible(wf, false);
-               y += 1;
+               y += show ? 1 : 0;
        }
 
-       y += 1;
-
-       widget_move(widget_button_base(screen->widgets.boot_add_b),
-                       y++, screen->field_x);
-       widget_move(widget_button_base(screen->widgets.boot_any_b),
-                       y++, screen->field_x);
-       widget_move(widget_button_base(screen->widgets.boot_none_b),
-                       y, screen->field_x);
+       if (show) {
+               y += 1;
+               widget_move(widget_button_base(screen->widgets.boot_add_b),
+                               y++, screen->field_x);
+               widget_move(widget_button_base(screen->widgets.boot_any_b),
+                               y++, screen->field_x);
+               widget_move(widget_button_base(screen->widgets.boot_none_b),
+                               y, screen->field_x);
+       }
 
        wf = widget_button_base(screen->widgets.boot_add_b);
-       if (widget_subset_n_inactive(screen->widgets.boot_order_f))
+       if (widget_subset_n_inactive(screen->widgets.boot_order_f) && show)
                widget_set_visible(wf, true);
        else
                widget_set_visible(wf, false);
 
-       y += 2;
+       if (show)
+               y += 2;
+
+       widget_set_visible(widget_button_base(screen->widgets.boot_any_b), show);
+       widget_set_visible(widget_button_base(screen->widgets.boot_none_b), show);
 
        wf = widget_textbox_base(screen->widgets.timeout_f);
        wl = widget_label_base(screen->widgets.timeout_l);
@@ -558,6 +595,22 @@ static void config_screen_layout_widgets(struct config_screen *screen)
 
        y += 1;
 
+       if (widget_height(widget_select_base(screen->widgets.boot_tty_f))) {
+               layout_pair(screen, y, screen->widgets.boot_tty_l,
+                           widget_select_base(screen->widgets.boot_tty_f));
+               y += widget_height(widget_select_base(screen->widgets.boot_tty_f));
+               widget_move(widget_label_base(screen->widgets.current_tty_l),
+                       y, screen->field_x);
+               y += 2;
+       } else {
+               widget_set_visible(widget_label_base(
+                                       screen->widgets.boot_tty_l), false);
+               widget_set_visible(widget_select_base(
+                                       screen->widgets.boot_tty_f), false);
+               widget_set_visible(widget_label_base(
+                                       screen->widgets.current_tty_l), false);
+       }
+
        widget_move(widget_button_base(screen->widgets.ok_b),
                        y, screen->field_x);
        widget_move(widget_button_base(screen->widgets.help_b),
@@ -584,6 +637,15 @@ static void config_screen_boot_order_change(void *arg, int value)
        widgetset_post(screen->widgetset);
 }
 
+static void config_screen_autoboot_change(void *arg, int value)
+{
+       struct config_screen *screen = arg;
+       screen->autoboot_enabled = !!value;
+       widgetset_unpost(screen->widgetset);
+       config_screen_layout_widgets(screen);
+       widgetset_post(screen->widgetset);
+}
+
 static void config_screen_add_device(void *arg)
 {
        struct config_screen *screen = arg;
@@ -599,7 +661,6 @@ static void config_screen_autoboot_none(void *arg)
        struct nc_widget_subset *subset = screen->widgets.boot_order_f;
 
        widget_subset_clear_active(subset);
-       screen->autoboot_enabled = false;
 
        widgetset_unpost(screen->widgetset);
        config_screen_layout_widgets(screen);
@@ -711,10 +772,11 @@ static void config_screen_setup_widgets(struct config_screen *screen,
 {
        struct nc_widgetset *set = screen->widgetset;
        struct interface_config *ifcfg;
-       char *str, *ip, *mask, *gw, *url;
+       char *str, *ip, *mask, *gw, *url, *tty;
        enum net_conf_type type;
        unsigned int i;
        int add_len, clear_len, any_len, min_len = 20;
+       bool found;
 
        build_assert(sizeof(screen->widgets) / sizeof(struct widget *)
                        == N_FIELDS);
@@ -722,6 +784,21 @@ static void config_screen_setup_widgets(struct config_screen *screen,
        type = screen->net_conf_type;
        ifcfg = first_active_interface(config);
 
+       screen->autoboot_enabled = config->autoboot_enabled;
+
+       screen->widgets.autoboot_l = widget_new_label(set, 0, 0,
+                                       _("Autoboot:"));
+       screen->widgets.autoboot_f = widget_new_select(set, 0, 0,
+                                       COLS - screen->field_x - 1);
+
+       widget_select_add_option(screen->widgets.autoboot_f, 0, _("Disabled"),
+                                !screen->autoboot_enabled);
+       widget_select_add_option(screen->widgets.autoboot_f, 1, _("Enabled"),
+                                screen->autoboot_enabled);
+
+       widget_select_on_change(screen->widgets.autoboot_f,
+                       config_screen_autoboot_change, screen);
+
        add_len = max(min_len, strncols(_("Add Device")));
        clear_len = max(min_len, strncols(_("Clear")));
        any_len = max(min_len, strncols(_("Clear & Boot Any")));
@@ -783,7 +860,6 @@ static void config_screen_setup_widgets(struct config_screen *screen,
                widget_subset_add_option(screen->widgets.boot_order_f, label);
        }
 
-       screen->autoboot_enabled = config->n_autoboot_opts;
        for (i = 0; i < config->n_autoboot_opts; i++) {
                struct autoboot_option *opt = &config->autoboot_opts[i];
                int idx;
@@ -943,6 +1019,23 @@ static void config_screen_setup_widgets(struct config_screen *screen,
                                _("Allow bootloader scripts to modify disks"),
                                config->allow_writes);
 
+       screen->widgets.boot_tty_l = widget_new_label(set, 0, 0,
+                       _("Default tty:"));
+       screen->widgets.boot_tty_f = widget_new_select(set, 0, 0,
+                                               COLS - screen->field_x - 1);
+
+       for (i = 0; i < config->n_tty; i++){
+               found = config->boot_tty &&
+                       strncmp(config->boot_tty, config->tty_list[i],
+                               strlen(config->boot_tty)) == 0;
+               widget_select_add_option(screen->widgets.boot_tty_f, i,
+                                       config->tty_list[i], found);
+       }
+
+       tty = talloc_asprintf(screen, _("Current interface: %s"),
+                               ttyname(STDIN_FILENO));
+       screen->widgets.current_tty_l = widget_new_label(set, 0 , 0, tty);
+
        screen->widgets.ok_b = widget_new_button(set, 0, 0, 10, _("OK"),
                        ok_click, screen);
        screen->widgets.help_b = widget_new_button(set, 0, 0, 10, _("Help"),