summaryrefslogtreecommitdiff
path: root/jet.c
diff options
context:
space:
mode:
authorJuan Manuel Tomás <jtomas1815@gmail.com>2020-04-08 23:31:50 -0300
committerJuan Manuel Tomás <jtomas1815@gmail.com>2020-04-08 23:31:50 -0300
commit1caf059c2cdffd3162fe030f824ded2bd5b03997 (patch)
treed412a52795e501f6eb1da6eee5a30b46b92ac141 /jet.c
parentf93182ebb5ca8fe765d138675d469a57e1601792 (diff)
downloadjet-1caf059c2cdffd3162fe030f824ded2bd5b03997.tar.gz
jet-1caf059c2cdffd3162fe030f824ded2bd5b03997.zip
Add scrolling support
Diffstat (limited to 'jet.c')
-rw-r--r--jet.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/jet.c b/jet.c
index 9a42328..0d1181a 100644
--- a/jet.c
+++ b/jet.c
@@ -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();