Exemple #1
0
void command_mode() {
    while(1) {
        char c;
        console_title("Command mode");
        console_status(status_str);
        c = getchar();
        if (c == '\n')
            edit_mode();
        else if (c == 'q' || c == 'Q') {
            extern int fileModified;
            if (!fileModified)
                return;
            console_status("Save changes? (y/n/c)");
            while(1) {
                c = getchar();
                if (c == 'y' || c == 'Y') {
                    if (file_save()) {
                        console_status(failure);
                        getchar();
                        break;
                    }
                    return; /* done. */
                } else if (c == 'n' || c == 'N') {
                    return; /* just return; */
                } else if (c == 'c' || c == 'C') {
                    break;  /* cancel; */
                }
            }
        }
    }
}
int selectc()
{
	int c, r;
	int ret;
	char h, l;
	unsigned int k_ch;
	
	c = (curchar / 16);
	r = (curchar % 16);

	for(;;)
	{
		dis_cmd("   Select Character");
		
		sel_mode();

		curchar = r + (c*16);

		display(curchar);

		h = ((mvwinch(set_win,(r+1),((c*2)+1))) & A_CHARTEXT);
		l = ((mvwinch(set_win,(r+1),((c*2)+2))) & A_CHARTEXT);
		wattron(set_win,A_REVERSE);
		mvwprintw(set_win,(r+1),((c*2)+1),"%c%c",h,l);
		wattroff(set_win,A_REVERSE);		
		wmove(set_win,(r+1),((c*2)+1));
		wrefresh(set_win);
		
		k_ch = wgetch(set_win);
		
		switch(k_ch)
		{
			case K_LEFT:
			case KEY_LEFT:
				if(c > 0)
				{
					normal_set(r,c);
					c--;
				}
				break;

			case K_DOWN:
			case KEY_DOWN:
				if(r < 15)
				{
					normal_set(r,c);
					r++;
				}
				break;

			case K_UP:
			case KEY_UP:
				if(r > 0)
				{
					normal_set(r,c);
					r--;
				}
				break;

			case K_RIGHT:
			case KEY_RIGHT:
				if(c < 15)
				{
					normal_set(r,c);
					c++;
				}
				break;

			case 'e':
			case 'E':			
				edit_mode();
				dis_cmd("   Edit Character");
				display(curchar);
				ret = edit();
				if(ret == 1)
					save_ch();
				break;

			case 'g':
			case 'G':
				dis_cmd("   Exchange: select Destination, then press RETURN or any other Key to ABORT");
				sr = r;
				sc = c;
				scurchar = curchar;
				if((curchar = sel_dest()) == -1)
				{ /* failsafe */
					r = sr;
					c = sc;
					curchar = scurchar;
				}
				else
				{ /* valid return */
					normal_set(r,c);
					c = (curchar / 16);
					r = (curchar % 16);
					xchg_ch(scurchar,curchar);
				}
				break;

			case 'm':
			case 'M':
				dis_cmd("   Move: select Destination, then press RETURN or any other Key to ABORT");
				sr = r;
				sc = c;
				scurchar = curchar;
				if((curchar = sel_dest()) == -1)
				{ /* failsafe */
					r = sr;
					c = sc;
					curchar = scurchar;
				}
				else
				{ /* valid return */
					normal_set(r,c);
					c = (curchar / 16);
					r = (curchar % 16);
					move_ch(scurchar,curchar);
				}
				break;

			case 'q':
			case 'Q':
				normal_set(r,c);
				wrefresh(set_win);			
				return(1);
				break;
			
			case 'x':
			case 'X':
				normal_set(r,c);
				wrefresh(set_win);			
				return(0);
				break;

			case 0x0c:
				wrefresh(curscr);
				break;
			
			default:
				beep();
				break;
				
		}
	}
}