hexedit: implement page up/down

function                                             old     new   delta
hexedit_main                                         924     970     +46

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2017-09-13 23:02:51 +02:00
parent 8187e01438
commit 62643017c3

View File

@ -236,7 +236,7 @@ int hexedit_main(int argc UNUSED_PARAM, char **argv)
redraw(); redraw();
printf(ESC"[1;10H"); /* position on 1st hex byte in first line */ printf(ESC"[1;10H"); /* position on 1st hex byte in first line */
//TODO: //PgUp/PgDown; Home/End: start/end of line; '<'/'>': start/end of file //TODO: //Home/End: start/end of line; '<'/'>': start/end of file
//Backspace: undo //Backspace: undo
//Enter: goto specified position //Enter: goto specified position
//Ctrl-L: redraw //Ctrl-L: redraw
@ -249,12 +249,14 @@ int hexedit_main(int argc UNUSED_PARAM, char **argv)
for (;;) { for (;;) {
char read_key_buffer[KEYCODE_BUFFER_SIZE]; char read_key_buffer[KEYCODE_BUFFER_SIZE];
unsigned cnt;
int32_t key; int32_t key;
uint8_t byte; uint8_t byte;
fflush_all(); fflush_all();
key = read_key(STDIN_FILENO, read_key_buffer, -1); key = read_key(STDIN_FILENO, read_key_buffer, -1);
cnt = 1;
switch (key) { switch (key) {
case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
@ -307,7 +309,10 @@ int hexedit_main(int argc UNUSED_PARAM, char **argv)
putchar(' '); putchar(' ');
} }
break; break;
case KEYCODE_PAGEDOWN:
cnt = G.height;
case KEYCODE_DOWN: case KEYCODE_DOWN:
k_down:
G.current_byte += 16; G.current_byte += 16;
if (G.current_byte >= G.eof_byte) { if (G.current_byte >= G.eof_byte) {
move_mapping_further(); move_mapping_further();
@ -324,6 +329,8 @@ int hexedit_main(int argc UNUSED_PARAM, char **argv)
row--; row--;
redraw_cur_line(); redraw_cur_line();
} }
if (--cnt)
goto k_down;
break; break;
case KEYCODE_LEFT: case KEYCODE_LEFT:
@ -348,7 +355,10 @@ int hexedit_main(int argc UNUSED_PARAM, char **argv)
G.current_byte--; G.current_byte--;
printf(ESC"[2D"); printf(ESC"[2D");
break; break;
case KEYCODE_PAGEUP:
cnt = G.height;
case KEYCODE_UP: case KEYCODE_UP:
k_up:
if ((G.current_byte - G.addr) < 16) { if ((G.current_byte - G.addr) < 16) {
move_mapping_lower(); move_mapping_lower();
if ((G.current_byte - G.addr) < 16) if ((G.current_byte - G.addr) < 16)
@ -364,6 +374,8 @@ int hexedit_main(int argc UNUSED_PARAM, char **argv)
printf(ESC"M"); /* scroll up */ printf(ESC"M"); /* scroll up */
redraw_cur_line(); redraw_cur_line();
} }
if (--cnt)
goto k_up;
break; break;
} }
} }