shithub: orca

Download patch

ref: c13bb9937b6ff2445e9f38fb052486491468ac33
parent: cf733a4c2e4e95184712af85478fe8ef40c27713
author: cancel <cancel@cancel.fm>
date: Tue Jan 14 02:45:24 EST 2020

Change "saved ok" msg to dismiss on any key press

Also will no longer eat the key event.

--- a/term_util.c
+++ b/term_util.c
@@ -35,6 +35,7 @@
 
 struct Qmsg {
   Qblock qblock;
+  Qmsg_dismiss_mode dismiss_mode;
 };
 
 struct Qmenu_item_extra {
@@ -212,9 +213,16 @@
   qblock_set_title(&qm->qblock, title);
 }
 
+void qmsg_set_dismiss_mode(Qmsg *qm, Qmsg_dismiss_mode mode) {
+  if (qm->dismiss_mode == mode)
+    return;
+  qm->dismiss_mode = mode;
+}
+
 Qmsg *qmsg_push(int height, int width) {
   Qmsg *qm = malloc(sizeof(Qmsg));
   qblock_init(&qm->qblock, Qblock_type_qmsg);
+  qm->dismiss_mode = Qmsg_dismiss_mode_explicitly;
   qnav_stack_push(&qm->qblock, height, width);
   return qm;
 }
@@ -270,13 +278,26 @@
   return msg;
 }
 
-bool qmsg_drive(Qmsg *qm, int key) {
-  (void)qm;
+bool qmsg_drive(Qmsg *qm, int key, Qmsg_action *out_action) {
+  memset(out_action, 0, sizeof(Qmsg_action));
+  Qmsg_dismiss_mode dm = qm->dismiss_mode;
+  switch (dm) {
+  case Qmsg_dismiss_mode_explicitly:
+    break;
+  case Qmsg_dismiss_mode_easily:
+    out_action->dismiss = true;
+    return true;
+  case Qmsg_dismiss_mode_passthrough:
+    out_action->dismiss = true;
+    out_action->passthrough = true;
+    return true;
+  }
   switch (key) {
   case ' ':
   case 27:
   case '\r':
   case KEY_ENTER:
+    out_action->dismiss = true;
     return true;
   }
   return false;
--- a/term_util.h
+++ b/term_util.h
@@ -106,6 +106,16 @@
   Qform_action_any any;
 } Qform_action;
 
+typedef enum {
+  Qmsg_dismiss_mode_explicitly,  // Space, return, escape dismiss. Default.
+  Qmsg_dismiss_mode_easily,      // Any key dismisses.
+  Qmsg_dismiss_mode_passthrough, // Easily, and pass through key event.
+} Qmsg_dismiss_mode;
+
+typedef struct {
+  bool dismiss : 1, passthrough : 1;
+} Qmsg_action;
+
 void qnav_init(void);
 void qnav_deinit(void);
 Qblock *qnav_top_block(void);
@@ -119,7 +129,8 @@
     ORCA_TERM_UTIL_PRINTF(2, 3);
 WINDOW *qmsg_window(Qmsg *qm);
 void qmsg_set_title(Qmsg *qm, char const *title);
-bool qmsg_drive(Qmsg *qm, int key);
+void qmsg_set_dismiss_mode(Qmsg *qm, Qmsg_dismiss_mode mode);
+bool qmsg_drive(Qmsg *qm, int key, Qmsg_action *out_action);
 Qmsg *qmsg_of(Qblock *qb);
 
 Qmenu *qmenu_create(int id);
--- a/tui_main.c
+++ b/tui_main.c
@@ -2176,7 +2176,8 @@
     return false;
   bool ok = hacky_try_save(field, osoc(str));
   if (ok) {
-    qmsg_printf_push(NULL, "Saved to:\n%s", osoc(str));
+    Qmsg *qm = qmsg_printf_push(NULL, "Saved to:\n%s", osoc(str));
+    qmsg_set_dismiss_mode(qm, Qmsg_dismiss_mode_passthrough);
   } else {
     qmsg_printf_push("Error Saving File", "Unable to save file to:\n%s",
                      osoc(str));
@@ -3163,8 +3164,13 @@
       switch (qb->tag) {
       case Qblock_type_qmsg: {
         Qmsg *qm = qmsg_of(qb);
-        if (qmsg_drive(qm, key))
-          qnav_stack_pop();
+        Qmsg_action act;
+        if (qmsg_drive(qm, key, &act)) {
+          if (act.dismiss)
+            qnav_stack_pop();
+          if (act.passthrough)
+            ungetch(key);
+        }
       } break;
       case Qblock_type_qmenu: {
         Qmenu *qm = qmenu_of(qb);