Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Gurrium committed Dec 29, 2022
1 parent 9845d1b commit 14ad42d
Showing 1 changed file with 35 additions and 10 deletions.
45 changes: 35 additions & 10 deletions kilo.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@

#define CTRL_KEY(k) ((k)&0x1f)

enum editorKey { ARROW_LEFT = 1000, ARROW_RIGHT, ARROW_UP, ARROW_DOWN };
enum editorKey {
ARROW_LEFT = 1000,
ARROW_RIGHT,
ARROW_UP,
ARROW_DOWN,
PAGE_UP,
PAGE_DOWN
};

/*** data ***/

Expand Down Expand Up @@ -72,15 +79,27 @@ int editorReadKey() {
if (read(STDIN_FILENO, &seq[1], 1) != 1) return '\x1b';

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;
}
}
}

Expand Down Expand Up @@ -181,6 +200,12 @@ void editorProcessKeyPress() {

exit(0);
break;

case PAGE_UP:
case PAGE_DOWN: {
int times = E.screenrows;
while (times--) editorMoveCursor(c == PAGE_UP ? ARROW_UP : ARROW_DOWN);
} break;
case ARROW_UP:
case ARROW_DOWN:
case ARROW_LEFT:
Expand Down

0 comments on commit 14ad42d

Please sign in to comment.