diff options
author | Juan Manuel Tomás <jtomas1815@gmail.com> | 2020-04-08 23:31:50 -0300 |
---|---|---|
committer | Juan Manuel Tomás <jtomas1815@gmail.com> | 2020-04-08 23:31:50 -0300 |
commit | 1caf059c2cdffd3162fe030f824ded2bd5b03997 (patch) | |
tree | d412a52795e501f6eb1da6eee5a30b46b92ac141 | |
parent | f93182ebb5ca8fe765d138675d469a57e1601792 (diff) | |
download | jet-1caf059c2cdffd3162fe030f824ded2bd5b03997.tar.gz jet-1caf059c2cdffd3162fe030f824ded2bd5b03997.zip |
Add scrolling support
-rw-r--r-- | jet.c | 24 |
1 files changed, 19 insertions, 5 deletions
@@ -32,14 +32,28 @@ int main(int argc, char *argv[]) { keypad(stdscr, TRUE); int window_height = getmaxy(stdscr); + int current_line = 0; + int number_of_lines = 0; + for (int i = 0; i < file_size; i++) { + if (buffer[i] == '\n') number_of_lines++; + } while (1) { - int current_line = 0; - for (int i = 0; i < file_size && current_line < window_height; i++) { - addch(buffer[i]); - if (buffer[i] == '\n') current_line++; + int iter_line = 0; + for (int i = 0; i < file_size && iter_line < window_height + current_line; i++) { + if (iter_line >= current_line) addch(buffer[i]); + if (buffer[i] == '\n') iter_line++; } - getch(); + + int input = getch(); clear(); + + switch (input) { + case KEY_UP: + if (current_line > 0) current_line--; + break; + case KEY_DOWN: + if (current_line < number_of_lines) current_line++; + } } endwin(); |