From: NeilBrown Date: Fri, 23 Jun 2023 09:24:30 +0000 (+1000) Subject: messageline: use lib-renderline for drawing the message line. X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=286ebbfb2395edbc46a6aa53e78bc98254b244df;p=edlib.git messageline: use lib-renderline for drawing the message line. This provides more flexibility and already allows long lines to wrap - as is very obvious in the "spell" test case. Signed-off-by: NeilBrown --- diff --git a/DOC/TODO.md b/DOC/TODO.md index 6de4bfd4..58d6ff62 100644 --- a/DOC/TODO.md +++ b/DOC/TODO.md @@ -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 diff --git a/lib-messageline.c b/lib-messageline.c index 38f518b5..a04f69bd 100644 --- a/lib-messageline.c +++ b/lib-messageline.c @@ -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); } diff --git a/tests.d/00-basic b/tests.d/00-basic index ddd61f32..969426c5 100644 --- a/tests.d/00-basic +++ b/tests.d/00-basic @@ -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 diff --git a/tests.d/00-mouse b/tests.d/00-mouse index e2093ead..29d14799 100644 --- a/tests.d/00-mouse +++ b/tests.d/00-mouse @@ -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 diff --git a/tests.d/01-c-mode b/tests.d/01-c-mode index b9dcfabb..b9ead397 100644 --- a/tests.d/01-c-mode +++ b/tests.d/01-c-mode @@ -449,4 +449,4 @@ Display 80,30 C436553A7587EAB23E351517263FDE2D 1,22 Key ":Up" Display 80,30 180D801EBB95A8A1F061567BC06BADA6 1,21 Key ":Tab" -Close 803 +Close 824 diff --git a/tests.d/01-hex b/tests.d/01-hex index dc196d51..a83921e3 100644 --- a/tests.d/01-hex +++ b/tests.d/01-hex @@ -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 diff --git a/tests.d/01-python b/tests.d/01-python index 6324bab7..b37a25f9 100644 --- a/tests.d/01-python +++ b/tests.d/01-python @@ -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 diff --git a/tests.d/01-redraw b/tests.d/01-redraw index 3161802b..8f71155c 100644 --- a/tests.d/01-redraw +++ b/tests.d/01-redraw @@ -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 diff --git a/tests.d/01-textfill b/tests.d/01-textfill index dcc68549..8fe2d4ce 100644 --- a/tests.d/01-textfill +++ b/tests.d/01-textfill @@ -572,4 +572,4 @@ Display 80,30 A2D00677EA9CF8DCC1BCDC3CADA5F113 21,9 Key "-n" Display 80,30 A2D00677EA9CF8DCC1BCDC3CADA5F113 21,10 Key "-n" -Close 999 +Close 1020 diff --git a/tests.d/02-diff b/tests.d/02-diff index 31a6b3da..bf1c8f32 100644 --- a/tests.d/02-diff +++ b/tests.d/02-diff @@ -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 diff --git a/tests.d/02-grep b/tests.d/02-grep index e662c692..dee2fcbe 100644 --- a/tests.d/02-grep +++ b/tests.d/02-grep @@ -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 diff --git a/tests.d/02-presenter b/tests.d/02-presenter index d38b5ee9..4af2a39f 100644 --- a/tests.d/02-presenter +++ b/tests.d/02-presenter @@ -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 diff --git a/tests.d/02-spell b/tests.d/02-spell index f0e159e8..f1a53380 100644 --- a/tests.d/02-spell +++ b/tests.d/02-spell @@ -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