#include <string.h> #include <ncurses.h>
// // 버튼 키입력을 이용한 사용자 대화형 프로그램 // int noWayOut(char* prompt);
int main(void) { initscr();
// sector #01 /* 펑션키의 사용을 위해 키패드 초기화 */ keypad(stdscr, TRUE);
// sector #02 /* set default init mode */ noecho(); cbreak();
printw("Press any key to exit! "); getch();
// sector #03 while( !noWayOut("Confirm?[Y/N]") ) { sleep(1); }
sleep(1); endwin(); return 0; }
int noWayOut(char* prompt) { int reply;
// sector #04 // save current terminal state savetty();
// set appropriate terminal mode noecho(); raw();
// sector #05 // clear message line move(LINES-1, 0); clrtoeol();
// sector #06 // print prompt mvaddstr(LINES-1, 0, prompt); move(LINES-1, strlen(prompt)+1); refresh();
// sector #07 // get response from user for(reply= -1; reply == -1;){ switch(getch()){ case 'y': case 'Y': reply = 1; break; case 'n': case 'N': reply= 0; break; case KEY_DOWN: // down arrow key case KEY_UP: // up arrow key // sector #08 default: beep(); break; } }
// sector #09 // display feedback string addstr(reply == 1? "[Yes]" : "[No]"); refresh();
// sector #10 // restore terminal state and return resetty();
return(reply); }
/* 06_getch.c */
|