Skip to content

Commit

Permalink
treewide: clean up wmove
Browse files Browse the repository at this point in the history
  • Loading branch information
ikozyris committed Nov 1, 2024
1 parent 26f27e5 commit 68bc256
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 28 deletions.
12 changes: 4 additions & 8 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ int main(int argc, char *argv[])
if (ry >= curnum) // do not scroll indefinetly
break;
if (!wrap.empty()) { // revert wrap
wmove(text_win, y, 0);
print_line(*it);
mvprint_line(y, 0, *it, 0, 0);
}
++it;
wrap.clear();
Expand All @@ -106,8 +105,7 @@ int main(int argc, char *argv[])

case UP:
if (!wrap.empty()) { // revert wrap
wmove(text_win, y, 0);
print_line(*it);
mvprint_line(y, 0, *it, 0, 0);
} if (y == 0 && ofy != 0)
scrollup();
else if (y != 0) {
Expand Down Expand Up @@ -255,11 +253,9 @@ int main(int argc, char *argv[])
if (x == maxx - 1) { // wrap line
wrap.push_back(maxx - 1);
rx = ofx += maxx - 1;
clrln;
mvprint_line(y, 1, *it, ofx, 0);
wmove(text_win, y, x = 0);
wclrtoeol(text_win);
wmove(text_win, y, 1);
print_line(*it, ofx);
wmove(text_win, y, 0);
} if (at(*it, rx) == '\t') {
waddnwstr(text_win, s, 1);
if (x % 8 >= 7)
Expand Down
6 changes: 4 additions & 2 deletions utils/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ char *input_header(const char *q)
return tmp;
}

#define clrln (wmove(text_win, y, 0), wclrtoeol(text_win))
#define mvprint_line(y, x, buffer, from, to) (wmove(text_win, y,x), print_line(buffer, from, to))

// prints substring of buffer, if (to == 0) print until maxx
unsigned print_line(const gap_buf &buffer, unsigned from = 0, unsigned to = 0)
{
Expand Down Expand Up @@ -67,11 +70,10 @@ void print_text(unsigned line)
wclrtobot(text_win);
wmove(text_win, line, 0);
for (unsigned ty = line; ty < min(curnum + ofy + 1, maxy) && iter != text.end(); ++iter) {
print_line(*iter);
mvprint_line(ty++, 0, *iter, 0, 0);
#ifdef HIGHLIGHT
apply(ty);
#endif
wmove(text_win, ++ty, 0);
}
}

Expand Down
27 changes: 9 additions & 18 deletions utils/key_func.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ void enter()
else {
wscrl(text_win, 1);
++ofy;
wmove(text_win, maxy - 1, 0);
print_line(*it);
mvprint_line(maxy - 1, 0, *it, 0, 0);
wmove(text_win, maxy - 1, x);
}
ofx = 0;
Expand All @@ -149,25 +148,22 @@ void eol()
ofx += (long)wrap.back();
bytes += nbytes;
}
wmove(text_win, y, 0);
wclrtoeol(text_win);
clrln;
print_line(*it, bytes, it->len);
}
}

void sol()
{
wmove(text_win, y, 0);
if (!wrap.empty()) { // line has been wrapped
wclrtoeol(text_win);
clrln;
print_line(*it);
#ifdef HIGHLIGHT
apply(y);
#endif
wmove(text_win, y, 0);
}
wrap.clear();
ofx = 0;
wmove(text_win, y, ofx = 0);
}

void scrolldown()
Expand All @@ -177,8 +173,7 @@ void scrolldown()
wscrl(ln_win, 1);
mvwprintw(ln_win, maxy - 1, 0, "%3u", ry + 2);
wrefresh(ln_win);
wmove(text_win, y, 0);
print_line(*it);
mvprint_line(y, 0, *it, 0, 0);
#ifdef HIGHLIGHT
apply(y);
#endif
Expand All @@ -193,9 +188,8 @@ void scrollup()
wscrl(ln_win, -1);
mvwprintw(ln_win, 0, 0, "%3u", ry);
--ofy;
wmove(text_win, 0, 0);
--it;
print_line(*it);
mvprint_line(0, 0, *it, 0, 0);
#ifdef HIGHLIGHT
apply(y);
#endif
Expand All @@ -209,8 +203,7 @@ void scrollup()
void left()
{
if (x == 0 && !wrap.empty()) { // line has been wrapped
wmove(text_win, y, 0);
wclrtoeol(text_win);
clrln;
ofx -= wrap.back();
wrap.pop_back();
print_line(*it, ofx < 0 ? 0 : ofx);
Expand Down Expand Up @@ -243,17 +236,15 @@ void left()
void right()
{
if (rx >= it->len - 1 && ry < curnum) { // go to next line
wmove(text_win, y, 0);
if (!wrap.empty()) // revert wrap
print_line(*it);
mvprint_line(y, 0, *it, 0, 0);
wmove(text_win, y + 1, 0);
++it;
wrap.clear();
ofx = 0;
} else if (x == maxx - 1) { // right to cut part of line
wrap_line:
wmove(text_win, y, 0);
wclrtoeol(text_win);
clrln;
ofx += x;
wrap.push_back(x);
print_line(*it, ofx);
Expand Down

0 comments on commit 68bc256

Please sign in to comment.