//系统的初始进入界面 static void start_menu(){ int index=1; char commend[1]; erase(); cbreak(); noecho(); mvprintw(3 ,25, "%s", " 欢迎访问模拟铁路订票系统!"); mvprintw(8, 35, "%s", "1. 登录"); mvprintw(9, 35, "%s", "2. 注册"); mvprintw(10, 35, "%s", "3. 退出"); refresh(); while(index){ commend[0]=getch(); switch(commend[0]){ case '1': echo(); nocbreak(); login_menu(); index=0; break; case '2': echo(); nocbreak(); register_menu(); index=0; break; case '3': index=0; break; default: mvprintw(13, 35, "%s", "无效的命令!"); break; } } }
//个人信息页面 static void userinfo_menu(){ int index=1; char commend[1]; erase(); cbreak(); noecho(); mvprintw(3 ,25, "%s", " 欢迎访问模拟铁路订票系统!"); mvprintw(5 ,25, "%s", " 个人资料:"); mvprintw(7, 30, "a. 用户 id :%d", static_message.userinfo_data.uid); mvprintw(8, 30, "b. 用户名:%s", static_message.userinfo_data.u_name); mvprintw(9, 30, "c. 性别:%s", static_message.userinfo_data.sex); mvprintw(10, 30, "d. 电话号码:%d", static_message.userinfo_data.phone_num); mvprintw(11, 30, "e. 邮箱:%s", static_message.userinfo_data.email); mvprintw(13, 30, "%s", "1. 修改个人资料"); mvprintw(13, 50, "%s", "2. 返回上一页"); refresh(); while(index){ commend[0]=getch(); switch(commend[0]){ case '1': echo(); nocbreak(); modify_userinfo_menu(); index=0; break; case '2': echo(); nocbreak(); main_menu(); index=0; break; default: mvprintw(15, 30, "%s", "无效的命令!"); break; } } }
void set_curses_mode(const ncurses_mode mode) /* {{{ */ { /* set curses settings for various common modes */ switch (mode) { case NCURSES_MODE_STD: keypad(statusbar, TRUE);/* enable keyboard mapping */ nonl(); /* tell curses not to do NL->CR/NL on output */ cbreak(); /* take input chars one at a time, no wait for \n */ noecho(); /* dont echo input */ curs_set(0); /* set cursor invisible */ wtimeout(statusbar, cfg.nc_timeout);/* timeout getch */ break; case NCURSES_MODE_STD_BLOCKING: keypad(statusbar, TRUE);/* enable keyboard mapping */ nonl(); /* tell curses not to do NL->CR/NL on output */ cbreak(); /* take input chars one at a time, no wait for \n */ noecho(); /* dont echo input */ curs_set(0); /* set cursor invisible */ wtimeout(statusbar, -1);/* no timeout on getch */ break; case NCURSES_MODE_STRING: curs_set(1); /* set cursor visible */ nocbreak(); /* wait for \n */ echo(); /* echo input */ wtimeout(statusbar, -1);/* no timeout on getch */ break; default: break; } } /* }}} */
int main() { int ret = EXIT_SUCCESS; initscr(); start_color(); cbreak(); nonl(); noecho(); keypad(stdscr, TRUE); if (viewer_init_colors()) { ret = EXIT_FAILURE; goto uninit; } if (main_menu()) ret = EXIT_FAILURE; uninit: viewer_restore_colors(); keypad(stdscr, FALSE); echo(); nocbreak(); endwin(); return ret; }
int ncurses_prompt( WINDOW *w, int r, int c, char *prompt, char *def, char *rbuf, int doecho) { int l; nocbreak(); status(""); if (def) { mvwprintw(w, r, c, "%s [%s]: ", prompt, def); } else { mvwprintw(w, r, c, "%s", prompt); } wrefresh(w); if (doecho == 1) echo(); wgetstr(w, rbuf); if (doecho == 1) noecho(); l = strlen(rbuf); if (rbuf[l - 1] == '\n') rbuf[--l] = 0; if (def && l == 0) { strcpy(rbuf, def); } status(""); cbreak(); return 0; }
/*** Put the terminal into cbreak mode. @function cbreak @bool[opt] on @treturn bool `true`, if successful @see cbreak(3x) @see nocbreak(3x) */ static int Pcbreak(lua_State *L) { if (lua_isnoneornil(L, 1) || lua_toboolean(L, 1)) return pushokresult(cbreak()); return pushokresult(nocbreak()); }
void t_half_delay_end(TUI_BOOL cooked) { nocbreak(); if (!(cooked & TUI_COOKED)) cbreak(); }
CurseGui::CurseGui(int x, int y) { if ((win = initscr()) == NULL || nocbreak() == ERR || noecho() == ERR || keypad(stdscr, TRUE) == ERR || (win = newwin(x, y, 0, 0)) == NULL) throw GUIExeption(std::string("Error during init the curses library")); start_color(); curs_set(0); if (init_pair(HEAD, COLOR_RED, COLOR_CYAN) == ERR || init_pair(WALL, COLOR_BLUE, COLOR_YELLOW) == ERR || init_pair(FOOD, COLOR_MAGENTA, COLOR_GREEN) == ERR || init_pair(BACKGROUND, COLOR_BLACK, COLOR_BLACK) == ERR || init_pair(SNAKE, COLOR_GREEN, COLOR_RED) == ERR) throw GUIExeption(std::string("Error during init the curses library")); _x = x; _y = y; wrefresh(win); int line = -1; while (++line < _y) { int col = -1; while (++col < _x) { if (line == 0 || line == _y - 1) { wmove(win, col, line); waddch(win, '|' | COLOR_PAIR(WALL)); } else if (col == 0 || col == _x - 1) { wmove(win, col, line); waddch(win, '-' | COLOR_PAIR(WALL)); } } } wrefresh(win); }
static void tmon_cleanup(void) { syslog(LOG_INFO, "TMON exit cleanup\n"); fflush(stdout); refresh(); if (tmon_log) fclose(tmon_log); if (event_tid) { pthread_mutex_lock(&input_lock); pthread_cancel(event_tid); pthread_mutex_unlock(&input_lock); pthread_mutex_destroy(&input_lock); } closelog(); /* relax control knobs, undo throttling */ set_ctrl_state(0); keypad(stdscr, FALSE); echo(); nocbreak(); close_windows(); endwin(); free_thermal_data(); exit(1); }
int32_t get_num (NOTUSED AppData * a) { WINDOW *menu_win, *menu_sub; int maxx; const int BUFSZ = 32; char buf[BUFSZ]; maxx = getmaxx (stdscr); menu_win = newwin (5, maxx - 1, 0, 1); menu_sub = derwin (menu_win, 1, maxx - 1 - 2, 3, 1); mvwprintw (menu_win, 1, 2, "%s", "Enter a number, please"); box (menu_win, 0, 0); wrefresh (menu_win); nl (); nodelay (menu_sub, FALSE); echo (); nocbreak (); keypad (menu_sub, FALSE); mvwgetnstr (menu_sub, 0, 0, buf, BUFSZ); buf[BUFSZ - 1] = '\0'; nonl (); noecho (); raw (); keypad (menu_sub, TRUE); return atoi (buf); }
/* restore tty modes to their original state. */ void reset_modes(void) { /* No need. */ if (screen_status == 0 ) return; screen_status = 0; /* Move to bottom of screen. */ move(LINES - 1, 0); refresh(); /* TODO: prolly need to check initial values, and save them. */ /* intrflush(stdscr, FALSE); */ keypad(stdscr, TRUE); /* Restore modes. */ nocbreak(); echo(); /* noraw() ; */ /* Turn curses "off". */ endwin(); /* TODO: investigate if have to to this after reset modes.*/ /* signal(SIGQUIT, SIG_DFL); */ /* signal(SIGINT, SIG_DFL); */ }
Window::~Window() { echo(); nocbreak(); endwin(); keypad(stdscr, FALSE); }
/* get confirmation before doing something */ int get_confirm() { int confirmed = 0; char first_char; mvprintw(Q_LINE, 5, "Are you sure? (y/n)"); clrtoeol(); refresh(); cbreak(); first_char = getch(); if (first_char == 'y' || first_char == 'Y') { confirmed = 1; } nocbreak(); // if not confirmed, give the user a short "Cancelled" feedback notice if (!confirmed) { mvprintw(Q_LINE, 1, " Cancelled"); clrtoeol(); refresh(); sleep(1); } return confirmed; }
void NCursesIOManager::destroy() { keypad(this->_window, FALSE); (void)nocbreak(); timeout(-1); (void)endwin(); }
int main() { int q; srand(time(0)); init_ncurses(); new SnakeHead(Snake_map); erase(); Snake_map.display(); q = getch(); int Game_over = 1; while (Game_over) { q = -1; erase(); Snake_map.display(); printw("%d\n", Snake_map.cnt_food()); halfdelay(1); q = getch(); Game_over = next_move(q); usleep(40000); } erase(); printw("YOU LOOSE!\nYour score: %d\n\n\nPlease ENTER!\n", Snake_map.cnt_food()); nocbreak(); getch(); endwin(); return 0; }
int get_confirm() { int confirmed = 0; char first_char; mvprintw(Q_LINE, 5, "Are you sure? "); clrtoeol(); refresh(); cbreak(); first_char = getch(); if (first_char == 'Y' || first_char == 'y') { confirmed = 1; } nocbreak(); if (!confirmed) { mvprintw(Q_LINE, 1, " Cancelled"); clrtoeol(); refresh(); sleep(1); } return confirmed; }
void emu_popup(struct em8051 *aCPU, char *aTitle, char *aMessage) { WINDOW * exc; nocbreak(); cbreak(); nodelay(stdscr, FALSE); halfdelay(1); while (getch() > 0) {} runmode = 0; setSpeed(speed, runmode); exc = subwin(stdscr, 5, 40, (LINES-5)/2, (COLS-40)/2); wattron(exc,A_REVERSE); werase(exc); box(exc,ACS_VLINE,ACS_HLINE); mvwaddstr(exc, 0, 2, aTitle); wattroff(exc,A_REVERSE); wmove(exc, 2, 2); waddstr(exc, aMessage); wmove(exc, 4, 4); wattron(exc,A_REVERSE); waddstr(exc, "Press any key to continue"); wattroff(exc,A_REVERSE); wrefresh(exc); getch(); delwin(exc); refreshview(aCPU); }
void cleanup(bool doexit) { if (Windows) { move(LINES - 2, 0); refresh(); nocbreak(); endwin(); } if (Playersfp) { fclose(Playersfp); Playersfp = NULL; } if (Monstfp) { fclose(Monstfp); Monstfp = NULL; } if (Messagefp) { fclose(Messagefp); Messagefp = NULL; } if (Energyvoidfp) { fclose(Energyvoidfp); Energyvoidfp = NULL; } if (doexit) exit(0); /* NOTREACHED */ }
int main() { CELL file_cpy = {0}; WINDOW *mainwin; mainwin = initscr(); start_color(); setup_colors(); cbreak(); noecho(); keypad(mainwin, TRUE); meta(mainwin, TRUE); raw(); leaveok(mainwin, TRUE); wbkgd(mainwin, COLOR_PAIR(COLOR_MAIN)); wattron(mainwin, COLOR_PAIR(COLOR_MAIN)); werase(mainwin); refresh(); file_cpy.window = mainwin; main_dir(&file_cpy); wbkgd(mainwin, A_NORMAL); werase(mainwin); echo(); nocbreak(); noraw(); refresh(); endwin(); return TRUE; }
// kill all CURSES windows and related stuff ---------------------------------- // void CON_KillCurses() { #ifdef USE_CURSES nocbreak(); echo(); endwin(); #endif // USE_CURSES }
int CRT_readKey() { nocbreak(); cbreak(); nodelay(stdscr, FALSE); int ret = getch(); halfdelay(CRT_delay/2); return ret; }
//登录后主页 static void main_menu(){ int index=1; char commend[1]; erase(); cbreak(); noecho(); mvprintw(3 ,25, "%s", " 欢迎访问模拟铁路订票系统!"); mvprintw(5 ,25, "%s", " 主菜单:"); mvprintw(7, 30, "%s", "1. 个人资料"); mvprintw(8, 30, "%s", "2. 车次信息"); mvprintw(9, 30, "%s", "3. 我的订单"); mvprintw(10, 30, "%s", "4. 注销登录"); mvprintw(11, 30, "%s", "5. 退出系统"); refresh(); while(index){ commend[0]=getch(); switch(commend[0]){ case '1': echo(); nocbreak(); userinfo_menu(); index=0; break; case '2': echo(); nocbreak(); select_traininfo_menu(); index=0; break; case '3': echo(); nocbreak(); order_menu(); index=0; break; case '4': echo(); nocbreak(); start_menu(); index=0; break; case '5': index=0; break; default: mvprintw(13, 30, "%s", "无效的命令!"); break; } } }
void unset_curses() { keypad(stdscr, false); nodelay(stdscr, false); nocbreak(); echo(); endwin(); }
restartterm(NCURSES_CONST char *termp, int filenum, int *errret) { int result; T((T_CALLED("restartterm(%s,%d,%p)"), termp, filenum, errret)); if (setupterm(termp, filenum, errret) != OK) { result = ERR; } else if (SP != 0) { int saveecho = SP->_echo; int savecbreak = SP->_cbreak; int saveraw = SP->_raw; int savenl = SP->_nl; if (saveecho) echo(); else noecho(); if (savecbreak) { cbreak(); noraw(); } else if (saveraw) { nocbreak(); raw(); } else { nocbreak(); noraw(); } if (savenl) nl(); else nonl(); reset_prog_mode(); #if USE_SIZECHANGE _nc_update_screensize(SP); #endif result = OK; } else { result = ERR; } returnCode(result); }
void moria_help(vtype help_level) { ntype help_string; pid_t help_pid; int status; game_state = GS_HELP; sprintf(help_string, "Imoria %s", help_level); if ((help_pid = fork()) == 0) { /* child process */ echo(); nocbreak(); clear_screen(); put_qio(); endwin(); execlp(HELP_FILE_PATH, "mhelp.pl", help_string, 0); printf("\n\rUnable to execute: %s\n\r", HELP_FILE_PATH); printf("Press return continue.\n\r"); fflush(stdout); getc(stdin); exit(1); } else if (help_pid == -1) { /* parent process on failure */ msg_print("Fork failed."); } else { /* parent process on success */ #if DO_DEBUG fprintf(debug_file,": child: %d watiting...\n",help_pid); fflush(debug_file); #endif waitpid(help_pid, &status, 0); /* mhelp.pl catches ^Z and exits */ #if DO_DEBUG fprintf(debug_file,": child: %d status 1: %d\n", help_pid, status); fflush(debug_file); #endif waitpid(help_pid, &status, 0); /* mhelp.pl catches ^Z and exits */ #if DO_DEBUG fprintf(debug_file,": child: %d status 2: %d\n", help_pid, status); fflush(debug_file); #endif cbreak(); noecho(); clear_screen(); draw_cave(); } //printf("\nDisplay help for %s\n\r", help_level); };
void GameStateFirstTime::draw() { // BIG HACK // // Instead of drawing, we actually query the user for // a profile name // // NEED to remove this // Are you kidding me? // Direct ncurses calls? clear(); mvaddstr(0, 0, "Hello, there!\n" "It seems this is your first time running yetris.\n" "\n" "Please enter a profile name.\n" "It'll store all your settings, scores and game statistics."); attron(A_REVERSE); mvaddstr(7, 0, "Profile Name:"); attroff(A_REVERSE); mvaddstr(8, 0, "default:"); mvaddstr(8, 9, Utils::File::getUser().c_str()); mvaddstr(10, 0, "It may not contain the following characters:\n" "\\ / . ^ ; # = ~"); refresh(); // Making everything "right" nocbreak(); curs_set(1); echo(); nodelay(stdscr, FALSE); char name[256]; std::memset(name, '\0', 256); mvgetnstr(7, 15, name, 255); if (Profile::isNameValid(name)) { if (strlen(name) == 0) this->name = Utils::File::getUser(); else this->name = name; } // Returning to ncurses' "wrong" mode nodelay(stdscr, TRUE); noecho(); curs_set(0); cbreak(); }
Input::~Input() { keypad(*screen, FALSE); echo(); nocbreak(); nl(); delete screen; }
menu_item_t *menu_wait(menu_t *menu, int timeout) { int c; menu_item_t *ret = NULL; assert(menu && menu == _libmenu_menus_l); if(!_libmenu_window) { _libmenu_window = newwin(menu->win_h, menu->win_w, menu->win_y, menu->win_x); keypad(_libmenu_window, TRUE); menu->item = _libmenu_selectable_item_after(menu, -1); _libmenu_invalid = 1; } if(_libmenu_invalid) { _libmenu_drawmenu(); _libmenu_invalid = 0; } if(timeout >= 0) halfdelay(timeout/100); else cbreak(); c = wgetch(_libmenu_window); switch(c) { case KEY_UP: menu->item = _libmenu_selectable_item_before(menu, menu->item); if(menu->item != -1 && menu->item < menu->scroll_pos) menu->scroll_pos = menu->item; _libmenu_drawmenu(); break; case KEY_DOWN: menu->item = _libmenu_selectable_item_after(menu, menu->item); /* Scrolling */ if(menu->item >= menu->scroll_pos + menu->win_h-2) menu->item = menu->scroll_pos + menu->win_h - 3; _libmenu_drawmenu(); break; case 10: { menu_item_t *i = _libmenu_item_n(menu->items_f, menu->item); if(i->type != MENU_ITEM_LABEL) return i; } break; case 'q': case 'Q': ret = MENU_QUIT; break; } nocbreak(); return ret; }
int getchoice(char* greet, char* choices[]) { static int selected_row = 0; int max_row = 0; int start_screenrow = MESSAGE_LINE, start_screencol = 10; char** option = NULL; int selected = 0; int key = 0; option = choices; while (*option) { max_row++; option++; } if (selected_row >= max_row) selected_row = 0; clear(); mvprintw(2, 20, "%s", "CD Database Application"); refresh(); mvprintw(start_screenrow-2, start_screencol, greet); keypad(stdscr, TRUE); cbreak(); noecho(); key=0; while (key != 'q' && key != KEY_ENTER && key != '\n') { if (key == KEY_UP) { if (selected_row == 0) selected_row = max_row - 1; else selected_row--; } if (key == KEY_DOWN) { if (selected_row == (max_row - 1)) selected_row = 0; else selected_row++; } selected = *choices[selected_row]; draw_menu(choices, selected_row, start_screenrow, start_screencol); key = getch(); } keypad(stdscr, FALSE); nocbreak(); echo(); if (key == 'q') selected = 'q'; return selected; }
int dialog_run(const char *fmt, ...) { char textva[2048]; va_list ap; int height, width; WINDOW *win; char *word; int col = 2; int line = 2; // Get the message from the format string va_start(ap, fmt); vsprintf(textva, fmt, ap); va_end(ap); // Determine dialog dimensions height = 6 + (strlen(textva) / 50); width = strlen(textva); // Check we don't have a too big or small window if (width > DIALOG_MAX_WIDTH) width = DIALOG_MAX_WIDTH; if (width < DIALOG_MIN_WIDTH) width = DIALOG_MIN_WIDTH; // Create the window win = newwin(height, width, (LINES - height) / 2, (COLS - width) / 2); box(win, 0, 0); // Write the message into the screen for (word = strtok(textva, " "); word; word = strtok(NULL, " ")) { if (col + strlen(word) > width - 2) { line++; col = 2; } mvwprintw(win, line, col, "%s", word); col += strlen(word) + 1; } // Write Accept button wattron(win, A_REVERSE); mvwprintw(win, height - 2, width/2 - 5, "[ Accept ]"); curs_set(0); // Disable input timeout nocbreak(); cbreak(); // Wait for input wgetch(win); delwin(win); return 1; }