#include "emul_repl.h" #include "emul_inst_exec.h" #include "emul_io_std.h" #include <stdio.h> #include <string.h> #include <ncurses.h> #define READ_LINE_MAX 64 static WINDOW *win; void emul_repl_readline(char input[READ_LINE_MAX]) { char c; int i = 0; int y, x; printw(">>"); refresh(); noecho(); while( (c = getch()) != '\n' ) { if (c == KEY_BACKSPACE) { getyx(win, y, x); input[--i] = '\0'; move(y, x-1); } else { input[i++] = c; echochar(c); } } echo(); input[i++] = '\0'; printw("\r"); clrtoeol(); //printw("\n"); refresh(); } void emul_repl_printline(); void emul_repl_init() { emul_inst_exec_init(); // ウィンドウポインタ取得 win = emul_getWin(); keypad(stdscr, TRUE); } char *menu[] = { "Display help >>:help", " Exit >>:exit" }; void emul_repl_start() { char input[READ_LINE_MAX]; exitcode_t state; int y, x; char *title = "Wellcome!"; int i,j; emul_repl_init(); // title getmaxyx(win, y, x); move(y/2-2, (x-strlen(title))/2); printw("%s", title); for (i = 0; i < 2; i++) { move(y/2+i, (x-strlen(menu[i]))/2); printw("%s", menu[i]); } move(0, 0); printw(""); refresh(); getch(); wclear(win); refresh(); while (1) { emul_repl_readline(input); emul_inst_exec_loadline(input); state = emul_inst_exec_run(); if (state == Failed) { emul_out_std_debug("Abend exit\n"); } else if (state == Success) { emul_out_std_debug("Sucsess\n"); break; } } } void emul_repl_end() { emul_inst_exec_end(); }