]> git.ozlabs.org Git - petitboot/blobdiff - ui/ncurses/nc-cui.c
Fix CUI scroll
[petitboot] / ui / ncurses / nc-cui.c
index 2a4c971165963bb60fc66a3afb3aa49f9db3ec92..83e29392249cee84c1cef3f19f0fdbd80bcb60c7 100644 (file)
@@ -30,7 +30,6 @@
 #include "ui/common/discover-client.h"
 #include "nc-cui.h"
 
-
 static struct cui_opt_data *cod_from_item(struct pmenu_item *item)
 {
        return item->data;
@@ -205,10 +204,17 @@ static int cui_process_key(void *arg)
        struct cui *cui = cui_from_arg(arg);
 
        assert(cui->current);
+
+       ui_timer_disable(&cui->timer);
        cui->current->process_key(cui->current);
+
        return 0;
 }
 
+/**
+ * cui_client_process_socket - Process a socket event from the discover server.
+ */
+
 static int cui_client_process_socket(void *arg)
 {
        struct discover_client *client = arg;
@@ -217,6 +223,24 @@ static int cui_client_process_socket(void *arg)
        return 0;
 }
 
+/**
+ * cui_handle_timeout - Handle the timeout.
+ */
+
+static void cui_handle_timeout(struct ui_timer *timer)
+{
+       struct cui *cui = cui_from_timer(timer);
+       struct pmenu_item *i = pmenu_find_selected(cui->main);
+
+#if defined(DEBUG)
+       {
+               struct cui_opt_data *cod = cod_from_item(i);
+               assert(cod && (cod->opt_hash == cui->default_item));
+       }
+#endif
+       i->on_execute(i);
+}
+
 /**
  * cui_handle_resize - Handle the term resize.
  */
@@ -316,15 +340,17 @@ static int cui_device_add(struct device *dev, void *arg)
 
                insert_pt++;
 
-               /* If this is the default_item select it. */
-
-               if (cod->opt_hash == cui->default_item)
-                       selected = i->nci;
-
                pb_log("%s: adding opt '%s'\n", __func__, cod->opt->name);
                pb_log("   image  '%s'\n", cod->kd->image);
                pb_log("   initrd '%s'\n", cod->kd->initrd);
                pb_log("   args   '%s'\n", cod->kd->args);
+
+               /* If this is the default_item select it and start timer. */
+
+               if (cod->opt_hash == cui->default_item) {
+                       selected = i->nci;
+                       ui_timer_kick(&cui->timer);
+               }
        }
 
        /* Re-attach the items array. */
@@ -340,6 +366,9 @@ static int cui_device_add(struct device *dev, void *arg)
                        item_count(cui->main->ncm) + 1);
        }
 
+       /* FIXME: need to make item visible somehow */
+       menu_driver(cui->main->ncm, REQ_SCR_UPAGE);
+       menu_driver(cui->main->ncm, REQ_SCR_DPAGE);
        set_current_item(cui->main->ncm, selected);
 
        if (cui->current == &cui->main->scr)
@@ -375,9 +404,15 @@ static void cui_device_remove(struct device *dev, void *arg)
 
        list_for_each_entry(&dev->boot_options, opt, list) {
                struct pmenu_item *i = pmenu_item_from_arg(opt->ui_info);
+               struct cui_opt_data *cod = cod_from_item(i);
 
-               assert(pb_protocol_device_cmp(dev, cod_from_item(i)->dev));
+               assert(pb_protocol_device_cmp(dev, cod->dev));
                pmenu_remove(cui->main, i);
+
+               /* If this is the default_item disable timer. */
+
+               if (cod->opt_hash == cui->default_item)
+                       ui_timer_disable(&cui->timer);
        }
 
        /* Re-attach the items array. */
@@ -397,10 +432,6 @@ static void cui_device_remove(struct device *dev, void *arg)
                cui->current->post(cui->current);
 }
 
-/**
- * cui_client_process_socket - Process a socket event from the discover server.
- */
-
 static struct discover_client_ops cui_client_ops = {
        .device_add = cui_device_add,
        .device_remove = cui_device_remove,
@@ -434,6 +465,7 @@ struct cui *cui_init(void* platform_info,
        cui->c_sig = pb_cui_sig;
        cui->platform_info = platform_info;
        cui->on_kexec = on_kexec;
+       cui->timer.handle_timeout = cui_handle_timeout;
 
        /* Loop here for scripts that just started the server. */
 
@@ -501,6 +533,8 @@ int cui_run(struct cui *cui, struct pmenu *main, unsigned int default_item)
                if (cui->abort)
                        break;
 
+               ui_timer_process_sig(&cui->timer);
+
                while (cui->resize) {
                        cui->resize = 0;
                        cui_handle_resize(cui);