]> git.neil.brown.name Git - edlib.git/commitdiff
messageline: use lib-renderline for drawing the message line.
authorNeilBrown <neil@brown.name>
Fri, 23 Jun 2023 09:24:30 +0000 (19:24 +1000)
committerNeilBrown <neil@brown.name>
Wed, 28 Jun 2023 07:51:41 +0000 (17:51 +1000)
This provides more flexibility and already allows long lines to wrap -
as is very obvious in the "spell" test case.

Signed-off-by: NeilBrown <neil@brown.name>
13 files changed:
DOC/TODO.md
lib-messageline.c
tests.d/00-basic
tests.d/00-mouse
tests.d/01-c-mode
tests.d/01-hex
tests.d/01-python
tests.d/01-redraw
tests.d/01-textfill
tests.d/02-diff
tests.d/02-grep
tests.d/02-presenter
tests.d/02-spell

index 6de4bfd47cbe245103012451ada85ac4a8a951f9..58d6ff62f9b2ff04cb88340ca1979d2b2b94fdfe 100644 (file)
@@ -19,7 +19,7 @@ the file.
 ### Small
 
 - [X] detect and limit recursion.
-- [ ] message-line: use lib-renderline for the one line, so we have
+- [X] message-line: use lib-renderline for the one line, so we have
       markup support.
 - [ ] history: Make it possible to search through history. Maybe Alt-p only shows
       lines containing current content.
@@ -419,8 +419,11 @@ Module features
 
 ### message-line
 
+- [ ] reset timer each time so that message stay an exact period, and
+      timestamp updates on the minute.
+- [ ] allow marked-up messages to be given.
 - [ ] Differentiate warnings from info, and blink-screen for warnings.
-- [ ] use lib-renderline for the one line, so we have markup support.
+- [X] use lib-renderline for the one line, so we have markup support.
 
 ### docs
 
index 38f518b5310f19ae4d22b75c01bf09832ac919ef..a04f69bd14e88da62e357a27148c0bf6a88a0bfd 100644 (file)
@@ -32,20 +32,12 @@ struct mlinfo {
                         */
        struct pane *line safe, *child;
        struct pane *log;
-       int height; /* height of line */
-       int ascent; /* how far down to baseline */
        int hidden;
        time_t last_message; /* message should stay for at least 10 seconds */
 };
 static struct pane *do_messageline_attach(struct pane *p safe);
-static struct map *messageline_map, *messageline_line_map;
+static struct map *messageline_map;
 DEF_LOOKUP_CMD(messageline_handle, messageline_map);
-DEF_LOOKUP_CMD(messageline_line_handle, messageline_line_map);
-
-static void pane_str(struct pane *p safe, char *s, char *attr, int x, int y)
-{
-       call("Draw:text", p, -1, NULL, s, 0, NULL, attr, x, y);
-}
 
 DEF_CMD(messageline_clone)
 {
@@ -97,7 +89,7 @@ DEF_CMD(messageline_msg)
                                     0, NULL, ci->str);
                }
                time(&mli->last_message);
-               pane_damaged(mli->line, DAMAGED_REFRESH);
+               pane_damaged(ci->home, DAMAGED_VIEW);
        }
        if (strcmp(ci->key, "Message:broadcast") == 0)
                return 1; /* Acknowledge message */
@@ -118,37 +110,32 @@ DEF_CMD(messageline_abort)
        free(mli->modal);
        mli->modal = NULL;
        time(&mli->last_message);
-       pane_damaged(mli->line, DAMAGED_REFRESH);
+       pane_damaged(ci->home, DAMAGED_VIEW);
        return Efallthrough;
 }
 
 DEF_CMD(messageline_refresh_size)
 {
        struct mlinfo *mli = ci->home->data;
-       if (mli->height == 0) {
-               struct call_return cr =
-                       call_ret(all, "Draw:text-size", ci->home, -1, NULL, "M",
-                                0, NULL, "bold");
-               mli->height = cr.y;
-               mli->ascent = cr.i2;
-       }
+       struct pane *p = mli->line;
 
        if (mli->hidden) {
-               pane_resize(mli->line, 0, ci->home->h,
-                           ci->home->w, mli->height);
+               pane_resize(p, 0, ci->home->h,
+                           ci->home->w, ci->home->h / 3);
                if (mli->child)
                        pane_resize(mli->child, 0, 0,
                                    ci->home->w, ci->home->h);
        } else {
-               pane_resize(mli->line, 0, ci->home->h - mli->height,
-                           ci->home->w, mli->height);
-               if (mli->child && ci->home->h > mli->height)
+               pane_resize(p, p->x, p->y, ci->home->w, ci->home->h/3);
+               call("render-line:measure", p);
+               pane_resize(p, p->x, ci->home->h - p->h,
+                           ci->home->w, p->h);
+               if (mli->child && ci->home->h > p->h)
                        pane_resize(mli->child, 0, 0,
                                    ci->home->w,
-                                   ci->home->h - mli->height);
+                                   ci->home->h - p->h);
        }
-       pane_damaged(ci->home, DAMAGED_REFRESH);
-       pane_damaged(mli->line, DAMAGED_REFRESH);
+       pane_damaged(p, DAMAGED_REFRESH);
        return 1;
 }
 
@@ -185,13 +172,13 @@ DEF_CMD(messageline_notify)
                mli->modal = NULL;
                if (mli->message)
                        mli->last_message = time(NULL);
-               pane_damaged(mli->line, DAMAGED_REFRESH);
+               pane_damaged(ci->home, DAMAGED_VIEW);
        }
        if (mli->message &&
            time(NULL) >= mli->last_message + wait_time) {
                free(mli->message);
                mli->message = NULL;
-               pane_damaged(mli->line, DAMAGED_REFRESH);
+               pane_damaged(ci->home, DAMAGED_VIEW);
        }
        if (!mli->message && !mli->modal) {
                pane_drop_notifiers(ci->home, "Keystroke-notify");
@@ -200,11 +187,27 @@ DEF_CMD(messageline_notify)
        return 1;
 }
 
-DEF_CMD(messageline_line_refresh)
+static void pane_str(struct pane *p safe, char *s, char *attr)
+{
+       struct mlinfo *mli = p->parent->data;
+       char *l = strconcat(p, SOH, attr, STX, s, ETX);
+       call("render-line:set", p, -1, NULL, l);
+       /* Allow message line to use up to 1/3 of total height */
+       pane_resize(p, p->x, p->y, p->w, p->parent->h/3);
+       call("render-line:measure", p);
+       if (!mli->hidden) {
+               pane_resize(p, p->x, p->parent->h - p->h, p->w, p->h);
+               if (mli->child) {
+                       struct pane *c = mli->child;
+                       pane_resize(c, 0, 0, c->w, p->parent->h - p->h);
+               }
+       }
+}
+
+DEF_CMD(messageline_refresh)
 {
        struct mlinfo *mli = ci->home->data;
 
-       call("Draw:clear", mli->line, 0, NULL, "bg:white");
        if (mli->message && !mli->modal &&
            time(NULL) >= mli->last_message + 30) {
                free(mli->message);
@@ -213,11 +216,9 @@ DEF_CMD(messageline_line_refresh)
                pane_drop_notifiers(ci->home, "Mouse-event-notify");
        }
        if (mli->modal)
-               pane_str(mli->line, mli->modal, "bold,fg:magenta-60,bg:white",
-                        0, 0 + mli->ascent);
+               pane_str(mli->line, mli->modal, "bold,fg:magenta-60,bg:white");
        else if (mli->message)
-               pane_str(mli->line, mli->message, "bold,fg:red,bg:cyan",
-                        0, 0 + mli->ascent);
+               pane_str(mli->line, mli->message, "bold,fg:red,bg:cyan");
        else {
                char buf[80];
                time_t t;
@@ -231,15 +232,14 @@ DEF_CMD(messageline_line_refresh)
                        strftime(buf, sizeof(buf), "%H:%M %d-%b-%Y", tm);
                else
                        buf[0] = 0;
-               pane_str(mli->line, buf, "bold,fg:blue",
-                        0, 0 + mli->ascent);
+               pane_str(mli->line, buf, "bold,fg:blue");
        }
        return 1;
 }
 
 DEF_CMD(force_refresh)
 {
-       pane_damaged(ci->home, DAMAGED_REFRESH);
+       pane_damaged(ci->home, DAMAGED_VIEW);
        return 1;
 }
 
@@ -254,20 +254,23 @@ static struct pane *do_messageline_attach(struct pane *p safe)
                return NULL;
        call("editor:request:Message:broadcast", ret);
        /* z=1 to avoid clone_children affecting it */
-       mlp = pane_register(ret, 1, &messageline_line_handle.c, mli);
+       mlp = call_ret(pane, "attach-renderline", ret, 1);
        if (!mlp) {
                pane_close(ret);
                return NULL;
        }
+       /* Support wrapping */
+       attr_set_int(&mlp->attrs, "shift_left", -1);
+       pane_damaged(ret, DAMAGED_VIEW);
        mli->line = mlp;
        pane_focus(ret);
        if (!edlib_testing(p))
                /* This can introduce unwanted variablitiy in tests */
-               call_comm("event:timer", mli->line, &force_refresh, 15000);
+               call_comm("event:timer", ret, &force_refresh, 15000);
 
        mli->log = call_ret(pane, "docs:byname", p, 0, NULL, "*Messages*");
        if (!mli->log)
-               mli->log = call_ret(pane, "log:create", p, 0, NULL,
+               mli->log = call_ret(pane, "log:create", ret, 0, NULL,
                                    "*Messages*");
 
        return ret;
@@ -303,7 +306,5 @@ void edlib_init(struct pane *ed safe)
        key_add(messageline_map, "Child-Notify",&messageline_child_notify);
        key_add(messageline_map, "Keystroke-notify", &messageline_notify);
        key_add(messageline_map, "Mouse-event-notify", &messageline_notify);
-
-       messageline_line_map = key_alloc();
-       key_add(messageline_line_map, "Refresh", &messageline_line_refresh);
+       key_add(messageline_map, "Refresh:view", &messageline_refresh);
 }
index ddd61f32d8d149247e0bc34e17a7114d285c2a08..969426c5534c496ee8919e16fe213accd9fb2688 100644 (file)
@@ -605,4 +605,4 @@ Key ":C-X"
 Display 80,30 84F4B35BF26F9D5EEBB67D572ADD0BBF 1,0
 Key ":C-C"
 Display 80,30 4790F2887DC559E9927F4059D9F4365D 1,0
-Close 1530
+Close 1549
index e2093eadf152d94927d8d076879446d8fac6ccef..29d147997e504537882b7321c7a3903f3e9a0cf3 100644 (file)
@@ -40,4 +40,4 @@ Display 80,30 50C981E00FFF0375A7B1A6724D9F8717 17,20
 Mouse ":Press-1" 8,4
 Display 80,30 8A8EA2DF577EB3DC956A0E0CC673A192 8,4
 Mouse ":Release-1" 8,4
-Close 223
+Close 244
index b9dcfabb1e82d806ffdad72039b17f3049894a6b..b9ead397a69623a1944860186958f5c4fabd6196 100644 (file)
@@ -449,4 +449,4 @@ Display 80,30 C436553A7587EAB23E351517263FDE2D 1,22
 Key ":Up"
 Display 80,30 180D801EBB95A8A1F061567BC06BADA6 1,21
 Key ":Tab"
-Close 803
+Close 824
index dc196d51b1dc36db1020d7aa901749172d3ece1d..a83921e3139ca4ed193c4fcf2b27e8e1b86f7887 100644 (file)
@@ -83,4 +83,4 @@ Key ":C-X"
 Display 80,30 45BD9A363837C8B0DAF047FB0002FC1D 14,3
 Key ":C-C"
 Display 80,30 115B1A4CFA0E343777EA20394DC3932E 14,3
-Close 557
+Close 578
index 6324bab7743f7f8100eacf39bfe2f385c79c3065..b37a25f98734739a402f823cce2603549bc49ecc 100644 (file)
@@ -498,4 +498,4 @@ Key ":C-X"
 Display 80,30 FB5AFD4627214C1B1CBEE5CE437CD80A 61,16
 Key ":C-C"
 Display 80,30 32112852551E58C291A5CB45D8CA8ED6 61,16
-Close 843
+Close 864
index 3161802b2e66c24eed62b1ef8bdd68ced4f759aa..8f71155ce7e8daed04f54c3490466ef14b8b9459 100644 (file)
@@ -41,4 +41,4 @@ Key ":C-X"
 Display 80,30 F99CB281FCAB081AD57FCDB39F9BF460 1,8
 Key ":C-C"
 Display 80,30 9C096A8B2633F1429AB22345C20B3B33 1,8
-Close 164
+Close 185
index dcc6854949f793a47689777b37ea6119fbc5f5a9..8fe2d4ce09716769f283b94dc948ea38dffd695e 100644 (file)
@@ -572,4 +572,4 @@ Display 80,30 A2D00677EA9CF8DCC1BCDC3CADA5F113 21,9
 Key "-n"
 Display 80,30 A2D00677EA9CF8DCC1BCDC3CADA5F113 21,10
 Key "-n"
-Close 999
+Close 1020
index 31a6b3daeb161d78210a6e0b35a8137d730d0c32..bf1c8f32207128ee589c04bfc15504116ab8e593 100644 (file)
@@ -95,4 +95,4 @@ Key ":C-X"
 Display 80,30 5E4A44E834E4301432950EA487DD2365 1,9
 Key ":C-C"
 Display 80,30 BE78BD218C4B954F0F53DFE544EE4DB1 1,9
-Close 273
+Close 294
index e662c6921af027ae2795feceb00308c46eb66732..dee2fcbe443af402ac99fc715d4e4f312734819a 100644 (file)
@@ -222,7 +222,7 @@ Display 80,30 DD0B850460093327B7F2F877E46EA378 1,7
 Key "-`"
 Display 80,30 9BFCD6FB7DDEEB9FF736EEE48A983DF2 1,6
 Key "-`"
-Display 80,30 CAEBB71698ADA0E51D9B5E710B1B0969 1,6
+Display 80,30 5BC5B368B3E25A73BE8F8D595D61AEE6 1,6
 Key "-`"
 Display 80,30 3A381382535261F222BA0E5DC190CC2A 1,6
 Key ":A-0"
@@ -241,4 +241,4 @@ Key ":C-X"
 Display 80,30 1B93FE4A0F3F6D0DA9A9A7767239F356 1,6
 Key ":C-C"
 Display 80,30 85E3F3D05E6AE32A75F5507046C60D2A 1,6
-Close 903
+Close 902
index d38b5ee948cad692a33058fe3e22f036e341864b..4af2a39fc2b87be98fc6ce2217e182873d7c17c7 100644 (file)
@@ -221,4 +221,4 @@ Key ":C-X"
 Display 80,30 FBA91029719D49956F70E72B42856A95 41,13
 Key ":C-C"
 Display 80,30 6B5AACDD8610D755C6CCFD94043F1F9E 41,13
-Close 1420
+Close 1441
index f0e159e83d2be3120041020bf6353fff7103d000..f1a5338083ac5f50fb495744a534bdca572a8681 100644 (file)
@@ -206,30 +206,29 @@ Display 80,30 FA1BED2E2C181128F00AEF782927EEA6 20,0
 Key ":A--"
 Display 80,30 13DD8B4A5B03CB54BBC9CC65CCB10272 20,0
 Key ":A-;"
-Display 80,30 F54DBC70726E98A2913EC0407C1B7ABC 8,5
+Display 80,30 187C12D6F0237E56AC725675C438D35D 8,5
 Key "-0"
-Display 80,30 0F01FA025124C1D7428D977AD07E4BEF 9,8
+Display 80,30 C60B776C161AC49D15E0B343E3A80200 9,8
 Key "-1"
-Display 80,30 E99CC0667BF4D51F70A00603488D7966 68,8
+Display 80,30 A7E960EF28E8FBEF8CE1D3934F114A8D 68,8
 Key "-2"
-Display 80,30 0D4F4437FB62A61B5447187A217BD5B3 8,15
+Display 80,30 FBDF992D22B009C514FDF2D2FDDCA4D7 8,15
 Key "-0"
-Display 80,30 75251A2017C61E2DE0A05ECD9DD5C7A0 13,18
+Display 80,30 043355AE1F8D1C60B714F84CAC2051DB 13,18
 Key "-1"
-Display 80,30 D3EC505D9F645F71622B46D6B1764BE1 30,23
+Display 80,30 736A56D79B465AA8A1BACE1DBC411CF9 30,22
 Key "- "
-Display 80,30 9A79A279F4348B4A1A24A13407C97211 6,25
+Display 80,30 CAA9CDFD50E6851E95BAC003879567A1 6,21
 Key "- "
-Display 80,30 25A416536F894D9F370AC7FB951E449B 59,27
-Display 80,30 077B6F221D9986860543469734275599 59,27
+Display 80,30 5E0A22C09D987BE6C6C07940B9B0E578 59,24
 Key ":Enter"
-Display 80,30 2EC831068E8DF773F9B5DF3EC997999E 59,27
+Display 80,30 0F4F95C15DA7193E6417004D2E499978 59,24
 Key ":C-X"
-Display 80,30 5E26219ECB9E5DDA49D0CD1B5F90FFA2 59,27
+Display 80,30 9599A4BF3962C00266BB8CF8D9AB3088 59,24
 Key ":C-S"
-Display 80,30 EAF91CE03C40FCE8DDB5D6FEA4E0052D 59,27
+Display 80,30 15D263B1D5B3FDF5F97D3428BAC8D27A 59,24
 Key ":C-X"
-Display 80,30 C60DD4C6AF97BED906B64520D5A4A0D2 59,27
+Display 80,30 4EEC8A848EC8816669FCC7D1F8E9717F 59,24
 Key ":C-C"
-Display 80,30 7D8FEE03B08CF6048D8C702DD641B86C 59,27
-Close 475
+Display 80,30 DB7F73E268B8F087996B4A4574F042E3 59,24
+Close 606