aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pw.c71
1 files changed, 24 insertions, 47 deletions
diff --git a/pw.c b/pw.c
index a8a8bef..dca5cff 100644
--- a/pw.c
+++ b/pw.c
@@ -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) {