ui/ncurses: Use pmenu_item destrutor to free ncurses ITEMs
[petitboot] / ui / ncurses / nc-config.c
1 /*
2  *  Copyright (C) 2013 IBM Corporation
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; version 2 of the License.
7  *
8  *  This program is distributed in the hope that it will be useful,
9  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  *  GNU General Public License for more details.
12  *
13  *  You should have received a copy of the GNU General Public License
14  *  along with this program; if not, write to the Free Software
15  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16  */
17
18 #if defined(HAVE_CONFIG_H)
19 #include "config.h"
20 #endif
21
22 #include <errno.h>
23 #include <stdlib.h>
24 #include <string.h>
25
26 #include <pb-config/pb-config.h>
27 #include <talloc/talloc.h>
28 #include <types/types.h>
29 #include <log/log.h>
30
31 #include "nc-cui.h"
32 #include "nc-config.h"
33 #include "nc-widgets.h"
34
35 #define N_FIELDS        24
36
37 extern const char *config_help_text;
38
39 enum net_conf_type {
40         NET_CONF_TYPE_DHCP_ALL,
41         NET_CONF_TYPE_DHCP_ONE,
42         NET_CONF_TYPE_STATIC,
43 };
44
45 struct config_screen {
46         struct nc_scr           scr;
47         struct cui              *cui;
48         struct nc_widgetset     *widgetset;
49         WINDOW                  *pad;
50
51         bool                    exit;
52         bool                    show_help;
53         void                    (*on_exit)(struct cui *);
54
55         int                     scroll_y;
56
57         int                     label_x;
58         int                     field_x;
59         int                     network_config_y;
60
61         enum net_conf_type      net_conf_type;
62
63         struct {
64                 struct nc_widget_checkbox       *autoboot_f;
65                 struct nc_widget_label          *autoboot_l;
66                 struct nc_widget_textbox        *timeout_f;
67                 struct nc_widget_label          *timeout_l;
68                 struct nc_widget_label          *timeout_help_l;
69
70                 struct nc_widget_label          *network_l;
71                 struct nc_widget_select         *network_f;
72
73                 struct nc_widget_label          *iface_l;
74                 struct nc_widget_select         *iface_f;
75                 struct nc_widget_label          *ip_addr_l;
76                 struct nc_widget_textbox        *ip_addr_f;
77                 struct nc_widget_label          *ip_mask_l;
78                 struct nc_widget_textbox        *ip_mask_f;
79                 struct nc_widget_label          *ip_addr_mask_help_l;
80                 struct nc_widget_label          *gateway_l;
81                 struct nc_widget_textbox        *gateway_f;
82                 struct nc_widget_label          *gateway_help_l;
83                 struct nc_widget_label          *dns_l;
84                 struct nc_widget_textbox        *dns_f;
85                 struct nc_widget_label          *dns_dhcp_help_l;
86                 struct nc_widget_label          *dns_help_l;
87
88                 struct nc_widget_button         *ok_b;
89                 struct nc_widget_button         *help_b;
90                 struct nc_widget_button         *cancel_b;
91         } widgets;
92 };
93
94 static struct config_screen *config_screen_from_scr(struct nc_scr *scr)
95 {
96         struct config_screen *config_screen;
97
98         assert(scr->sig == pb_config_screen_sig);
99         config_screen = (struct config_screen *)
100                 ((char *)scr - (size_t)&((struct config_screen *)0)->scr);
101         assert(config_screen->scr.sig == pb_config_screen_sig);
102         return config_screen;
103 }
104
105 static void pad_refresh(struct config_screen *screen)
106 {
107         int y, x, rows, cols;
108
109         getmaxyx(screen->scr.sub_ncw, rows, cols);
110         getbegyx(screen->scr.sub_ncw, y, x);
111
112         prefresh(screen->pad, screen->scroll_y, 0, y, x, rows, cols);
113 }
114
115 static void config_screen_process_key(struct nc_scr *scr, int key)
116 {
117         struct config_screen *screen = config_screen_from_scr(scr);
118         bool handled;
119
120         handled = widgetset_process_key(screen->widgetset, key);
121
122         if (!handled) {
123                 switch (key) {
124                 case 'x':
125                 case 27: /* esc */
126                         screen->exit = true;
127                         break;
128                 case 'h':
129                         screen->show_help = true;
130                         break;
131                 }
132         }
133
134         if (screen->exit) {
135                 screen->on_exit(screen->cui);
136
137         } else if (screen->show_help) {
138                 screen->show_help = false;
139                 cui_show_help(screen->cui, "System Configuration",
140                                 config_help_text);
141
142         } else if (handled) {
143                 pad_refresh(screen);
144         }
145 }
146
147 static void config_screen_resize(struct nc_scr *scr)
148 {
149         struct config_screen *screen = config_screen_from_scr(scr);
150         (void)screen;
151 }
152
153 static int config_screen_post(struct nc_scr *scr)
154 {
155         struct config_screen *screen = config_screen_from_scr(scr);
156         widgetset_post(screen->widgetset);
157         nc_scr_frame_draw(scr);
158         redrawwin(scr->main_ncw);
159         wrefresh(screen->scr.main_ncw);
160         pad_refresh(screen);
161         return 0;
162 }
163
164 static int config_screen_unpost(struct nc_scr *scr)
165 {
166         struct config_screen *screen = config_screen_from_scr(scr);
167         widgetset_unpost(screen->widgetset);
168         return 0;
169 }
170
171 struct nc_scr *config_screen_scr(struct config_screen *screen)
172 {
173         return &screen->scr;
174 }
175
176 static int screen_process_form(struct config_screen *screen)
177 {
178         const struct system_info *sysinfo = screen->cui->sysinfo;
179         enum net_conf_type net_conf_type;
180         struct interface_config *iface;
181         struct config *config;
182         char *str, *end;
183         int rc;
184
185         config = config_copy(screen, screen->cui->config);
186
187         config->autoboot_enabled =
188                 widget_checkbox_get_value(screen->widgets.autoboot_f);
189
190
191         str = widget_textbox_get_value(screen->widgets.timeout_f);
192         if (str) {
193                 unsigned long x;
194                 errno = 0;
195                 x = strtoul(str, &end, 10);
196                 if (!errno && end != str)
197                         config->autoboot_timeout_sec = x;
198         }
199
200         net_conf_type = widget_select_get_value(screen->widgets.network_f);
201
202         /* if we don't have any network interfaces, prevent per-interface
203          * configuration */
204         if (sysinfo->n_interfaces == 0)
205                 net_conf_type = NET_CONF_TYPE_DHCP_ALL;
206
207         if (net_conf_type == NET_CONF_TYPE_DHCP_ALL) {
208                 config->network.n_interfaces = 0;
209
210         } else {
211                 int idx;
212
213                 iface = talloc_zero(config, struct interface_config);
214                 config->network.n_interfaces = 1;
215                 config->network.interfaces = talloc_array(config,
216                                 struct interface_config *, 1);
217                 config->network.interfaces[0] = iface;
218
219                 /* copy hwaddr (from the sysinfo interface data) to
220                  * the configuration */
221                 idx = widget_select_get_value(screen->widgets.iface_f);
222                 memcpy(iface->hwaddr, sysinfo->interfaces[idx]->hwaddr,
223                                 sizeof(iface->hwaddr));
224         }
225
226         if (net_conf_type == NET_CONF_TYPE_DHCP_ONE) {
227                 iface->method = CONFIG_METHOD_DHCP;
228         }
229
230         if (net_conf_type == NET_CONF_TYPE_STATIC) {
231                 char *ip, *mask, *gateway;
232
233                 ip = widget_textbox_get_value(screen->widgets.ip_addr_f);
234                 mask = widget_textbox_get_value(screen->widgets.ip_mask_f);
235                 gateway = widget_textbox_get_value(screen->widgets.gateway_f);
236
237                 if (!ip || !*ip || !mask || !*mask) {
238                         screen->scr.frame.status =
239                                 "No IP / mask values are set";
240                         nc_scr_frame_draw(&screen->scr);
241                         talloc_free(config);
242                         return -1;
243                 }
244
245                 iface->method = CONFIG_METHOD_STATIC;
246                 iface->static_config.address = talloc_asprintf(iface, "%s/%s",
247                                 ip, mask);
248                 iface->static_config.gateway = talloc_strdup(iface, gateway);
249         }
250
251         str = widget_textbox_get_value(screen->widgets.dns_f);
252         talloc_free(config->network.dns_servers);
253         config->network.dns_servers = NULL;
254         config->network.n_dns_servers = 0;
255
256         if (str && strlen(str)) {
257                 char *dns, *tmp;
258                 int i;
259
260                 for (;;) {
261                         dns = strtok_r(str, " \t", &tmp);
262
263                         if (!dns)
264                                 break;
265
266                         i = config->network.n_dns_servers++;
267                         config->network.dns_servers = talloc_realloc(config,
268                                         config->network.dns_servers,
269                                         const char *,
270                                         config->network.n_dns_servers);
271                         config->network.dns_servers[i] =
272                                 talloc_strdup(config, dns);
273
274                         str = NULL;
275                 }
276         }
277
278         rc = cui_send_config(screen->cui, config);
279         talloc_free(config);
280
281         if (rc)
282                 pb_log("cui_send_config failed!\n");
283         else
284                 pb_debug("config sent!\n");
285
286         return 0;
287 }
288
289 static void ok_click(void *arg)
290 {
291         struct config_screen *screen = arg;
292         if (screen_process_form(screen))
293                 /* errors are written to the status line, so we'll need
294                  * to refresh */
295                 wrefresh(screen->scr.main_ncw);
296         else
297                 screen->exit = true;
298 }
299
300 static void help_click(void *arg)
301 {
302         struct config_screen *screen = arg;
303         screen->show_help = true;
304 }
305
306 static void cancel_click(void *arg)
307 {
308         struct config_screen *screen = arg;
309         screen->exit = true;
310 }
311
312 static int layout_pair(struct config_screen *screen, int y,
313                 struct nc_widget_label *label,
314                 struct nc_widget *field)
315 {
316         struct nc_widget *label_w = widget_label_base(label);
317         widget_move(label_w, y, screen->label_x);
318         widget_move(field, y, screen->field_x);
319         return max(widget_height(label_w), widget_height(field));
320 }
321
322 static void config_screen_layout_widgets(struct config_screen *screen,
323                 enum net_conf_type net_conf)
324 {
325         struct nc_widget *wl, *wf, *wh;
326         int y, x, help_x;
327         bool show;
328
329         y = 1;
330         help_x = screen->field_x + 2 +
331                 widget_width(widget_textbox_base(screen->widgets.dns_f));
332
333         y += layout_pair(screen, y, screen->widgets.autoboot_l,
334                         widget_checkbox_base(screen->widgets.autoboot_f));
335
336         wf = widget_textbox_base(screen->widgets.timeout_f);
337         widget_move(widget_label_base(screen->widgets.timeout_l),
338                         y, screen->label_x);
339         widget_move(wf, y, screen->field_x);
340         widget_move(widget_label_base(screen->widgets.timeout_help_l),
341                         y, screen->field_x + widget_width(wf) + 1);
342
343         y += 2;
344
345         y += layout_pair(screen, y, screen->widgets.network_l,
346                         widget_select_base(screen->widgets.network_f));
347
348         y += 1;
349
350         /* conditionally show iface select */
351         wl = widget_label_base(screen->widgets.iface_l);
352         wf = widget_select_base(screen->widgets.iface_f);
353
354         show = net_conf == NET_CONF_TYPE_DHCP_ONE ||
355                 net_conf == NET_CONF_TYPE_STATIC;
356
357         widget_set_visible(wl, show);
358         widget_set_visible(wf, show);
359
360         if (show)
361                 y += layout_pair(screen, y, screen->widgets.iface_l, wf) + 1;
362
363         /* conditionally show static IP params */
364         show = net_conf == NET_CONF_TYPE_STATIC;
365
366         wl = widget_label_base(screen->widgets.ip_addr_l);
367         wf = widget_textbox_base(screen->widgets.ip_addr_f);
368         widget_set_visible(wl, show);
369         widget_set_visible(wf, show);
370         x = screen->field_x + widget_width(wf) + 1;
371
372         if (show)
373                 layout_pair(screen, y, screen->widgets.ip_addr_l, wf);
374
375         wl = widget_label_base(screen->widgets.ip_mask_l);
376         wf = widget_textbox_base(screen->widgets.ip_mask_f);
377         widget_set_visible(wl, show);
378         widget_set_visible(wf, show);
379
380         if (show) {
381                 widget_move(wl, y, x);
382                 widget_move(wf, y, x + 2);
383         }
384
385         /* help for IP/mask */
386         wh = widget_label_base(screen->widgets.ip_addr_mask_help_l);
387         widget_set_visible(wh, show);
388         if (show) {
389                 widget_move(wh, y, help_x);
390                 y++;
391         }
392
393         wl = widget_label_base(screen->widgets.gateway_l);
394         wf = widget_textbox_base(screen->widgets.gateway_f);
395         wh = widget_label_base(screen->widgets.gateway_help_l);
396         widget_set_visible(wl, show);
397         widget_set_visible(wf, show);
398         widget_set_visible(wh, show);
399
400         if (show) {
401                 layout_pair(screen, y, screen->widgets.gateway_l, wf);
402                 widget_move(wh, y, help_x);
403                 y++;
404         }
405
406         wh = widget_label_base(screen->widgets.dns_help_l);
407         layout_pair(screen, y, screen->widgets.dns_l,
408                         widget_textbox_base(screen->widgets.dns_f));
409         widget_move(wh, y, help_x);
410         y++;
411
412         /* we show the DNS/DHCP help if we're configuring DHCP */
413         show = net_conf != NET_CONF_TYPE_STATIC;
414         wl = widget_label_base(screen->widgets.dns_dhcp_help_l);
415         widget_set_visible(wl, show);
416         if (show) {
417                 widget_move(wl, y, screen->field_x);
418                 y += 1;
419         }
420
421         y += 1;
422
423         widget_move(widget_button_base(screen->widgets.ok_b),
424                         y, screen->field_x);
425         widget_move(widget_button_base(screen->widgets.help_b),
426                         y, screen->field_x + 10);
427         widget_move(widget_button_base(screen->widgets.cancel_b),
428                         y, screen->field_x + 20);
429 }
430
431 static void config_screen_network_change(void *arg, int value)
432 {
433         struct config_screen *screen = arg;
434         screen->net_conf_type = value;
435         widgetset_unpost(screen->widgetset);
436         config_screen_layout_widgets(screen, value);
437         widgetset_post(screen->widgetset);
438 }
439
440 static struct interface_config *first_active_interface(
441                 const struct config *config)
442 {
443         unsigned int i;
444
445         for (i = 0; i < config->network.n_interfaces; i++) {
446                 if (config->network.interfaces[i]->ignore)
447                         continue;
448                 return config->network.interfaces[i];
449         }
450         return NULL;
451 }
452
453 static enum net_conf_type find_net_conf_type(const struct config *config)
454 {
455         struct interface_config *ifcfg;
456
457         ifcfg = first_active_interface(config);
458
459         if (!ifcfg)
460                 return NET_CONF_TYPE_DHCP_ALL;
461
462         else if (ifcfg->method == CONFIG_METHOD_DHCP)
463                 return NET_CONF_TYPE_DHCP_ONE;
464
465         else if (ifcfg->method == CONFIG_METHOD_STATIC)
466                 return NET_CONF_TYPE_STATIC;
467
468         assert(0);
469         return NET_CONF_TYPE_DHCP_ALL;
470 }
471
472 static void config_screen_setup_empty(struct config_screen *screen)
473 {
474         widget_new_label(screen->widgetset, 2, screen->field_x,
475                         "Waiting for configuration data...");
476         screen->widgets.cancel_b = widget_new_button(screen->widgetset,
477                         4, screen->field_x, 6, "Cancel", cancel_click, screen);
478 }
479
480
481 static void config_screen_setup_widgets(struct config_screen *screen,
482                 const struct config *config,
483                 const struct system_info *sysinfo)
484 {
485         struct nc_widgetset *set = screen->widgetset;
486         struct interface_config *ifcfg;
487         char *str, *ip, *mask, *gw;
488         enum net_conf_type type;
489         unsigned int i;
490
491         build_assert(sizeof(screen->widgets) / sizeof(struct widget *)
492                         == N_FIELDS);
493
494         type = screen->net_conf_type;
495         ifcfg = first_active_interface(config);
496
497         screen->widgets.autoboot_l = widget_new_label(set, 0, 0, "Autoboot:");
498         screen->widgets.autoboot_f = widget_new_checkbox(set, 0, 0,
499                                         config->autoboot_enabled);
500
501         str = talloc_asprintf(screen, "%d", config->autoboot_timeout_sec);
502         screen->widgets.timeout_l = widget_new_label(set, 0, 0, "Timeout:");
503         screen->widgets.timeout_f = widget_new_textbox(set, 0, 0, 5, str);
504         screen->widgets.timeout_help_l = widget_new_label(set, 0, 0, "seconds");
505
506         widget_textbox_set_validator_integer(screen->widgets.timeout_f, 0, 999);
507
508         screen->widgets.network_l = widget_new_label(set, 0, 0, "Network");
509         screen->widgets.network_f = widget_new_select(set, 0, 0, 50);
510
511         widget_select_add_option(screen->widgets.network_f,
512                                         NET_CONF_TYPE_DHCP_ALL,
513                                         "DHCP on all active interfaces",
514                                         type == NET_CONF_TYPE_DHCP_ALL);
515         widget_select_add_option(screen->widgets.network_f,
516                                         NET_CONF_TYPE_DHCP_ONE,
517                                         "DHCP on a specific interface",
518                                         type == NET_CONF_TYPE_DHCP_ONE);
519         widget_select_add_option(screen->widgets.network_f,
520                                         NET_CONF_TYPE_STATIC,
521                                         "Static IP configuration",
522                                         type == NET_CONF_TYPE_STATIC);
523
524         widget_select_on_change(screen->widgets.network_f,
525                         config_screen_network_change, screen);
526
527         screen->widgets.iface_l = widget_new_label(set, 0, 0, "Device:");
528         screen->widgets.iface_f = widget_new_select(set, 0, 0, 50);
529
530         for (i = 0; i < sysinfo->n_interfaces; i++) {
531                 struct interface_info *info = sysinfo->interfaces[i];
532                 char str[50], mac[20];
533                 bool is_default;
534
535                 is_default = ifcfg && !memcmp(ifcfg->hwaddr, info->hwaddr,
536                                         sizeof(ifcfg->hwaddr));
537
538                 mac_str(info->hwaddr, info->hwaddr_size, mac, sizeof(mac));
539                 snprintf(str, sizeof(str), "%s [%s, %s]", info->name, mac,
540                                 info->link ? "link up" : "link down");
541
542                 widget_select_add_option(screen->widgets.iface_f,
543                                                 i, str, is_default);
544         }
545
546         gw = ip = mask = NULL;
547         if (ifcfg && ifcfg->method == CONFIG_METHOD_STATIC) {
548                 char *sep;
549
550                 str = talloc_strdup(screen, ifcfg->static_config.address);
551                 sep = strchr(str, '/');
552                 ip = str;
553
554                 if (sep) {
555                         *sep = '\0';
556                         mask = sep + 1;
557                 }
558                 gw = ifcfg->static_config.gateway;
559         }
560
561         screen->widgets.ip_addr_l = widget_new_label(set, 0, 0, "IP/mask:");
562         screen->widgets.ip_addr_f = widget_new_textbox(set, 0, 0, 16, ip);
563         screen->widgets.ip_mask_l = widget_new_label(set, 0, 0, "/");
564         screen->widgets.ip_mask_f = widget_new_textbox(set, 0, 0, 4, mask);
565         screen->widgets.ip_addr_mask_help_l =
566                 widget_new_label(set, 0, 0, "(eg. 192.168.0.10 / 24)");
567
568         widget_textbox_set_validator_ipv4(screen->widgets.ip_addr_f);
569         widget_textbox_set_validator_integer(screen->widgets.ip_mask_f, 1, 31);
570
571         screen->widgets.gateway_l = widget_new_label(set, 0, 0, "Gateway:");
572         screen->widgets.gateway_f = widget_new_textbox(set, 0, 0, 16, gw);
573         screen->widgets.gateway_help_l =
574                 widget_new_label(set, 0, 0, "(eg. 192.168.0.1)");
575
576         widget_textbox_set_validator_ipv4(screen->widgets.gateway_f);
577
578         str = talloc_strdup(screen, "");
579         for (i = 0; i < config->network.n_dns_servers; i++) {
580                 str = talloc_asprintf_append(str, "%s%s",
581                                 (i == 0) ? "" : " ",
582                                 config->network.dns_servers[i]);
583         }
584
585         screen->widgets.dns_l = widget_new_label(set, 0, 0, "DNS Server(s):");
586         screen->widgets.dns_f = widget_new_textbox(set, 0, 0, 32, str);
587         screen->widgets.dns_help_l =
588                 widget_new_label(set, 0, 0, "(eg. 192.168.0.2)");
589
590         widget_textbox_set_validator_ipv4_multi(screen->widgets.dns_f);
591
592         screen->widgets.dns_dhcp_help_l = widget_new_label(set, 0, 0,
593                         "(if not provided by DHCP server)");
594
595         screen->widgets.ok_b = widget_new_button(set, 0, 0, 6, "OK",
596                         ok_click, screen);
597         screen->widgets.help_b = widget_new_button(set, 0, 0, 6, "Help",
598                         help_click, screen);
599         screen->widgets.cancel_b = widget_new_button(set, 0, 0, 6, "Cancel",
600                         cancel_click, screen);
601 }
602
603 static void config_screen_widget_focus(struct nc_widget *widget, void *arg)
604 {
605         struct config_screen *screen = arg;
606         int w_y, s_max;
607
608         w_y = widget_y(widget) + widget_focus_y(widget);
609         s_max = getmaxy(screen->scr.sub_ncw) - 1;
610
611         if (w_y < screen->scroll_y)
612                 screen->scroll_y = w_y;
613
614         else if (w_y + screen->scroll_y + 1 > s_max)
615                 screen->scroll_y = 1 + w_y - s_max;
616
617         else
618                 return;
619
620         pad_refresh(screen);
621 }
622
623 static void config_screen_draw(struct config_screen *screen,
624                 const struct config *config,
625                 const struct system_info *sysinfo)
626 {
627         bool repost = false;
628         int height;
629
630         /* The size of the pad we'll need depends on the number of interfaces.
631          *
632          * We use N_FIELDS (which is quite conservative, as some fields share
633          * a line) as a base, then add 3 (as the network select field is
634          * takes 3 lines), and n_interfaces (as the network interface field
635          * has n_interfaces lines).
636          */
637         height = N_FIELDS + 3;
638         if (sysinfo)
639                 height += sysinfo->n_interfaces;
640         if (!screen->pad || getmaxy(screen->pad) < height) {
641                 if (screen->pad)
642                         delwin(screen->pad);
643                 screen->pad = newpad(height, COLS);
644         }
645
646         if (screen->widgetset) {
647                 widgetset_unpost(screen->widgetset);
648                 talloc_free(screen->widgetset);
649                 repost = true;
650         }
651
652         screen->widgetset = widgetset_create(screen, screen->scr.main_ncw,
653                         screen->pad);
654         widgetset_set_widget_focus(screen->widgetset,
655                         config_screen_widget_focus, screen);
656
657         if (!config || !sysinfo) {
658                 config_screen_setup_empty(screen);
659         } else {
660                 screen->net_conf_type = find_net_conf_type(config);
661
662                 config_screen_setup_widgets(screen, config, sysinfo);
663                 config_screen_layout_widgets(screen, screen->net_conf_type);
664         }
665
666         if (repost)
667                 widgetset_post(screen->widgetset);
668 }
669
670 void config_screen_update(struct config_screen *screen,
671                 const struct config *config,
672                 const struct system_info *sysinfo)
673 {
674         config_screen_draw(screen, config, sysinfo);
675         pad_refresh(screen);
676 }
677
678 static int config_screen_destroy(void *arg)
679 {
680         struct config_screen *screen = arg;
681         if (screen->pad)
682                 delwin(screen->pad);
683         return 0;
684 }
685
686 struct config_screen *config_screen_init(struct cui *cui,
687                 const struct config *config,
688                 const struct system_info *sysinfo,
689                 void (*on_exit)(struct cui *))
690 {
691         struct config_screen *screen;
692
693         screen = talloc_zero(cui, struct config_screen);
694         talloc_set_destructor(screen, config_screen_destroy);
695         nc_scr_init(&screen->scr, pb_config_screen_sig, 0,
696                         cui, config_screen_process_key,
697                         config_screen_post, config_screen_unpost,
698                         config_screen_resize);
699
700         screen->cui = cui;
701         screen->on_exit = on_exit;
702         screen->label_x = 2;
703         screen->field_x = 17;
704
705         screen->scr.frame.ltitle = talloc_strdup(screen,
706                         "Petitboot System Configuration");
707         screen->scr.frame.rtitle = NULL;
708         screen->scr.frame.help = talloc_strdup(screen,
709                         "tab=next, shift+tab=previous, x=exit, h=help");
710         nc_scr_frame_draw(&screen->scr);
711
712         scrollok(screen->scr.sub_ncw, true);
713
714         config_screen_draw(screen, config, sysinfo);
715
716         return screen;
717 }