diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2022-05-06 07:18:45 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2022-05-06 07:18:45 -0700 |
commit | bbaa0628b2bd81ef47bee702b184e72568319f45 (patch) | |
tree | 80e2e4c437b01dd83b477133e124ac44c0f77837 /pw.c | |
parent | 668c0d87b56e3f1b8fa7992bbd1709dbaaa89470 (diff) | |
download | pw-bbaa0628b2bd81ef47bee702b184e72568319f45.tar.gz pw-bbaa0628b2bd81ef47bee702b184e72568319f45.tar.bz2 pw-bbaa0628b2bd81ef47bee702b184e72568319f45.zip |
Rewrite buggy middle pane logic.
Diffstat (limited to 'pw.c')
-rw-r--r-- | pw.c | 71 |
1 files changed, 24 insertions, 47 deletions
@@ -399,56 +399,33 @@ static void drawline(pwstate *pw, const char *line, int lineno) } if (vsplit2 > 0) { - unsigned pos = line - oline; - unsigned delta = vs2pos - pos; - if (pos + len <= vs2pos) { - unsigned i = vsplit2; - if (vsplit1) { - hlchar(pw, '|'); - i--; - } - for (; i > 0; i--) - putchar(' '); - columns -= vsplit2; - if (len < vsplit2) { - line += len; - len = 0; - } else { - len -= vsplit2; - line += vsplit2; - } - endmark = 1; - } else if (len - delta <= vsplit2) { - unsigned spaces = vsplit2 - (len - delta) + 1; - if (vsplit1) { - hlchar(pw, '|'); - delta++; - } - fputs(line + delta, stdout); - for (unsigned i = spaces; i > 0; i--) - putchar(' '); - columns -= vsplit2; - if (len < vsplit2) { - line += len; - len = 0; - } else { - len -= vsplit2; - line += vsplit2; - } - endmark = 1; - } else { - unsigned start = 0; - if (vsplit1) { - hlchar(pw, '|'); - start++; - } - for (unsigned i = start; i < vsplit2; i++) - putchar(line[delta + i]); + unsigned width = vsplit2; + unsigned i = 0; + + if (vsplit1) { + hlchar(pw, '|'); + width--; + } + if (vs2pos < olen) { + unsigned nchar = min(olen - vs2pos, width); + const char *ptr = oline + vs2pos; + for (; i < nchar; i++) + putchar(*ptr++); + } + for (; i < width; i++) + putchar(' '); + + columns -= vsplit2; + + if (len >= vsplit2) { line += vsplit2; len -= vsplit2; - columns -= vsplit2; - endmark = 1; + } else { + line += len; + len = 0; } + + endmark = 1; } if ((size_t) pw->hpos + 1 <= len) { |