diff --git a/emul_repl.c b/emul_repl.c index 16a30d1..55897ed 100644 --- a/emul_repl.c +++ b/emul_repl.c @@ -10,19 +10,41 @@ static WINDOW *win; + void emul_repl_readline(char input[READ_LINE_MAX]) { static int current_line = 0; int history = 0; int c; int i = 0; int y, x; + void emul_repl_show_history() { + int max_y, max_x; + input[0] = '\0'; + emul_inst_dec_get_line(input, current_line+history); + getyx(win, y, x); + // 1行削除 + move(y, 0); + clrtoeol(); + // ヒストリ番号表示 + getmaxyx(win, max_y, max_x); + move(y, max_x-8); + printw("L[%5d]", current_line+history); + // ヒストリ表示および格納 + move(y, 0); + printw(">>"); + i = 0; + while ( input[i] != '\n' && input[i] != '\0') { + echochar(input[i++]); + } + refresh(); + } current_line = emul_inst_dec_get_program_line_max(); printw(">>"); refresh(); noecho(); cbreak(); while( (c = getch()) != '\n' ) { - if (c == 127) { // Delete and back + if (c == 127 || c == KEY_BACKSPACE) { // Delete and back if ( i > 0 ) { getyx(win, y, x); input[--i] = '\0'; @@ -33,32 +55,12 @@ } else if (c == KEY_UP) { if (current_line+history > 0) { history--; - input[0] = '\0'; - emul_inst_dec_get_line(input, current_line+history); - getyx(win, y, x); - move(y, 0); - clrtoeol(); - printw("%d>", current_line+history); - i = 0; - while ( input[i] != '\n' && input[i] != '\0') { - echochar(input[i++]); - } - refresh(); + emul_repl_show_history(); } } else if (c == KEY_DOWN) { if (current_line+history < current_line) { history++; - input[0] = '\0'; - emul_inst_dec_get_line(input, current_line+history); - getyx(win, y, x); - move(y, 0); - clrtoeol(); - printw("%d>", current_line+history); - i = 0; - while ( input[i] != '\n' && input[i] != '\0') { - echochar(input[i++]); - } - refresh(); + emul_repl_show_history(); } } else if (c == KEY_RIGHT) { // Nothing do