Add more meaning to render:wrap and discard shift-left and shift_left.
It was confusing having two ... or three ... attributes for almost the
same thing.
Signed-off-by: NeilBrown <neil@brown.name>
perform detailed drawing of the background
+ "color:COLOUR" - fills the background with the given colour.
+ "image:IMAGE" - the image is drawn to fill the pane
-- "render-wrap" - if set to any value other than "yes", text is not
- wrapped.
+- "render-wrap" - How to handle lines wider than the pane:
+ - if "yes" wrap the line onto multiple lines.
+ - if "NN" shift the line "NN" character spaces (in standard font) to left.
+ - if "NN auto", update as needed so that cursor is displayed.
+ - if not set, treat as "yes"
+ - if any other value, treat as "0 auto"
- "render-vmargin" - if set to a number of lines, "render-lines" will
attempt to keep the cursor at least this far from the top or bottom
of the display.
The pane's behaviour can be modified by several attributes that can be
found in the stack:
-- "shift_left" - this should be in integer. If less than zero the line
- will be wrapped if it is too wide to display completely in the pane.
- If it is non-negative then the display will not be wrapped and the
- display will be shifted to the left this far so later parts of the
- line can be seen.
+- "render:wrap" - this is processed the same way that render-lines
+ understands it, though no "auto" adjustment is made. It either
+ requests wrap or sets the shift size.
- "prefix" - This marked-up text will be display first. It will not be
shifted even when the main text is shifted left.
replacement string is shorter. If longer, they get added.
- [X] path completion in shell command. If cannot find look for '/'
following punctuation (=) and try there.
-- [ ] resolve shift-left vs shift_left distinction - add a "fixed" suffix?
+- [X] resolve shift-left vs shift_left distinction - add a "fixed"
+ suffix? Also consider render-wrap
- [ ] should zoom affect whole window, not just pane?
- [X] ditch cached-size for images - store in pane data instead.
- [X] use foreach_attr for parsing image details
- "scale" - width/height values to aim for - in "points" which are 1/10 for an M
e.g. if 800x240, then text is scaled so that at least 80 M's fit across,
and 24 M's fit down.
- - "render-wrap" - if define but not "yes", don't wrap long lines, else shift left to
- fit cursor on pane.
+ - "render-wrap" - How to handle lines wider than the pane:
+ - if "yes" wrap the line onto multiple lines.
+ - if "NN" shift the line "NN" character spaces (in standard font) to left.
+ - if "NN auto", update as needed so that cursor is displayed.
+ - if not set, treat as "yes"
+ - if any other value, treat as "0 auto"
- "prefix" - text to place at start of each line. This can be used as a prompt in a
dialogue box.
if (!c)
return dflt;
rv = strtol(c, &end, 10);
- if (end == c || !end || *end)
+ if (end == c || !end || (*end && *end != ' '))
return dflt;
return rv;
}
call("render-line:set", ci->focus, b.len, NULL, buf_final(&b));
for (i = 0; i < 10; i++) {
int cw;
- attr_set_int(&ci->focus->attrs, "shift_left", shift);
+ attr_set_int(&ci->focus->attrs, "render-wrap", shift);
call("render-line:measure", ci->focus, b.len);
cw = pane_attr_get_int(ci->focus, "curs_width", 1);
if (ci->home->parent->cx < ci->home->parent->w - cw)
return Efail;
call("doc:set:autoclose", docp, 1);
attr_set_str(&docp->attrs, "render-simple", "format");
- attr_set_str(&docp->attrs, "shift-left", "0");
+ attr_set_int(&docp->attrs, "render-wrap", 0);
attr_set_str(&docp->attrs, "heading", "");
attr_set_str(&docp->attrs, "line-format", "<action-activate:menu-select>%name</>");
attr_set_str(&docp->attrs, "done-key", ci->str2 ?: "menu-done");
return NULL;
}
/* Support wrapping */
- attr_set_int(&mlp->attrs, "shift_left", -1);
+ attr_set_str(&mlp->attrs, "render:wrap", "yes");
pane_damaged(ret, DAMAGED_VIEW);
mli->line = mlp;
pane_focus(ret);
*/
struct rline_data *rd = &p->data;
struct render_item *ri, *wraprl;
- int shift_left = pane_attr_get_int(focus, "shift_left", 0);
+ int shift_left = pane_attr_get_int(focus, "render-wrap", -1);
bool wrap = shift_left < 0;
int wrap_margin;
int right_margin;
int rpt = ci->num;
int shift;
- shift = pane_attr_get_int(ci->focus, "shift-left", -1);
+ shift = pane_attr_get_int(ci->focus, "render-wrap", -1);
if (strcmp(ci->key, "K:CX->") == 0 || strcmp(ci->key, "K->") == 0)
rpt = -rpt;
if (rpt == NO_NUMERIC) {
shift += rpt;
}
if (shift < 0)
- attr_set_str(&ci->focus->attrs, "shift-left", "");
+ attr_set_str(&ci->focus->attrs, "render-wrap", "yes");
+ else if (shift > 0)
+ attr_set_int(&ci->focus->attrs, "render-wrap", shift);
+ else if (rpt > 0)
+ attr_set_str(&ci->focus->attrs, "render-wrap", "0 auto");
else
- attr_set_int(&ci->focus->attrs, "shift-left", shift);
+ /* When reducing shift to zero, don't enable auto */
+ attr_set_int(&ci->focus->attrs, "render-wrap", 0);
call("view:changed", ci->focus);
call("Mode:set-num2", ci->focus, N2_shift);
call("Message:modal", ci->focus, 0, NULL, "Type < or > to shift again");
struct mark *mk safe, short cursor_offset,
char **cursor_attr)
{
+ struct rl_data *rl = p->data;
struct pane *hp = mk->mdata;
struct call_return cr;
if (!mark_valid(mk) || !hp)
return False;
pane_resize(hp, hp->x, hp->y, p->w, p->h);
+ if (!rl->shift_locked) {
+ int sl = pane_attr_get_int(focus, "render-wrap", -2);
+ if (sl != rl->shift_left) {
+ char *sla = NULL;
+ asprintf(&sla, "%d auto", rl->shift_left);
+ attr_set_str(&focus->attrs, "render-wrap", sla);
+ free(sla);
+ }
+ }
cr = pane_call_ret(all, hp, "render-line:measure",
focus, cursor_offset);
if (cursor_attr)
return y;
}
-DEF_CMD(render_lines_get_attr)
-{
- struct rl_data *rl = ci->home->data;
-
- if (ci->str && strcmp(ci->str, "shift_left") == 0) {
- char ret[10];
- if (rl->do_wrap && !rl->shift_locked)
- return comm_call(ci->comm2, "cb", ci->focus,
- 0, NULL, "-1");
- snprintf(ret, sizeof(ret), "%d", rl->shift_left);
- return comm_call(ci->comm2, "cb", ci->focus, 0, NULL, ret);
- }
- return Efallthrough;
-}
-
DEF_CMD(render_lines_point_moving)
{
struct pane *p = ci->home;
struct mark *pm = NULL;
struct mark *m1, *m2;
bool refresh_all = False;
+ bool wrap;
char *hdr;
char *a;
int shift;
a = pane_attr_get(focus, "render-wrap");
- if (rl->do_wrap != (!a || strcmp(a, "yes") ==0)) {
- rl->do_wrap = (!a || strcmp(a, "yes") ==0);
+ wrap = (!a || strcmp(a, "yes") == 0);
+ if (rl->do_wrap != wrap) {
+ rl->do_wrap = wrap;
refresh_all = True;
+ rl->shift_left = 0;
+ }
+ if (wrap)
+ rl->shift_locked = True;
+ if (!a)
+ /* avoid any ambiguity */
+ attr_set_str(&focus->attrs, "render-wrap", "yes");
+
+ if (a) {
+ char *end;
+ shift = strtol(a, &end, 10);
+ if (end == a || (end && *end && *end != ' '))
+ shift = -1;
}
+ else
+ shift = -1;
- shift = pane_attr_get_int(focus, "shift-left", -1);
- if (shift >= 0) {
+ if (a && shift >= 0) {
if (rl->shift_left != shift)
refresh_all = True;
rl->shift_left = shift;
- rl->shift_locked = 1;
- } else {
+ rl->shift_locked = strstr(a, "auto") == NULL;
+ } else if (!wrap) {
+ /* unrecognised - no wrap, not locked */
if (rl->shift_locked)
refresh_all = True;
+ rl->shift_left = 0;
rl->shift_locked = 0;
+ attr_set_str(&focus->attrs, "render-wrap", "0 auto");
}
if (refresh_all) {
struct mark *v;
key_add(rl_map, "Refresh:view", &render_lines_revise);
key_add(rl_map, "Refresh:size", &render_lines_resize);
key_add(rl_map, "Notify:clip", &render_lines_clip);
- key_add(rl_map, "get-attr", &render_lines_get_attr);
key_add(rl_map, "mark:moving", &render_lines_point_moving);
key_add(rl_map, "doc:replaced", &render_lines_notify_replace);