diff options
author | Juan Manuel Tomás <jtomas1815@gmail.com> | 2020-04-27 10:46:11 -0300 |
---|---|---|
committer | Juan Manuel Tomás <jtomas1815@gmail.com> | 2020-04-27 10:46:11 -0300 |
commit | 66cd8d27049a8da828a0666001ff4a83fc7ca891 (patch) | |
tree | f8047492a984ea568d53ef4e1c28efb4120a62ca | |
parent | a8b879b9e91d29eb8d3172a445b7501ffd3a83c2 (diff) | |
download | jet-66cd8d27049a8da828a0666001ff4a83fc7ca891.tar.gz jet-66cd8d27049a8da828a0666001ff4a83fc7ca891.zip |
Update number_of_lines on every keystroke
-rw-r--r-- | jet.c | 13 |
1 files changed, 4 insertions, 9 deletions
@@ -33,22 +33,17 @@ int main(int argc, char *argv[]) { int window_height = getmaxy(stdscr); int current_line = 0; - int number_of_lines = 0; - for (struct point i = {page, 0}; !at_eof(&i); move_point_forward(&i)) { - if (element(&i) == '\n') number_of_lines++; - } - while (1) { clear(); + int number_of_lines = 0; int x = -1, y = -1; - int iter_line = 0; - for (struct point i = {page, 0}; !at_eof(&i) && iter_line < window_height + current_line; move_point_forward(&i)) { + for (struct point i = {page, 0}; !at_eof(&i); move_point_forward(&i)) { + if (element(&i) == '\n') number_of_lines++; if (same_location(&i, &cursor)) { getyx(stdscr, y, x); } - if (iter_line >= current_line) addch(element(&i)); - if (element(&i) == '\n') iter_line++; + if (number_of_lines >= current_line && number_of_lines < window_height + current_line) addch(element(&i)); } if (x > -1 && y > -1) { move(y, x); |