diff options
author | Johnny Richard <johnny@johnnyrichard.com> | 2022-04-26 03:21:56 +0200 |
---|---|---|
committer | Johnny Richard <johnny@johnnyrichard.com> | 2022-04-26 03:21:56 +0200 |
commit | 2ff134c08e2c1ca342719314776d3c63c4226c8b (patch) | |
tree | ee337fd96df8ad6e22263b7711d267240c37d47b | |
parent | c229b010d643f87b4504bf6635449568aec23b95 (diff) |
Implement page up and page down
-rw-r--r-- | ted.c | 35 |
1 files changed, 29 insertions, 6 deletions
@@ -35,7 +35,9 @@ enum editor_key { ARROW_LEFT = 1000, ARROW_RIGHT, ARROW_UP, - ARROW_DOWN + ARROW_DOWN, + PAGE_UP, + PAGE_DOWN }; typedef struct editor_config { @@ -109,11 +111,23 @@ editor_read_key() } if (seq[0] == '[') { - switch (seq[1]) { - case 'A': return ARROW_UP; - case 'B': return ARROW_DOWN; - case 'C': return ARROW_RIGHT; - case 'D': return ARROW_LEFT; + if (seq[1] >= '0' && seq[1] <= '9') { + if (read(STDIN_FILENO, &seq[2], 1) != 1) { + return '\x1b'; + } + if (seq[2] == '~') { + switch (seq[1]) { + case '5': return PAGE_UP; + case '6': return PAGE_DOWN; + } + } + } else { + switch (seq[1]) { + case 'A': return ARROW_UP; + case 'B': return ARROW_DOWN; + case 'C': return ARROW_RIGHT; + case 'D': return ARROW_LEFT; + } } } return '\x1b'; @@ -207,6 +221,15 @@ editor_process_key(editor_config_t *ec) editor_clear_screen(); exit(EXIT_SUCCESS); break; + case PAGE_UP: + case PAGE_DOWN: + { + int times = ec->screen_rows; + while (times--) { + editor_move_cursor(ec, c == PAGE_UP ? ARROW_UP : ARROW_DOWN); + } + } + break; case ARROW_UP: case ARROW_DOWN: case ARROW_LEFT: |