From 79ea1292cf6eb463b823cb67ca89e33ed14c03f4 Mon Sep 17 00:00:00 2001 From: ikozyris <80053394+ikozyris@users.noreply.github.com> Date: Wed, 17 Jul 2024 00:42:16 +0300 Subject: [PATCH] fix: various incorrect behaivors around line wrapping --- main.cpp | 16 ++++++++++++---- utils/io.cpp | 4 ++-- utils/sizes.c | 4 ++-- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/main.cpp b/main.cpp index 8ead0f5..76373f5 100755 --- a/main.cpp +++ b/main.cpp @@ -154,8 +154,12 @@ int main(int argc, char *argv[]) wmove(text_win, y, maxx - 1); } else if (x > 0) wmove(text_win, y, x - 1); - else if (y > 0) - wmove(text_win, y - 1, (--it)->len); + else if (y > 0) { + if (ofx > 0) + print_line(*it); + wmove(text_win, y - 1, min((--it)->len, maxx -1)); + ofx = 0; + } break; case RIGHT: @@ -171,8 +175,12 @@ int main(int argc, char *argv[]) } else if (ry != curnum ? rx < it->len - 1 : rx < it->len) wmove(text_win, y, x + 1); else if (ry < curnum) { + wmove(text_win, y, 0); + if (ofx > 0) + print_line(*it); wmove(text_win, y + 1, 0); ++it; + ofx = 0; } break; @@ -208,7 +216,7 @@ int main(int argc, char *argv[]) case HOME: wmove(text_win, y, 0); x = 0; rx = ofx; - if (x == 0 && rx >= maxx - 1) { // line has been wrapped + if (ofx >= it->len - maxx) { // line has been wrapped wclrtoeol(text_win); print_line(*it); #ifdef HIGHLIGHT @@ -229,7 +237,7 @@ int main(int argc, char *argv[]) data2(*it, it->len - maxx, it->len); waddnstr(text_win, lnbuf, maxx - 1); - ofx = it->len - maxx; + ofx += it->len - maxx; } break; diff --git a/utils/io.cpp b/utils/io.cpp index 46c2cef..cbe9df1 100644 --- a/utils/io.cpp +++ b/utils/io.cpp @@ -35,11 +35,11 @@ char *input_header(const char *q) return tmp; } -long print_line(gap_buf &buffer) +unsigned print_line(gap_buf &buffer) { if (buffer.len == 0) return 0; - unsigned rlen = data(buffer, 0, min(buffer.len, maxx)) - 1; + unsigned rlen = data(buffer, 0, min(buffer.len, maxx * 2)) - 1; if (lnbuf[rlen - 1] == '\n') --rlen; for (unsigned i = 0; i < rlen && getcurx(text_win) < maxx - 1; ++i) diff --git a/utils/sizes.c b/utils/sizes.c index 45b0f6e..a1d2ded 100644 --- a/utils/sizes.c +++ b/utils/sizes.c @@ -8,7 +8,7 @@ const char *itoa(long a) } // convert bytes to base-10 human-readable string e.g 1024 = 1.024KB = 1KiB -char *hrsize(size_t bytes) +const char *hrsize(size_t bytes) { char *suffix[] = {(char*)"B", (char*)"KB", (char*)"MB", (char*)"GB", (char*)"TB"}; @@ -31,5 +31,5 @@ unsigned sizeofline(unsigned y) { wmove(text_win, y, i); while ((winch(text_win) & A_CHARTEXT) == ' ') wmove(text_win, y, --i); - return i+2; + return i + 2; }