Skip to content

Commit

Permalink
fix: various incorrect behaivors around line wrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
ikozyris committed Jul 16, 2024
1 parent 07d01dd commit 79ea129
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
16 changes: 12 additions & 4 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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;

Expand Down Expand Up @@ -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
Expand All @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions utils/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions utils/sizes.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"};
Expand All @@ -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;
}

0 comments on commit 79ea129

Please sign in to comment.