summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ted.c35
1 files changed, 29 insertions, 6 deletions
diff --git a/ted.c b/ted.c
index a0d6492..4568719 100644
--- a/ted.c
+++ b/ted.c
@@ -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: