shithub: orca

Download patch

ref: 4631c7732dfc7497622a7a1e5bb6a5ced7e617e2
parent: 8ab1e0cbc9512fc4142a49b6cf604db0bb37c185
author: cancel <cancel@cancel.fm>
date: Thu Dec 13 17:36:55 EST 2018

Cleanup

--- a/examples/_benchmark.orca
+++ b/examples/_benchmark.orca
@@ -1,46 +1,46 @@
 #.......A.......B.......C.......D.......E.......F.......G.......H.......I.......J.......K.......L.......M......#
 ................................................................................................................
 ........A.......B.......C.......D...............F...............H.......I.......J.......K.......Lc......M.......
-........0...............0.......................1.......................4...............................0.......
+........0...............8.......*...............1.......................3...............................0.......
 ................................................................................................................
 ........A2......B1......C2.....0D...............F2.............0H.......I2.....................0Lc......M2......
-........................0.......................0...............123.....6...............................0.......
+........2.......*.......0.......*...............0...............123.....7...............................0.......
 ................................................................................................................
 ........A.2.....B0......Cc.....2D...............F.2............1H.......I.2....................1Lc......M.2.....
-........................0.......................0...............123.....0...............................0.......
+........2...............8.......*...............0...............123.....1...............................0.......
 ................................................................................................................
-........A22.....Bw.....0C......3D0..............F22............2H.......I22....................2Lc......M22.....
-........................0.......................1...............123.....2...............................0.......
+........A22.....Bw.....0C......3D0..............F22............2H.......I22....................2L.c.....M22.....
+........4.......*.......8.......................1...............123.....2...............................0.......
 ................................................................................................................
 ........A23.....Bs.....1C2.....4D1..............F23.....................I23....................3L.c.....M23.....
-........................0.......................0.......................2...............................2.......
+........5.......*.......0.......................0.......................2...............................2.......
 ................................................................................................................
 ........A2K.....Be.....2Cc.....4D2..............F2K.....................I2K.............................M9K.....
-........................0.......................0.......................2...............................9.......
+........m.......*.......4.......................0.......................b...............................9.......
 ................................................................................................................
 ........AK2.....Bw.....3C4.....gD8..............FKK.....................IK2.............................MK6.....
-........................0.......................1.......................k...............................2.......
+........m.......*.......2.......*...............1.......................k...............................2.......
 ................................................................................................................
 #.......N.......O.......P.......Q.......R.......S.......T.......U.......V.......W.......X.......Y.......Z......#
 ................................................................................................................
 ................O......2P1......Q.......R...............Tc......U.......V...............X.......................
-........................................0.......................................................................
+................................0.......0...............c.......................................................
 ................................................................................................................
 ..............0.O2....1.P1.....1Q2......R2.............3Tc.............aV5............0.X2......................
-................2.......................1.......................................................................
+................2...............1.......0...............c...............................2.......................
 ................................................................................................................
 ...............0O2....2.P......2Q2......R.2...........4.Tc..............Va.............0X2......................
-................2.......................0.......................................................................
+................2...............1.......0...............c...............5...............2.......................
 ................................................................................................................
 ..............20O23............3Q22.....R22...........03Tc..............Vb............20X23.....................
-................3.......................2.......................................................................
+................................2.......2...............c.................................2.....................
 ................................................................................................................
 ..............10O23............4Q23.....R24...........13Tc.............cVc............10X23.....................
-................2.......................2.......................................................................
+................3...............2.......3................................................2......................
 ................................................................................................................
 ..............11O..............4Q9K.....R2K...........c3Tc..............Vc............11X.......................
-................44......................3................................................4......................
+.................4..............2.......j...............c...............c.......................................
 ................................................................................................................
 ...............................0Q.......RKK...........50T.......................................................
-........................................k.......................................................................
-................................................................................................................
\ No newline at end of file
+................................0.......k.......................................................................
+................................................................................................................
--- a/term_util.c
+++ b/term_util.c
@@ -89,15 +89,17 @@
   wprintw(qb->outer_window, title);
 }
 
-Qnav_block* qnav_push_message(int height, int width) {
-  Qnav_block* qb = malloc(sizeof(Qnav_block));
-  qnav_stack_push(Qnav_type_message, height, width, qb);
-  qnav_draw_box(qb);
-  return qb;
+WINDOW* qmsg_window(Qmsg* qm) { return qm->nav_block.content_window; }
+
+Qmsg* qmsg_push(int height, int width) {
+  Qmsg* qm = malloc(sizeof(Qmsg));
+  qnav_stack_push(Qnav_type_msg, height, width, &qm->nav_block);
+  qnav_draw_box(&qm->nav_block);
+  return qm;
 }
 
-bool qnav_drive_message(Qnav_block* qb, int key) {
-  (void)qb;
+bool qmsg_drive(Qmsg* qm, int key) {
+  (void)qm;
   switch (key) {
   case ' ':
   case 27:
@@ -108,6 +110,8 @@
   return false;
 }
 
+Qmsg* qmsg_of(Qnav_block* qb) { return ORCA_CONTAINER_OF(qb, Qmsg, nav_block); }
+
 void qmenu_start(Qmenu* qm) { memset(qm, 0, sizeof(Qmenu)); }
 void qmenu_add_text_item(Qmenu* qm, char const* text, int id) {
   ITEM* item = new_item(text, NULL);
@@ -144,11 +148,12 @@
 
 void qnav_free_block(Qnav_block* qb) {
   switch (qb->tag) {
-  case Qnav_type_message: {
-    free(qb);
+  case Qnav_type_msg: {
+    Qmsg* qm = qmsg_of(qb);
+    free(qm);
   } break;
   case Qnav_type_qmenu: {
-    Qmenu* qm = ORCA_CONTAINER_OF(qb, Qmenu, nav_block);
+    Qmenu* qm = qmenu_of(qb);
     qmenu_free(qm);
   } break;
   }
--- a/term_util.h
+++ b/term_util.h
@@ -40,7 +40,7 @@
 void term_util_init_colors();
 
 typedef enum {
-  Qnav_type_message,
+  Qnav_type_msg,
   Qnav_type_qmenu,
 } Qnav_type_tag;
 
@@ -58,6 +58,10 @@
 
 typedef struct {
   Qnav_block nav_block;
+} Qmsg;
+
+typedef struct {
+  Qnav_block nav_block;
   MENU* ncurses_menu;
   ITEM* ncurses_items[32];
   Usz items_count;
@@ -89,8 +93,10 @@
 Qnav_block* qnav_top_block();
 void qnav_stack_pop();
 
-Qnav_block* qnav_push_message(int height, int width);
-bool qnav_drive_message(Qnav_block* qb, int key);
+Qmsg* qmsg_push(int height, int width);
+WINDOW* qmsg_window(Qmsg* qm);
+bool qmsg_drive(Qmsg* qm, int key);
+Qmsg* qmsg_of(Qnav_block* qb);
 
 void qmenu_start(Qmenu* qm);
 void qmenu_add_text_item(Qmenu* qm, char const* text, int id);
--- a/tui_main.c
+++ b/tui_main.c
@@ -1464,8 +1464,8 @@
   if (!ged->filename)
     return;
   bool ok = hacky_try_save(&ged->field, ged->filename);
-  Qnav_block* msg = qnav_push_message(3, 50);
-  WINDOW* msgw = msg->content_window;
+  Qmsg* msg = qmsg_push(3, 50);
+  WINDOW* msgw = qmsg_window(msg);
   wmove(msgw, 0, 1);
   if (ok) {
     wprintw(msgw, "Saved to: %s", ged->filename);
@@ -1758,8 +1758,9 @@
     Qnav_block* qb = qnav_top_block();
     if (qb) {
       switch (qb->tag) {
-      case Qnav_type_message: {
-        if (qnav_drive_message(qb, key))
+      case Qnav_type_msg: {
+        Qmsg* qm = qmsg_of(qb);
+        if (qmsg_drive(qm, key))
           qnav_stack_pop();
       } break;
       case Qnav_type_qmenu: {
@@ -1779,8 +1780,8 @@
                 try_save_with_msg(&ged_state);
               } break;
               case Menu_id_save_as: {
-                Qnav_block* msg = qnav_push_message(3, 30);
-                WINDOW* msgw = msg->content_window;
+                Qmsg* msg = qmsg_push(3, 30);
+                WINDOW* msgw = qmsg_window(msg);
                 wmove(msgw, 0, 1);
                 wprintw(msgw, "Not yet implemented");
               } break;