Esempio n. 1
0
//系统的初始进入界面
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;
		}
	}
}
Esempio n. 2
0
//个人信息页面
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;
		}
	}
}
Esempio n. 3
0
File: tasknc.c Progetto: skn/tasknc
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;
	}
} /* }}} */
Esempio n. 4
0
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;
}
Esempio n. 5
0
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;
}
Esempio n. 6
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());
}
Esempio n. 7
0
void t_half_delay_end(TUI_BOOL cooked)
{
	nocbreak();

	if (!(cooked & TUI_COOKED))
		cbreak();
}
Esempio n. 8
0
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);
}
Esempio n. 9
0
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);
}
Esempio n. 10
0
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);
}
Esempio n. 11
0
/* 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);                                 */
}
Esempio n. 12
0
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;
}
Esempio n. 14
0
void NCursesIOManager::destroy()
{
	keypad(this->_window, FALSE);
	(void)nocbreak();
	timeout(-1);
	(void)endwin();
}
Esempio n. 15
0
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;
}
Esempio n. 16
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;
}
Esempio n. 17
0
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);
}
Esempio n. 18
0
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 */
}
Esempio n. 19
0
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;
}
Esempio n. 20
0
// kill all CURSES windows and related stuff ----------------------------------
//
void CON_KillCurses()
{
#ifdef USE_CURSES
	nocbreak();
	echo();
	endwin();
#endif // USE_CURSES
}
Esempio n. 21
0
File: CRT.c Progetto: lyase/htop
int CRT_readKey() {
     nocbreak();
     cbreak();
     nodelay(stdscr, FALSE);
     int ret = getch();
     halfdelay(CRT_delay/2);
     return ret;
}
Esempio n. 22
0
//登录后主页
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;
		}
	}
}
Esempio n. 23
0
void unset_curses()
{
	keypad(stdscr, false);
  	nodelay(stdscr, false);
  	nocbreak();
  	echo();
  	endwin();
}
Esempio n. 24
0
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);
}
Esempio n. 25
0
File: help.c Progetto: lollek/imoria
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();
}
Esempio n. 27
0
Input::~Input()
{
    keypad(*screen, FALSE);
    echo();
    nocbreak();
    nl();

    delete screen;
}
Esempio n. 28
0
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;
}
Esempio n. 29
0
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;
}
Esempio n. 30
0
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;

}