コード例 #1
0
ファイル: slk.c プロジェクト: Palantir555/ecos-mars-zx3
int slk_attr_set(const attr_t attrs, short color_pair, void *opts)
{
    PDC_LOG(("slk_attr_set() - called\n"));

    return slk_attrset(attrs | COLOR_PAIR(color_pair));
}
コード例 #2
0
ファイル: control.c プロジェクト: dakk/spaceinvaders-curses
/**
 * Funzione di rendering e gestione delle iterazioni tra gli oggetti della scena
 */
void control_task()
{
	int i;			
	
	/* System V: inizializzazione */
	// Queue id per i messaggi
	int    qid;			
	
	// Chiave del progetto per individuare la coda dei messaggi
    key_t  msgkey;
    
    // Genero la chiave ipc    
    msgkey = ftok(FTOK_PATH, FTOK_PROJ_ID);    
    
    // Apro (o creo) la coda
    if((qid = msgget(msgkey, 0666 | IPC_CREAT)) == -1)
    {
		perror("Impossibile creare la coda");
		exit(1);
    }
    
    /* Inoltre creo una queue per ogni alieno, per trasmettere le comunicazioni
     * relative alle collisioni */
    int	qid_coll[ALIEN_NUM];
    key_t msgkey_coll[ALIEN_NUM];
    
    // Struttura per memorizzare lo stato delle collisioni ed inviarlo coem messaggio all'alieno
	collision_msg_t coll_m;
	coll_m.mtype = 1;
	
	/* Genero le chiavi e creo le code */
	for(i = 0; i < ALIEN_NUM; i++)
	{
		msgkey_coll[i] = ftok(FTOK_PATH, FTOK_PROJ_ID_COLL_BASE + i);    
		
		// Apro (o creo) la coda
		if((qid_coll[i] = msgget(msgkey_coll[i], 0666 | IPC_CREAT)) == -1)
		{
			perror("Impossibile creare la coda");
			exit(1);
		}		
	}
	
    
    int last_alien_hit = -1;// Id dell'ultimo alieno colpito
	int obj_n = 1;			// Numero di oggetti nella scena
	int scores = 0;			// Punteggio
	char buffer[512];		// Buffer per stampare le stats
	unsigned long iterations = 0;	// Numero di iterazioni		
	int aliens = ALIEN_NUM;	
	
	// Buffer di ricezione
	object_data_t recv_data;
	
	// Informazioni degli oggetti; la navicella e' in posizione 0.
	// L'elemento corrente e' puntato dal puntatore current
	object_data_t objects[OBJECTS_MAX];
	
	// Oggetto corrente e suo id; spaceship = -1;
	object_data_t *current;
	int current_id;
	
	// Variabile che indica se il loop deve essere eseguito
	int playing = 1;
	
	// Variabile temporanea per lo stato delle collisioni dell'oggetto corrente
	int col;
	

	// Inizializzo le ncurses
	initscr();
	
	
	// Inizializzo i colori delle ncurses
	#ifdef COLORS
		start_color();
		init_pair(1, COLOR_WHITE, COLOR_BLACK);
		attron(COLOR_PAIR(1));
	#endif
	
		
	// Non visualizzo i tasti premuti
	noecho();
	
	// Inizializzo il generatore random
	srand((int)time(0));
	
	// Nascondo il cursore
	curs_set(0); 
	
	
	// Inizializzo la navicella
	objects[0].type = OT_SPACESHIP;
	
	// Inizializzo gli oggetti come non utilizzati
	for(i = 0; i < OBJECTS_MAX; i++)
		objects[i].x = -1;
		
		
	// Finche' il gioco non finisce, eseguo
	do 
	{ 					
		// Ricevo i dati di un oggetto dalla coda messaggi
		msgrcv(qid, &recv_data, sizeof(recv_data) - sizeof(recv_data.mtype), 1, 0);
				
		
		// Se non e' la navicella, ricerco nella lista l'oggetto ricevuto
		current = NULL;
		
		if(recv_data.type != OT_SPACESHIP)
		{
			for(i = 1; i < OBJECTS_MAX; i++)
			{
				if(recv_data.pid == objects[i].pid)
				{
					current = &objects[i];
					current_id = i;
					i = OBJECTS_MAX;
				}
			}
			
			// Non l'ho trovato, cerco uno spazio libero
			if(current == NULL)
			{
				for(i = 1; i < OBJECTS_MAX; i++)
					if(objects[i].x == -1)
					{
						obj_n++;
						current = &objects[i];
						i = OBJECTS_MAX;
					}
			}
		}
		// Altrimenti la navicella sta' in posizione 0
		else
		{
			current = &objects[0];
			current_id = 0;
		}
		
		
		// Collision detect
		int collision_count = 0;
			
		// Se l'oggetto corrente ha una posizione inizializzata, faccio
		// il check delle collisioni
		if(current->x != -1)
		{
			for(i = 0; i < OBJECTS_MAX; i++)
			{
				// Un oggetto non collide con se stesso
				if(current_id == i)
					continue;
					
				// Nella posizione i non c'e' nessun oggetto
				if(objects[i].x == -1)
					continue;
					
					
				// Se una bomba colpisce un alieno, me ne frego
				if(((objects[i].type == OT_BOMB) && (current->type == OT_ALIEN)) ||
					((objects[i].type == OT_ALIEN) && (current->type == OT_BOMB)))
					continue;
					
				// Se due missili si colpiscono, me ne frego
				if(((objects[i].type == OT_MISSILE) && (current->type == OT_MISSILE)))
					continue;
					
					
				// Controllo lo stato delle collisioni tra l'oggetto corrente
				// e quello in posizione i
				col = control_check_collision(&objects[i], current);
				
				
				// Se c'e' stata una collisione
				if(col != 0)
				{					
					// Imposto il flag			
					collision_count = 1;
					
					// Se abilitato, stampo una stringa di debug
					#ifdef DEBUG
						char cinfo[1024];
						sprintf(cinfo, "Collision: type %d and type %d, x %d and x %d, y %d and y %d",
								(int) objects[i].type, (int) current->type, objects[i].x, current->x,
								objects[i].y, current->y);
						mvaddstr(1, 1, cinfo);
					#endif
					
					// A seconda del tipo di oggetto corrente, faccio un azione diversa
					// per ogni tipo di collisione
					switch(current->type)
					{
						// Se un missile colpisce un alieno, toglie una vita
						// o lo ammazza, ed incrementa il punteggio
						case OT_MISSILE:
							if(objects[i].type == OT_ALIEN)
							{
								if((last_alien_hit == objects[i].pid) && (iterations >= MIN_HIT_DIFF))
								{
									coll_m.coll = 'z';
									last_alien_hit = -1;
								}
								else
								{
									coll_m.coll = 'c';
									last_alien_hit = objects[i].pid;	
								}
								
								iterations = 0;
								
								msgsnd(qid_coll[objects[i].id], &coll_m, sizeof(coll_m) - sizeof(coll_m.mtype), 0);
								scores += objects[i].size * 10;
							}
							// Se una bomba ed un missile collidono, killo la bomba
							else if(objects[i].type == OT_BOMB)
								kill(current->pid, SIGQUIT);							
							
							// E killo il missile in ogni caso
							kill(current->pid, SIGQUIT);
							break;
							
						// Collisione alieno
						case OT_ALIEN:
							// Se due alieni collidono rimbalzano
							if(objects[i].type == OT_ALIEN)
							{
								coll_m.coll = 'r';
									
								// Se collidono e stanno andando entrambi
								// nella stessa dir, cambio direzione solo ad uno
								if(objects[i].dir == current->dir)
								{
									if(current->x < objects[i].x)
										msgsnd(qid_coll[current->id], &coll_m, sizeof(coll_m) - sizeof(coll_m.mtype), 0);
									else
										msgsnd(qid_coll[objects[i].id], &coll_m, sizeof(coll_m) - sizeof(coll_m.mtype), 0);
								}
								else
								{
									msgsnd(qid_coll[objects[i].id], &coll_m, sizeof(coll_m) - sizeof(coll_m.mtype), 0);
									msgsnd(qid_coll[current->id], &coll_m, sizeof(coll_m) - sizeof(coll_m.mtype), 0);
								}						
							}
							// Se collide con un missile, invio il messaggio
							// all'alieno e killo il missile
							else if(objects[i].type == OT_MISSILE)
							{
								if(last_alien_hit == current->pid && iterations >= MIN_HIT_DIFF)
								{
									coll_m.coll = 'z';
									last_alien_hit = -1;
								}
								else
								{
									coll_m.coll = 'c';
									last_alien_hit = current->pid;
								}
								
								iterations = 0;
									
								msgsnd(qid_coll[current->id], &coll_m, sizeof(coll_m) - sizeof(coll_m.mtype), 0);
								
								scores += current->size * 10;
								
								kill(objects[i].pid, SIGQUIT);
							}
							// Se un alieno collide con la navicella, fine gioco
							else if(objects[i].type == OT_SPACESHIP)
							{
								playing = 0;
								usleep(SLEEP_OVER);		
							}
							break;
													
								
						// Collisione bomba	
						case OT_BOMB:
							// Se la bomba collide con la navicella, game over
							if(objects[i].type == OT_SPACESHIP)
							{
								playing = 0;			
								usleep(SLEEP_OVER);				
							}
							// Se una bomba ed un missile collidono, le killo
							else if(objects[i].type == OT_MISSILE)
							{
								kill(objects[i].pid, SIGQUIT);
								kill(current->pid, SIGQUIT);							
							}
							
							break;
							
						// Collisione navicella	
						case OT_SPACESHIP:
							// Se la navicella collide con un missile o con una bomba, fine gioco
							if((objects[i].type == OT_BOMB) || (objects[i].type == OT_ALIEN))
							{
								playing = 0;		
								usleep(SLEEP_OVER);							
							}
							break;
							
					}
					
					
					// Aggiorno lo schermo
					refresh();
				}
			}
		}
		
	
		// Qualsiasi oggetto sia, cancello prima di tutto la sua vecchia
		// porzione di schermo, ed inserisco nell'array degli oggetti i
		// dati appena ricevuti
		if(current->x != -1)
			clear_quad(current->x, current->y, current->size);
		
		*current = recv_data;
		
		
		// A seconda del tipo di oggetto, eseguo un operazione differente			
		switch(recv_data.type)
		{
			// Astronave aliena
			case OT_ALIEN:				
				// Se la vita di un alieno e' negativa, vuol dire che deve morire;
				// deve comunque inviare la struttura inizializzando come tipo
				// OT_DELETE
				if(current->life == -1)
				{					
					aliens--;
					 
					continue;
				}
					
				// A seconda del livello, disegno l'alieno in modo diverso
				switch(current->size)
				{
					case ALIEN_DATA1_SIZE:
						render_string_array(current->x, current->y, ALIEN_DATA1, ALIEN_DATA1_SIZE);	
						break;
						
					case ALIEN_DATA2_SIZE:
						render_string_array(current->x, current->y, ALIEN_DATA2, ALIEN_DATA2_SIZE);	
						break;
						
					case ALIEN_DATA3_SIZE:
						render_string_array(current->x, current->y, ALIEN_DATA3, ALIEN_DATA3_SIZE);	
						break;
				}
				
				// Il nemico e' sceso troppo in basso, game over
				if(current->y > (SCREEN_HEIGHT - ALIEN_DATA2_SIZE))
				{
					playing = 0;
					usleep(SLEEP_OVER);		
				}
					
				break;
			
			
			// Navicella	
			case OT_SPACESHIP:
				render_string_array(current->x, current->y, SPACE_SHIP_DATA, SPACE_SHIP_SIZE);	

				break;
				
			
			// Bomba aliena	
			case OT_BOMB:			
				mvaddch(current->y, current->x, BOMB_DATA);
				break;
			
			
			// Missile dell'astronave	
			case OT_MISSILE:				
				mvaddch(current->y, current->x, MISSILE_DATA);

				break;	
			
			
			// Un oggetto sta' morendo e vuole esser cancellato dall'array	
			case OT_DELETE:		
				// Invalido la sua entry nell'array
				current->x = -1;
				
				// Decremento il numero di oggetti della scena
				obj_n--;
				
				// Attendo che muoia (per non aver zombie)
				waitpid(current->pid);
				break;
		};
		
				
		
		// Cancello la riga del punteggio
		mvaddstr(0, 0, "\t\t\t\t\t\t\t\t\t\t");
				
		// Visualizzo il punteggio attuale
		sprintf(buffer, "Scores: %d", scores);		
		mvaddstr(0, 1, buffer);
		
		
		// Visualizzo il numero di oggetti della scena
		sprintf(buffer, "Active Processes: %d", obj_n);		
		mvaddstr(0, 20, buffer);
			
		// Visualizzo il numero di oggetti della scena
		//sprintf(buffer, "Last hit: %d", last_alien_hit);		
		//mvaddstr(0, 50, buffer);
			
		// Visualizzo il numero di alieni
		sprintf(buffer, "Aliens: %d", aliens);		
		mvaddstr(0, 50, buffer);
	
		
			
		// Rendo invisibile il cursore e faccio il refresh
		curs_set(0);
		refresh();
		
		// Aggiorno il numero di iterazioni
		iterations++;
	} while(playing && aliens > 0);
	
	// Fermo le ncurses
	#ifdef COLORS
		attroff(COLOR_PAIR(1));
	#endif
	endwin();
	
	// Se ci son processi rimasti, invio un segnale di kill per terminarli
	for (i = 0; i < OBJECTS_MAX; i++)
	{
		if(objects[i].x != -1)
		{
			// Se e' un alieno, utilizzo la coda dei messaggi per le collisioni
			// per dire di uccidersi
			if(objects[i].type == OT_ALIEN)
			{
				coll_m.coll = 'd';
				
				msgsnd(qid_coll[objects[i].id], &coll_m, sizeof(coll_m) - sizeof(coll_m.mtype), 0);		
			}
			else
			{
				kill(objects[i].pid, SIGQUIT);
			}
			
			// Attendo che il processo esca
			waitpid(objects[i].pid);
			obj_n--;
			objects[i].x = -1;
		}
	}
	
	
	// Elimino tutte le code dei messaggi create in precedenza
	msgctl(qid, IPC_RMID, NULL);
	
	for(i = 0; i < ALIEN_NUM; i++)
		msgctl(qid_coll[i], IPC_RMID, NULL);
	
	// Aggiungo il punteggio alla lista degli highscore e visualizzo
	// un messaggio di fine gioco
	system("clear");
	
	int pos = scores_add(scores);
	
	if(aliens == 0)
		printf("Hai vinto!\n");
	else
		printf("Hai perso!\n");
		
	if(pos == 0)
		printf("Nuovo punteggio high score! %d\n", scores);
	else
		printf("Il tuo punteggio e' %d\n", scores);
	
	// Visualizzo la lista dei punteggi alti
	int scorl[SCORES_N_MAX];
	scores_load(scorl);	
	for(i = 0; i < SCORES_N_MAX; i++)
		printf("\t%d\t%d\n", i+1, scorl[i]);
	
}
コード例 #3
0
ファイル: main.c プロジェクト: svilerino/Desarrollo-Tecnica3
int main(){
system("clear");
srand(time(NULL));
int filas=0,columnas=0,opcion=0,a=0;
int **mat;
initscr();
colores();
wbkgd(stdscr,COLOR_PAIR(3));refresh();
do{
	erase();refresh();
	printw("\nMenu\n\t1.-Generar Matriz\n\t2.-Mostrar Soluciones\n\t3.-Cargar Matriz\n\t4.-Guardar Matriz\n\t5.-Ver Matriz\n\t0.-Salir\n");refresh();
	scanw("%i",&opcion);
	switch(opcion){
		case 0:
			printw("\nAdios!\n");refresh();
			printw("\nPresione cualquier tecla.");refresh();
			getch();
			break;
		case 1:
			printw("\nIngrese Filas:");refresh();
			scanw("%i",&filas);
			printw("\nIngrese Columnas:");refresh();
			scanw("%i",&columnas);
			mat=CreaMatriz(filas,columnas);
			Cargar(mat,filas,columnas);
			Mostrar(mat,filas,columnas,0,0);
			printw("\nPresione cualquier tecla.");refresh();
			getch();
			break;
		case 2:
			a=0;
			while(a<columnas){
				if(mat[0][a]!=1){
					attron(COLOR_PAIR(5));
					printw("\n\n\nEntrando por(%i;%i)",0,a);refresh();
					attroff(COLOR_PAIR(5));
					printw("\n(%i;%i)",0,a);refresh();
					mat[0][a]=2;
					Laberinto(mat,filas,columnas,0,a);
					mat[0][a]=0;
				}
				a++;
			}
			printw("\nPresione cualquier tecla.");refresh();
			getch();
			break;
		case 3:
			mat=CargaMat(&filas,&columnas);
			getch();
			break;
		case 4:
			GuardaMat(mat,filas,columnas);
			getch();
			break;
		case 5:
			Mostrar(mat,filas,columnas,0,0);
			printw("\nPresione cualquier tecla.");refresh();
			getch();
			break;
		default:
			printw("\nOpcion Invalida");refresh();
			printw("\nPresione cualquier tecla.");refresh();
			getch();
	}
}while(opcion!=0);
endwin();
return(0);
}
コード例 #4
0
ファイル: firework.c プロジェクト: Noiwex/luajit-curses
void get_color(void)
{
    chtype bold = (rand() % 2) ? A_BOLD : A_NORMAL;
    attrset(COLOR_PAIR(rand() % 8) | bold);
}
コード例 #5
0
ファイル: ui-terminal-curses.c プロジェクト: erf/vis
static inline attr_t style_to_attr(CellStyle *style) {
	return style->attr | COLOR_PAIR(color_pair_get(style->fg, style->bg));
}
コード例 #6
0
ファイル: lcdk.c プロジェクト: AitorATuin/lcdk
int _color_pair (int color)
{
	return COLOR_PAIR(color);
}
コード例 #7
0
ファイル: curses.c プロジェクト: WuKongQC/opensips
int draw_sibling_menu(select_menu *menu)
{
	int i,c,maxopt,d;
	char buf[40];
	select_menu *it;
	int cur_index=0;
	int skip=0;
	int max_len=0,len;
again:
	wclear(menu_window);

	/* print title in colour */
	attron(COLOR_PAIR(1));
	mvprintw(HIGH_NOTICE_Y,max_x/2-20,menu->parent?menu->parent->name:"OpenSIPS Main Configuration Menu");
	/* print footer */
	print_notice(NOTICE_Y,NOTICE_X,0,"Press h for navigation help.");
	attroff(COLOR_PAIR(1));

	/* draw actual menu */
	i=0;
	for (it=menu;it;it=it->next_sibling) {
		wmove(menu_window, max_y/4+i++, max_x / 2 - 20);
		snprintf(buf, sizeof(buf), " %s", it->name);
		waddstr(menu_window, buf);
		len = strlen(it->name) +6;
		if (len > max_len)
			max_len = len;
	}

	/* draw selection marker */
	wmove(menu_window, max_y/4+cur_index, (max_x / 2) - 25);
	waddstr(menu_window, "--->");

	/* print box with color */
	wattron(menu_window,COLOR_PAIR(2));
	for (d=-1;d<i+1;d++) {
		wmove(menu_window,max_y/4+d,max_x/2-30);
		wprintw(menu_window,"|");
		wmove(menu_window,max_y/4+d,max_x/2-20+max_len);
		wprintw(menu_window,"|");
	}

	for (d=0;d<max_len+9;d++) {
		wmove(menu_window,max_y/4-2,max_x/2-29+d);
		wprintw(menu_window,"_");
		wmove(menu_window,max_y/4+i,max_x/2-29+d);
		wprintw(menu_window,"_");
	}

	wattroff(menu_window,COLOR_PAIR(2));
	wmove(menu_window, 0, 0);
	wrefresh(menu_window);

	maxopt = i-1;

	c = getch();
	switch (c) {
		case KEY_UP:
			if (cur_index > 0)
				cur_index--;
			break;
		case KEY_DOWN:
			if (cur_index < maxopt)
				cur_index++;
			break;
		case KEY_RIGHT:
		case KEY_ENTER:
		case '\n':
			for (i=0,it=menu;i<cur_index;i++,it=it->next_sibling)
				;
			c = exec_menu_action(it);
			break;
		case 'h':
		case 'H':
			clear();
			print_notice(max_y/2,20,0,"Use UP and DOWN arrow keys to navigate.");
			print_notice(max_y/2+1,20,0,"Use RIGHT arrow or ENTER key to enter a certain menu.");
			print_notice(max_y/2+2,20,0,"Use LEFT arror or Q key to go back.");
			print_notice(max_y/2+3,20,0,"Use SPACE to toggle an entry ON/OFF.\n");
			print_notice(max_y/2+4,20,1,"Press any key to return to menuconfig.");
			refresh();
			break;
		case KEY_LEFT:
		case 'q':
		case 'Q':
			for (it=menu;it;it=it->next_sibling) {
				if (it->child_changed == CHILD_CHANGED) {
					if (skip == 0) {
						/* have we asked before and got negative response ? */
						print_notice(NOTICE_Y,NOTICE_X,0,"You have not saved changes. Go back anyway ? [y/n] ");
						c = getch();
						if (c == 'n' || c == 'N')
							goto again;
						else {
							it->child_changed = CHILD_CHANGE_IGNORED;
							skip=1;
							return 0;
						}
					} else
						it->child_changed = CHILD_CHANGE_IGNORED;
				}
			}
			if (skip == 1)
				return 0;
			return 0;
	}

	goto again;
}
コード例 #8
0
ファイル: hn_dbLogin.c プロジェクト: HotQ/HNotes
Status db_login(MYSQL *conn_ptr){

	char	user[50]="",
			password[50]="",
			password_verify[100]="";
	// start_color();
	// init_color(COLOR_BLACK, 0, 0, 0);
	// init_pair(1, COLOR_GREEN, COLOR_BLACK);


	printw("mysql user:\t");
	scanw("%s",user);

	printw("mysql password:\t");
	noecho();  
        scanw("%s",password);   
    echo();
	printw("\n");

	refresh();
        
    conn_ptr=mysql_init(NULL);
    conn_ptr = mysql_real_connect(conn_ptr, "localhost", user, password, NULL, 0, NULL, 0);

    char input_ch;

    if(conn_ptr){
    	attron(A_BOLD);
    	   printw("[ info  @%s]  Connect successfully!\n",user);
    	attroff(A_BOLD);
    	refresh();
    }else{
    	attron(A_BOLD);
    	   printw("[ info  @%s]  F****d~\n",user);
    	attroff(A_BOLD);
    	refresh();
    	return Status_Forbidden;
    }


	if(mysql_query(conn_ptr, "use HNotes")){
		printw("[ query @%s]  Create database? [Y/n] :  ",user);refresh();
		scanw("%c",&input_ch);
		if(input_ch=='Y' || input_ch=='y' ){
            if(!mysql_query(conn_ptr, "create DATABASE HNotes;")){
            	//mysql_query(conn_ptr, "create table ;")
            	printw("[");    	
            	attron(COLOR_PAIR(1));
                attron(A_BOLD);
            	   printw("  OK");
            	attroff(COLOR_PAIR(1));
                attroff(A_BOLD);
            	printw("   @%s]  Create database already.\n",user);
            	mysql_query(conn_ptr, "use HNotes");
            	printw("[ info  @%s]  Enter database already.\n ",user);

            }

		}
		if(input_ch=='N' || input_ch=='n' ){
			    printw("[");
            	attron(COLOR_PAIR(2));
                attron(A_BOLD);
            	   printw("  NO");
            	attroff(COLOR_PAIR(2));
                attroff(A_BOLD);
            	printw("   @%s]  Refuse to create database.\n",user);
		}
		refresh();
	}else{
		attron(A_BOLD);
		printw("[ info  @%s]  Enter database already.\n ",user);
		attroff(A_BOLD);
	}

	refresh();
	//ShowQueryResult_Select(conn_ptr,"show databases;");
    mysql_query(conn_ptr,"use HNotes;"); 
    ShowQueryResult_Select(stdscr,conn_ptr,"select * from demo1;");



	return Status_OK;
    

}
コード例 #9
0
void printgen() {				/*Prints genre menu*/
	int y, x;
	clear();
	init_pair(1, COLOR_CYAN, COLOR_BLACK);
	bkgd(COLOR_PAIR(1));
	attron(A_BOLD);
	for(x = 44; x < 100; x++) {
		attron(COLOR_PAIR(1));
		printw("*");
		move(0, x);
		attroff(COLOR_PAIR(1));
	}
	for(y = 0; y < 11; y++) {
		attron(COLOR_PAIR(1));
		printw("*");
		move(y, 44);
		attroff(COLOR_PAIR(1));
	}
	for(x = 44; x < 100; x++) {
		attron(COLOR_PAIR(1));
		printw("*");
		move(11, x);
		attroff(COLOR_PAIR(1));
	}
	for(y = 0; y < 11; y++) {
		attron(COLOR_PAIR(1));
		printw("*");
		move(y, 100);
		attroff(COLOR_PAIR(1));
	}
	init_pair(2,COLOR_YELLOW,COLOR_BLACK);
        attron(COLOR_PAIR(2));
        border(0,0,0,0, 0,0,0,0);
        refresh();
        attroff(COLOR_PAIR(2));
        refresh();	
	mvaddstr(2,60," ----- SELECT GENRES -----");
	mvaddstr(4,48,"1. Fiction");
	mvaddstr(5,48,"2. Non-fiction");
	mvaddstr(6,48,"3. Reference");
	mvaddstr(7,48,"4. Self-help");
	mvaddstr(8,48,"5. Back to main menu");
	mvaddstr(9,48,"Enter your choice:");
   	refresh();
}
コード例 #10
0
ファイル: tictactoefunctions.c プロジェクト: supakan/Cargame
void drawBoard() {

  int i, h;
  initscr();
  start_color();
  init_pair(1,COLOR_RED,COLOR_GREEN);
  int a = rand()%2;
  if(a == 1){
  init_pair(2,COLOR_YELLOW,COLOR_BLACK);
}
  else if (a == 0){
  init_pair(2,COLOR_GREEN,COLOR_BLACK);
}
  init_pair(3,COLOR_WHITE,COLOR_BLACK);
  for(i=0;i<=17;i++) {
    attrset(COLOR_PAIR(1));
    mvaddch(i, 15, '|');
    mvaddch(i,31,'|');
  }
   attrset(COLOR_PAIR(2));
   mvaddstr(0,0,"    (;;);;)");
   mvaddstr(1,0,"  (;;);;;);;)");
   mvaddstr(2,0,"    (;;(;;;)");
  attrset(COLOR_PAIR(3));
  mvaddstr(3,0,"      |i!|");
  mvaddstr(4,0,"      |ii|");
  attrset(COLOR_PAIR(2));
  mvaddstr(6,0,"    (;;);;)");
  mvaddstr(7,0,"  (;;);;;);;)");
  mvaddstr(8,0,"    (;;(;;;)");
  attrset(COLOR_PAIR(3));
  mvaddstr(9,0,"      |i!|");
  mvaddstr(10,0,"      |ii|");
  attrset(COLOR_PAIR(2));
  mvaddstr(12,0,"    (;;);;)");
  mvaddstr(13,0,"  (;;);;;);;)");
  mvaddstr(14,0,"    (;;(;;;)");
  attrset(COLOR_PAIR(3));
  mvaddstr(15,0,"      |i!|");
  mvaddstr(16,0,"      |ii|");	


  attrset(COLOR_PAIR(2));
  mvaddstr(0,32,"    (;;);;)");
  mvaddstr(1,32,"  (;;);;;);;)");
  mvaddstr(2,32,"    (;;(;;;)");
  attrset(COLOR_PAIR(3));
  mvaddstr(3,32,"      |i!|");
  mvaddstr(4,32,"      |ii|");
  attrset(COLOR_PAIR(2));
  mvaddstr(6,32,"    (;;);;)");
  mvaddstr(7,32,"  (;;);;;);;)");
  mvaddstr(8,32,"    (;;(;;;)");
  attrset(COLOR_PAIR(3));
  mvaddstr(9,32,"      |i!|");
  mvaddstr(10,32,"      |ii|");
  attrset(COLOR_PAIR(2));
  mvaddstr(12,32,"    (;;);;)");
  mvaddstr(13,32,"  (;;);;;);;)");
  mvaddstr(14,32,"    (;;(;;;)");
  attrset(COLOR_PAIR(3));
  mvaddstr(15,32,"      |i!|");
  mvaddstr(16,32,"      |ii|");

  init_pair(40,COLOR_WHITE,COLOR_BLACK);
  init_pair(41,COLOR_YELLOW,COLOR_BLACK);
  init_pair(42,COLOR_RED,COLOR_BLACK);
  init_pair(43,COLOR_GREEN,COLOR_BLACK);
  init_pair(44,COLOR_CYAN,COLOR_BLACK);

  attrset(COLOR_PAIR(44));
  mvprintw(0,55," _ ");
  mvprintw(1,55,"|!|  is treasure (Increase your point).");
  mvprintw(2,55,"|_|");

  attrset(COLOR_PAIR(42)); 
  mvprintw(4,55," O ");
  mvprintw(5,55,"/_\\  is enemy car (If you crash it, game will be over).");
  mvprintw(6,55,"\\O/");

  attrset(COLOR_PAIR(41));
  mvprintw(8,55,"|b|");
  mvprintw(9,55,"|e|  is beer (If you get it, you will be drunken state).");
  mvprintw(10,55,"|r|");

  attrset(COLOR_PAIR(40));
  mvprintw(12,55,"   ");
  mvprintw(13,55,"O~*  is bomb (Decrease your point).");
  mvprintw(14,55,"   ");

  attrset(COLOR_PAIR(43));
  mvprintw(15,55,"/\\ ");
  mvprintw(16,55,"/\\  is Nitrous (Increase jump point).");
  mvprintw(17,55,"/\\ ");

  refresh();
    }
コード例 #11
0
/*
takes in an int i (current position in list), a list, the count of how many items are in the list(cnt),
an integer to check if the user has won the level (win), and the level counter.
Moves the unit, applies any damage dealt, removes dead units from the list and checks if the
user wins the level.
*/
int MoveUnit(int i, List * L, int * cnt, int * direction, int * win, int levelCount) {
	/*ch holds the farmer avatar value*/
	char ch;
	/*check is set if the unit is travelling vertically
	(code to check for damage is the same travelling up or down, eliminates
	redundant code)*/
	int check = 0;
	mvwprintw(stdscr, 0, 0, "Level %d", levelCount);

	/*Checks which direction to head when travelling vertically, so the unit
	doesn't jump between the path behind it and in front of it. 1 = up,
	0 = down*/
	if(mvinch(L->items[i].y, (L->items[i].x + 1)) != '.' && mvinch(L->items[i].y, (L->items[i].x + 1)) != 'B' && mvinch(L->items[i].y, (L->items[i].x + 1)) != 'Y' && mvinch(L->items[i].y, (L->items[i].x + 1)) != 'S' && mvinch((L->items[i].y - 1), L->items[i].x) == '+')
		L->items[i].direction = 1;
	else if(mvinch(L->items[i].y, (L->items[i].x + 1)) != '.' && mvinch(L->items[i].y, (L->items[i].x + 1)) != 'B' && mvinch(L->items[i].y, (L->items[i].x + 1)) != 'Y' && mvinch(L->items[i].y, (L->items[i].x + 1)) != 'S' && mvinch((L->items[i].y + 1), L->items[i].x) == '+')
		L->items[i].direction = 0;

	/*check if the unit should move to the left*/
	if(mvinch(L->items[i].y, (L->items[i].x - 1)) == '+') {
		/*move avatar to the left, replace its old spot with a '+',
		alter the unit's coordinates.*/
		mvaddch(L->items[i].y, (L->items[i].x - 1), L->items[i].avatar);
		mvaddch(L->items[i].y, L->items[i].x, '+');
		L->items[i].x = L->items[i].x - 1;

		/*damage calculations*/
		ch = (char)mvinch((L->items[i].y - 1), (L->items[i].x - 1));
		if(ch == 'B') {
			L->items[i].hp = L->items[i].hp - BDAM;
			/*if damage is taken, replace the character, but in red*/
			attron(COLOR_PAIR(1));
			mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar);
			attroff(COLOR_PAIR(1));
		}else if(ch == 'Y') {
			L->items[i].hp = L->items[i].hp - YDAM;
			attron(COLOR_PAIR(1));
			mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar);
			attroff(COLOR_PAIR(1));
		}else if(ch == 'S') {
			L->items[i].hp = L->items[i].hp - SDAM;
			attron(COLOR_PAIR(1));
			mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar);
			attroff(COLOR_PAIR(1));
		}

		ch = (char)mvinch((L->items[i].y - 1), (L->items[i].x));
		if(ch == 'B') {
			L->items[i].hp = L->items[i].hp - BDAM;
			attron(COLOR_PAIR(1));
			mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar);
			attroff(COLOR_PAIR(1));
		}else if(ch == 'Y') {
			L->items[i].hp = L->items[i].hp - YDAM;
			attron(COLOR_PAIR(1));
			mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar);
			attroff(COLOR_PAIR(1));
		}else if(ch == 'S') {
			L->items[i].hp = L->items[i].hp - SDAM;
			attron(COLOR_PAIR(1));
			mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar);
			attroff(COLOR_PAIR(1));
		}

		ch = (char)mvinch((L->items[i].y - 1), (L->items[i].x + 1));
		if(ch == 'B') {
			L->items[i].hp = L->items[i].hp - BDAM;
			attron(COLOR_PAIR(1));
			mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar);
			attroff(COLOR_PAIR(1));
		}else if(ch == 'Y') {
			L->items[i].hp = L->items[i].hp - YDAM;
			attron(COLOR_PAIR(1));
			mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar);
			attroff(COLOR_PAIR(1));
		}else if(ch == 'S') {
			L->items[i].hp = L->items[i].hp - SDAM;
			attron(COLOR_PAIR(1));
			mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar);
			attroff(COLOR_PAIR(1));
		}

		ch = (char)mvinch((L->items[i].y + 1), (L->items[i].x - 1));
		if(ch == 'B') {
			L->items[i].hp = L->items[i].hp - BDAM;
			attron(COLOR_PAIR(1));
			mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar);
			attroff(COLOR_PAIR(1));
		}else if(ch == 'Y') {
			L->items[i].hp = L->items[i].hp - YDAM;
			attron(COLOR_PAIR(1));
			mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar);
			attroff(COLOR_PAIR(1));
		}else if(ch == 'S') {
			L->items[i].hp = L->items[i].hp - SDAM;
			attron(COLOR_PAIR(1));
			mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar);
			attroff(COLOR_PAIR(1));
		}

		ch = (char)mvinch((L->items[i].y + 1), (L->items[i].x));
		if(ch == 'B') {
			L->items[i].hp = L->items[i].hp - BDAM;
			attron(COLOR_PAIR(1));
			mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar);
			attroff(COLOR_PAIR(1));
		}else if(ch == 'Y') {
			L->items[i].hp = L->items[i].hp - YDAM;
			attron(COLOR_PAIR(1));
			mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar);
			attroff(COLOR_PAIR(1));
		}else if(ch == 'S') {
			L->items[i].hp = L->items[i].hp - SDAM;
			attron(COLOR_PAIR(1));
			mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar);
			attroff(COLOR_PAIR(1));
		}

		ch = (char)mvinch((L->items[i].y + 1), (L->items[i].x + 1));
		if(ch == 'B') {
			L->items[i].hp = L->items[i].hp - BDAM;
			attron(COLOR_PAIR(1));
			mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar);
			attroff(COLOR_PAIR(1));
		}else if(ch == 'Y') {
			L->items[i].hp = L->items[i].hp - YDAM;
			attron(COLOR_PAIR(1));
			mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar);
			attroff(COLOR_PAIR(1));
		}else if(ch == 'S') {
			L->items[i].hp = L->items[i].hp - SDAM;
			attron(COLOR_PAIR(1));
			mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar);
			attroff(COLOR_PAIR(1));
		}
	/*check if unit moves up.*/
	}else if(mvinch((L->items[i].y - 1), L->items[i].x) == '+' && L->items[i].direction == 1) {
		mvaddch((L->items[i].y - 1), L->items[i].x, L->items[i].avatar);
		mvaddch(L->items[i].y, L->items[i].x, '+');
		L->items[i].y = L->items[i].y - 1;
		check = 1;
	
	/*check if unit moves down.*/
	} else if(mvinch((L->items[i].y + 1), L->items[i].x) == '+' && L->items[i].direction == 0) {
		mvaddch((L->items[i].y + 1), L->items[i].x, L->items[i].avatar);
		mvaddch(L->items[i].y, L->items[i].x, '+');
		L->items[i].y = L->items[i].y + 1;
		check = 1;
	/*following code blocks check if the unit has reached the end of the map.
	If so, removes unit from the map (not the list!), sets win condition to 1,
	and subtracts 1 from the count of units on the board.*/
	}else if(mvinch(L->items[i].y, (L->items[i].x - 1)) == 'O') {
		mvaddch(L->items[i].y, L->items[i].x, '+');
		if(*cnt != 0)
			*cnt = *cnt - 1;
		*win = 1;
	
	} else if(mvinch((L->items[i].y - 1), L->items[i].x) == 'O') {
		mvaddch(L->items[i].y, L->items[i].x, '+');
		if(*cnt != 0)
			*cnt = *cnt - 1;
		*win = 1;
	
	} else if(mvinch((L->items[i].y + 1), L->items[i].x) == 'O') {
		mvaddch(L->items[i].y, L->items[i].x, '+');
		if(*cnt != 0)
			*cnt = *cnt - 1;
		*win = 1;
	}

	/*if the unit is travellint vertically, check for damage*/
	if(check == 1) {
		/*damage calculations*/
		ch = (char)mvinch((L->items[i].y - 1), (L->items[i].x - 1));
		if(ch == 'B') {
			L->items[i].hp = L->items[i].hp - BDAM;
			attron(COLOR_PAIR(1));
			mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar);
			attroff(COLOR_PAIR(1));
		}else if(ch == 'Y') {
			L->items[i].hp = L->items[i].hp - YDAM;
			attron(COLOR_PAIR(1));
			mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar);
			attroff(COLOR_PAIR(1));
		}else if(ch == 'S') {
			L->items[i].hp = L->items[i].hp - SDAM;
			attron(COLOR_PAIR(1));
			mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar);
			attroff(COLOR_PAIR(1));
		}

		ch = (char)mvinch((L->items[i].y), (L->items[i].x - 1));
		if(ch == 'B') {
			L->items[i].hp = L->items[i].hp - BDAM;
			attron(COLOR_PAIR(1));
			mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar);
			attroff(COLOR_PAIR(1));
		}else if(ch == 'Y') {
			L->items[i].hp = L->items[i].hp - YDAM;
			attron(COLOR_PAIR(1));
			mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar);
			attroff(COLOR_PAIR(1));
		}else if(ch == 'S') {
			L->items[i].hp = L->items[i].hp - SDAM;
			attron(COLOR_PAIR(1));
			mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar);
			attroff(COLOR_PAIR(1));
		}

		ch = (char)mvinch((L->items[i].y + 1), (L->items[i].x - 1));
		if(ch == 'B') {
			L->items[i].hp = L->items[i].hp - BDAM;
			attron(COLOR_PAIR(1));
			mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar);
			attroff(COLOR_PAIR(1));
		}else if(ch == 'Y') {
			L->items[i].hp = L->items[i].hp - YDAM;
			attron(COLOR_PAIR(1));
			mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar);
			attroff(COLOR_PAIR(1));
		}else if(ch == 'S') {
			L->items[i].hp = L->items[i].hp - SDAM;
			attron(COLOR_PAIR(1));
			mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar);
			attroff(COLOR_PAIR(1));
		}

		ch = (char)mvinch((L->items[i].y - 1), (L->items[i].x + 1));
		if(ch == 'B') {
			L->items[i].hp = L->items[i].hp - BDAM;
			attron(COLOR_PAIR(1));
			mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar);
			attroff(COLOR_PAIR(1));
		}else if(ch == 'Y') {
			L->items[i].hp = L->items[i].hp - YDAM;
			attron(COLOR_PAIR(1));
			mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar);
			attroff(COLOR_PAIR(1));
		}else if(ch == 'S') {
			L->items[i].hp = L->items[i].hp - SDAM;
			attron(COLOR_PAIR(1));
			mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar);
			attroff(COLOR_PAIR(1));
		}

		ch = (char)mvinch((L->items[i].y), (L->items[i].x + 1));
		if(ch == 'B') {
			L->items[i].hp = L->items[i].hp - BDAM;
			attron(COLOR_PAIR(1));
			mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar);
			attroff(COLOR_PAIR(1));
		}else if(ch == 'Y') {
			L->items[i].hp = L->items[i].hp - YDAM;
			attron(COLOR_PAIR(1));
			mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar);
			attroff(COLOR_PAIR(1));
		}else if(ch == 'S') {
			L->items[i].hp = L->items[i].hp - SDAM;
			attron(COLOR_PAIR(1));
			mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar);
			attroff(COLOR_PAIR(1));
		}

		ch = (char)mvinch((L->items[i].y + 1), (L->items[i].x + 1));
		if(ch == 'B') {
			L->items[i].hp = L->items[i].hp - BDAM;
			attron(COLOR_PAIR(1));
			mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar);
			attroff(COLOR_PAIR(1));
		}else if(ch == 'Y') {
			L->items[i].hp = L->items[i].hp - YDAM;
			attron(COLOR_PAIR(1));
			mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar);
			attroff(COLOR_PAIR(1));
		}else if(ch == 'S') {
			L->items[i].hp = L->items[i].hp - SDAM;
			attron(COLOR_PAIR(1));
			mvaddch(L->items[i].y, L->items[i].x, L->items[i].avatar);
			attroff(COLOR_PAIR(1));
		}
	}

	/*remove the unit from the map and the list if it has no hp left*/
	if(L->items[i].hp <= 0) {
		mvaddch(L->items[i].y, L->items[i].x, '+');
		Remove(i, L);
		*cnt = *cnt - 1;
	}

	refresh();

	if(*cnt == 0)
		return 0;
	return 1;
}
コード例 #12
0
ファイル: ncurses.c プロジェクト: UnitedMarsupials/kame
static void color_edit(void)
/* display the color test pattern, without trying to edit colors */
{
    int	i, c, value = 0, current = 0, field = 0, usebase = 0;

    refresh();

    for (i = 0; i < COLORS; i++)
	init_pair(i, COLOR_WHITE, i);

    do {
	short	red, green, blue;

	attron(A_BOLD);
	mvaddstr(0, 20, "Color RGB Value Editing");
	attroff(A_BOLD);

	for (i = 0; i < COLORS; i++)
        {
	    mvprintw(2 + i, 0, "%c %-8s:",
		     (i == current ? '>' : ' '),
		     (i < sizeof(colors)/sizeof(colors[0]) ? colors[i] : ""));
	    attrset(COLOR_PAIR(i));
	    addstr("        ");
	    attrset(A_NORMAL);

	    /*
	     * Note: this refresh should *not* be necessary!  It works around
	     * a bug in attribute handling that apparently causes the A_NORMAL
	     * attribute sets to interfere with the actual emission of the
	     * color setting somehow.  This needs to be fixed.
	     */
	    refresh();

	    color_content(i, &red, &green, &blue);
	    addstr("   R = ");
	    if (current == i && field == 0) attron(A_STANDOUT);
	    printw("%04d", red);
	    if (current == i && field == 0) attrset(A_NORMAL);
	    addstr(", G = ");
	    if (current == i && field == 1) attron(A_STANDOUT);
	    printw("%04d", green);
	    if (current == i && field == 1) attrset(A_NORMAL);
	    addstr(", B = ");
	    if (current == i && field == 2) attron(A_STANDOUT);
	    printw("%04d", blue);
	    if (current == i && field == 2) attrset(A_NORMAL);
	    attrset(A_NORMAL);
	    addstr(")");
	}

	mvaddstr(COLORS + 3, 0,
	    "Use up/down to select a color, left/right to change fields.");
	mvaddstr(COLORS + 4, 0,
	    "Modify field by typing nnn=, nnn-, or nnn+.  ? for help.");

	move(2 + current, 0);

	switch (c = getch())
	{
	case KEY_UP:
	    current = (current == 0 ? (COLORS - 1) : current - 1);
	    value = 0;
	    break;

	case KEY_DOWN:
	    current = (current == (COLORS - 1) ? 0 : current + 1);
	    value = 0;
	    break;

	case KEY_RIGHT:
	    field = (field == 2 ? 0 : field + 1);
	    value = 0;
	    break;

	case KEY_LEFT:
	    field = (field == 0 ? 2 : field - 1);
	    value = 0;
	    break;

	case '0': case '1': case '2': case '3': case '4':
	case '5': case '6': case '7': case '8': case '9':
	    do {
		value = value * 10 + (c - '0');
		c = getch();
	    } while
		(isdigit(c));
	    if (c != '+' && c != '-' && c != '=')
		beep();
	    else
		ungetch(c);
	    break;

	case '+':
	    usebase = 1;
	    goto changeit;

	case '-':
	    value = -value;
	    usebase = 1;
	    goto changeit;

	case '=':
	    usebase = 0;
	changeit:
	    color_content(current, &red, &green, &blue);
	    if (field == 0)
		red = red * usebase + value;
	    else if (field == 1)
		green = green * usebase + value;
	    else if (field == 2)
		blue = blue * usebase + value;
	    init_color(current, red, green, blue);
	    break;

	case '?':
	    erase();
    P("                      RGB Value Editing Help");
    P("");
    P("You are in the RGB value editor.  Use the arrow keys to select one of");
    P("the fields in one of the RGB triples of the current colors; the one");
    P("currently selected will be reverse-video highlighted.");
    P("");
    P("To change a field, enter the digits of the new value; they won't be");
    P("echoed.  Finish by typing `='; the change will take effect instantly.");
    P("To increment or decrement a value, use the same procedure, but finish");
    P("with a `+' or `-'.");
    P("");
    P("To quit, do `x' or 'q'");

	    move(LINES - 1, 0);
	    addstr("Press any key to continue... ");
	    (void) getch();
	    erase();
	    break;

	case 'x':
	case 'q':
	    break;

	default:
	    beep();
	    break;
	}
    } while
	(c != 'x' && c != 'q');

    erase();
    endwin();
}
コード例 #13
0
ファイル: Footer.cpp プロジェクト: TacoVox/AutoTux
ui::Footer::Footer(int x, int y) : xsize(x), ysize(y),
    _footer(newwin(1, xsize, ysize - 1, 0)),
    time(std::time(nullptr)) {
    init_pair(1, 7, 4);
    wbkgd(_footer, COLOR_PAIR(1));
}
コード例 #14
0
ファイル: cbfs_module.c プロジェクト: AdriDlu/coreboot
static int cbfs_module_redraw(WINDOW * win)
{
	struct cbfile *f;
	int i, row = 2;

	print_module_title(win, "CBFS Listing");

	if (!header) {
		mvwprintw(win, 11, 61 / 2, "Bad or missing CBFS header");
		return 0;
	}

	/* Draw a line down the middle. */
	for (i = 2; i < 21; i++)
		mvwaddch(win, i, 30, ACS_VLINE);

	/* Draw the names down the left side. */
	for (i = 0; i < filecount; i++) {
		if (i == selected)
			wattrset(win, COLOR_PAIR(3) | A_BOLD);
		else
			wattrset(win, COLOR_PAIR(2));

		if (strlen(filenames[i]) == 0) {
			if (findfile(filenames[i])->type == COMPONENT_NULL)
				mvwprintw(win, 2 + i, 1, "<free space>");
			else
				mvwprintw(win, 2 + i, 1, "<unnamed>");
		} else {
			mvwprintw(win, 2 + i, 1, "%.25s", filenames[i]);
		}
	}

	f = findfile(filenames[selected]);
	if (!f) {
		mvwprintw(win, 11, 32, "ERROR: CBFS component not found");
		return 0;
	}

	wattrset(win, COLOR_PAIR(2));

	/* mvwprintw(win, row++, 32, "Offset: 0x%x", f->offset); *//* FIXME */
	mvwprintw(win, row, 32, "Type: ");
	switch (ntohl(f->type)) {
	case COMPONENT_BOOTBLOCK:
		mvwprintw(win, row++, 38, "bootblock");
		break;
	case COMPONENT_CBFSHEADER:
		mvwprintw(win, row++, 38, "CBFS header");
		break;
	case COMPONENT_STAGE:
		mvwprintw(win, row++, 38, "stage");
		break;
	case COMPONENT_PAYLOAD:
		mvwprintw(win, row++, 38, "payload");
		break;
	case COMPONENT_OPTIONROM:
		mvwprintw(win, row++, 38, "optionrom");
		break;
	case COMPONENT_RAW:
		mvwprintw(win, row++, 38, "raw");
		break;
	case COMPONENT_MICROCODE:
		mvwprintw(win, row++, 38, "microcode");
		break;
	case COMPONENT_CMOS_LAYOUT:
		mvwprintw(win, row++, 38, "cmos layout");
		break;
	case COMPONENT_NULL:
		mvwprintw(win, row++, 38, "free");
		break;
	case COMPONENT_DELETED:
		mvwprintw(win, row++, 38, "deleted");
		break;
	default:
		mvwprintw(win, row++, 38, "Unknown (0x%x)", ntohl(f->type));
		break;
	}
	mvwprintw(win, row++, 32, "Size: %d", ntohl(f->len));
	mvwprintw(win, row++, 32, "Checksum: 0x%x", ntohl(f->checksum));

	return 0;
}
コード例 #15
0
ファイル: engine.c プロジェクト: liushizhe/yetris
/** Starts all the subscreens of the game */
int engine_windows_init()
{
	window_s  w;
	screen_s* s = &(engine.screen);

	int main_x = 0;
	int main_y = 0;
	if (global.screen_center_horizontally)
		main_x = engine.screen.width/2 - 80/2;

	if (global.screen_center_vertically)
		main_y = engine.screen.height/2 - 24/2;

	/* main window, wrapper of all others */
	w.width  = 80;
	w.height = 24;
	w.x      = main_x;
	w.y      = main_y;
	w.win    = newwin(w.height, w.width, w.y, w.x);
	if (global.screen_show_outer_border)
	{
		if (global.screen_fancy_borders)
			window_fancy_borders(w.win);
		else
			window_normal_borders(w.win);
	}

	wnoutrefresh(w.win);
	s->main = w;

	/* leftmost */
	w.width  = 6 * 2 + 2;
	w.height = s->main.height - 2; /* borders */
	w.x      = 2;
	w.y      = 1;
	w.win    = derwin(s->main.win, w.height, w.width, w.y, w.x);

	if (global.screen_fancy_borders)
	{
		window_fancy_borders(w.win);

		/* If the player has no hold, doesnt make sense printing these parts */
		if (global.game_can_hold)
		{
			/* making the top line between hold and score windows */
			mvwaddch(w.win, 5, 0, ACS_LLCORNER|COLOR_PAIR(WHITE_BLACK));
			my_mvwhline(w.win, 5, 1, ACS_HLINE|COLOR_PAIR(BLACK_BLACK)|A_BOLD, w.width - 2);
			mvwaddch(w.win, 5, w.width - 1, ACS_LRCORNER|COLOR_PAIR(BLACK_BLACK)|A_BOLD);

			/* making the bottom line between hold and score windows */
			mvwaddch(w.win, 6, 0, ACS_ULCORNER|COLOR_PAIR(WHITE_BLACK)|A_BOLD);
			my_mvwhline(w.win, 6, 1, ACS_HLINE|COLOR_PAIR(WHITE_BLACK), w.width - 2);
			mvwaddch(w.win, 6, w.width - 1, ACS_URCORNER|COLOR_PAIR(WHITE_BLACK));
		}

	}
	else
	{
		window_normal_borders(w.win);
		wattrset(w.win, engine_get_color(COLOR_BLACK, COLOR_BLACK, true));
		mvwhline(w.win, 5, 1, '-', w.width - 2);
	}

	wnoutrefresh(w.win);
	s->leftmost = w;

	/* middle-left */
	w.width  = 10 * 2 + 2;
	w.height = s->main.height - 2; /* borders */
	w.x      = s->leftmost.x + s->leftmost.width + 1;
	w.y      = 1;
	w.win    = derwin(s->main.win, w.height, w.width, w.y, w.x);
	if (global.screen_fancy_borders)
		window_fancy_borders(w.win);
	else
		window_normal_borders(w.win);
	wnoutrefresh(w.win);
	s->middle_left = w;

	/* middle-right */
	w.width  = 4 * 2 + 2;
	w.height = s->main.height - 2; /* borders */
	w.x      = s->middle_left.x + s->middle_left.width + 1;
	w.y      = 1;
	w.win    = derwin(s->main.win, w.height, w.width, w.y, w.x);
	if (global.screen_fancy_borders)
	{
		window_fancy_borders(w.win);
		/* making the top line between 1st next and the rest */
		mvwaddch(w.win, 3, 0, ACS_LLCORNER|COLOR_PAIR(WHITE_BLACK));
		mvwhline(w.win, 3, 1, ACS_HLINE|COLOR_PAIR(BLACK_BLACK)|A_BOLD, w.width - 2);
		mvwaddch(w.win, 3, w.width - 1, ACS_LRCORNER|COLOR_PAIR(BLACK_BLACK)|A_BOLD);

		/* making the bottom line between 1st next and the rest */
		mvwaddch(w.win, 4, 0, ACS_ULCORNER|COLOR_PAIR(WHITE_BLACK)|A_BOLD);
		mvwhline(w.win, 4, 1, ACS_HLINE|COLOR_PAIR(WHITE_BLACK), w.width - 2);
		mvwaddch(w.win, 4, w.width - 1, ACS_URCORNER|COLOR_PAIR(WHITE_BLACK));

	}
	else
	{
		window_normal_borders(w.win);
		wattrset(w.win, engine_get_color(COLOR_BLACK, COLOR_BLACK, true));
		mvwhline(w.win, 3, 1, '-', w.width - 2);
	}
	wnoutrefresh(w.win);
	s->middle_right = w;

	/* right-most */
	w.width  = s->main.width - (s->middle_right.x + s->middle_right.width) - 3;
	w.height = s->main.height - 2; /* borders */
	w.x      = s->middle_right.x + s->middle_right.width + 1;
	w.y      = 1;
	w.win    = derwin(s->main.win, w.height, w.width, w.y, w.x);
	if (global.screen_fancy_borders)
		window_fancy_borders(w.win);
	else
		window_normal_borders(w.win);
	wnoutrefresh(w.win);
	s->rightmost = w;

	/* next pieces */
	w.width  = s->middle_right.width  - 2;
	w.height = s->middle_right.height - 2;
	w.x      = 1;
	w.y      = 1;
	w.win    = derwin(s->middle_right.win, w.height, w.width, w.y, w.x);
	wnoutrefresh(w.win);
	s->next_container = w;

	/* first next piece */
	w.width  = s->next_container.width;
	w.height = 2;
	w.x      = 0;
	w.y      = 0;
	w.win    = derwin(s->next_container.win, w.height, w.width, w.y, w.x);
	wnoutrefresh(w.win);
	s->next[0] = w;

	/* the rest */
	int i; int y_offset = 2;
	for (i = 1; i <= global.game_next_no; i++)
	{
		/* making all the next pieces 1 line lower */
		if (i != 1)
			y_offset = 0;

		w.width  = s->next_container.width;
		w.height = 2;
		w.x      = 0;
		w.y      = s->next[i - 1].y + s->next[i - 1].height + 1 + y_offset;
		w.win    = derwin(s->next_container.win, w.height, w.width, w.y, w.x);
		wnoutrefresh(w.win);
		s->next[i] = w;
	}

	s->board = new_sub_win_from(s->middle_left.win, (s->middle_left.width - 2), (s->middle_left.height - 2), 1, 1);

	s->info  = new_sub_win_from(s->rightmost.win,   (s->rightmost.width - 4),   (s->rightmost.height - 2),   2, 1);

	s->leftmost_container = new_sub_win_from(s->leftmost.win,
											 (s->leftmost.width - 2),
											 (s->leftmost.height - 2),
											 1,
											 1);

	s->hold = new_sub_win_from(s->leftmost_container.win,
							   s->leftmost_container.width,
							   4,
							   0,
							   0);

	s->score = new_sub_win_from(s->leftmost_container.win,
								s->leftmost_container.width,
								s->leftmost_container.height - (s->hold.height) - 2,
								0,
								s->hold.y + s->hold.height + 2);

	/* w.width  = s->leftmost_container.width; */
	/* w.height = s->leftmost_container.height - (s->hold.height) - 2; */
	/* w.x      = 0; */
	/* w.y      = s->hold.y + s->hold.height + 2; */
	/* w.win    = derwin(s->leftmost_container.win, w.height, w.width, w.y, w.x); */
	/* wnoutrefresh(w.win); */
	/* s->score = w; */

	w = s->info;
	wattrset(w.win, engine_get_color(COLOR_WHITE, COLOR_BLACK, true));
	mvwaddstr(w.win, w.height - 1, 16 , "Loading");
	wnoutrefresh(w.win);
	return 1;
}
コード例 #16
0
ファイル: out_curses.c プロジェクト: Csrawil/canaima
static void
print_content(void)
{
	int required_lines = 0, disable_detailed = 0, disabled_graphical = 0;

	if (NULL == get_current_node())
		return;

	if (c_list_in_list) {
		NEXT_ROW;
		putl("");

		if (c_use_colors)
			attrset(COLOR_PAIR(LAYOUT_HEADER) | layout[LAYOUT_HEADER].attr);
	
		NEXT_ROW;
		putl("  #   Tarjeta de Red ' Rawil'               RX Tasa         RX #   " \
			"  TX Tasa         TX #");
	
		NEXT_ROW;
		hline(ACS_HLINE, cols);

		if (c_combined_node_list)
			foreach_node(draw_node, NULL);
		else
			draw_node(get_current_node(), NULL);
	} else {
		NEXT_ROW;
		hline(ACS_HLINE, cols);
		move(row, 24);
		addstr(" Press l to enable list view ");
		move(row, 0);
	}

	/*
	 * calculate lines required for graphical and detailed stats unfolded
	 */
	if (c_graphical_in_list)
		required_lines += lines_required_for_graphical();
	else
		required_lines++;

	if (c_detailed_in_list)
		required_lines += lines_required_for_detailed();
	else
		required_lines++;

	if ((rows - row) <= (required_lines + 1)) {
		/*
		 * not enough lines, start over with detailed stats disabled
		 */
		required_lines = 0;
		disable_detailed = 1;

		/*
		 * 1 line for folded detailed stats display
		 */
		required_lines++;

		if (c_graphical_in_list)
			required_lines += lines_required_for_graphical();
		else
			required_lines++;

		if ((rows - row) <= (required_lines + 1)) {
			/*
			 * bad luck, not even enough space for graphical stats
			 * reserve 2 lines for displaying folded detailed and
			 * graphical stats
			 */
			required_lines = 2;
			disabled_graphical = 1;
		}
	}

	/*
	 * Clear out spare space
	 */
	while (row < (rows - (required_lines + 2))) {
		NEXT_ROW; putl("");
	}

	NEXT_ROW;
	hline(ACS_HLINE, cols);

	if (c_graphical_in_list) {
		if (disabled_graphical) {
			move(row, 15);
			addstr(" Increase screen size to see graphical statistics ");
			move(row, 0);
		} else
			draw_graphic();
	} else {
		move(row, 20);
		addstr(" Press g to enable graphical statistics ");
		move(row, 0);
	}

	NEXT_ROW;
	hline(ACS_HLINE, cols);

	if (c_detailed_in_list) {
		if (disable_detailed) {
			move(row, 15);
			addstr(" Increase screen size to see detailed statistics ");
			move(row, 0);
		} else
			draw_detailed();
	} else {
		move(row, 20);
		addstr(" Press d to enable detailed statistics ");
		move(row, 0);
	}
}
コード例 #17
0
ファイル: engine.c プロジェクト: liushizhe/yetris
void engine_draw_next_pieces(game_s* g)
{
	WINDOW* w = NULL;
	int i, k;
	for (i = 0; i < global.game_next_no; i++)
	{
		piece_s p = g->piece_next[i];
		w = engine.screen.next[i].win;

		werase(w);

		/* This is a little hack to pretty-print pieces
		 * TODO somehow manage to fix this */
		for (k = 0; k < 4; k++)
		{
			/* shifting them to the left */
			p.block[k].x -= p.x + 1;
			p.block[k].y -= p.y;

			p.block[k].y--;

			if (p.type == PIECE_O)
				p.block[k].y -= 1;
		}
		engine_draw_piece(&p, w);
		wnoutrefresh(w);
	}

	w = engine.screen.middle_right.win;

	if (global.screen_fancy_borders)
	{
		mvwaddch(w, 3, 0, ACS_LLCORNER|COLOR_PAIR(WHITE_BLACK));
		mvwhline(w, 3, 1, ACS_HLINE|COLOR_PAIR(BLACK_BLACK)|A_BOLD, 8);
		mvwaddch(w, 3, 9, ACS_LRCORNER|COLOR_PAIR(BLACK_BLACK)|A_BOLD);
	}
	else
	{
		wattrset(w, engine_get_color(COLOR_BLACK, COLOR_BLACK, true));
		mvwhline(w, 3, 1, '-', 8);
	}

	wattrset(w, engine_get_color(COLOR_BLUE, COLOR_BLACK, false));
	mvwaddstr(w, 0, 1, "Next");
	wnoutrefresh(w);

	window_s* win = &(engine.screen.middle_right);

	/* RE-DRAWING BORDERS (damn this sucks) */
	if (global.screen_fancy_borders)
	{
		window_fancy_borders(win->win);
		/* making the top line between 1st next and the rest */
		mvwaddch(win->win, 3, 0, ACS_LLCORNER|COLOR_PAIR(WHITE_BLACK));
		mvwhline(win->win, 3, 1, ACS_HLINE|COLOR_PAIR(BLACK_BLACK)|A_BOLD, win->width - 2);
		mvwaddch(win->win, 3, win->width - 1, ACS_LRCORNER|COLOR_PAIR(BLACK_BLACK)|A_BOLD);

		/* making the bottom line between 1st next and the rest */
		mvwaddch(win->win, 4, 0, ACS_ULCORNER|COLOR_PAIR(WHITE_BLACK)|A_BOLD);
		mvwhline(win->win, 4, 1, ACS_HLINE|COLOR_PAIR(WHITE_BLACK), win->width - 2);
		mvwaddch(win->win, 4, win->width - 1, ACS_URCORNER|COLOR_PAIR(WHITE_BLACK));

	}
	else
	{
		window_normal_borders(win->win);
		wattrset(win->win, engine_get_color(COLOR_BLACK, COLOR_BLACK, true));
		mvwhline(win->win, 3, 1, '-', win->width - 2);
	}

}
コード例 #18
0
ファイル: out_curses.c プロジェクト: Csrawil/canaima
static void
curses_draw(void)
{
	if (NULL == get_current_node()) {
		first_node();
		first_intf();
	}

    row = 0;
    move(0,0);
	
	getmaxyx(stdscr, rows, cols);
	
	if (cols < 80) {
		clear();
		putl("Screen must be at least 80 columns wide");
		refresh();
		return;
	}

	if (c_use_colors)
		attrset(COLOR_PAIR(LAYOUT_STATUSBAR) | layout[LAYOUT_STATUSBAR].attr);
	else
		attrset(A_REVERSE);

	if (get_current_node() && get_current_intf()) {
		putl(" interface: %s at %s",
			get_current_intf()->i_name, get_current_node()->n_name);
	}

	move(row, COLS - strlen(PACKAGE_STRING) - 1);
	putl("%s", PACKAGE_STRING);
	move(row, 0);
	
	if (c_use_colors)
		attrset(COLOR_PAIR(LAYOUT_DEFAULT) | layout[LAYOUT_DEFAULT].attr);
	else
		attroff(A_REVERSE);
	
	print_content();

	if (quit_mode)
		print_quit();
	else if (print_help)
		draw_help();

	for (; row < rows-2;) {
		move(++row, 0);
		putl("");
	}
	
	row = rows-1;
	move(row, 0);

	if (c_use_colors)
		attrset(COLOR_PAIR(LAYOUT_STATUSBAR) | layout[LAYOUT_STATUSBAR].attr);
	else
		attrset(A_REVERSE);

	putl(" ^ prev interface, v next interface, <- prev node, -> next node, ? help");
	
	attrset(0);
	refresh();
}
コード例 #19
0
ファイル: curses.c プロジェクト: WuKongQC/opensips
int draw_item_list(select_menu *menu)
{
	select_item *it;
	int i=0,j=0,k=0,d,sc=0;
	int c,curopt=0;
	char buf[40];
	select_item *current=NULL;
	int should_scroll,max_display;
	int len,max_len=0;
	int disp_start=0,actual_pos=0;
again:
	i=0;j=0;k=0;
	max_display=max_y/2-2;
	should_scroll=menu->item_no>max_display?1:0;

	wclear(menu_window);

	/* print title in colour */
	attron(COLOR_PAIR(1));
	mvprintw(HIGH_NOTICE_Y,max_x/2-20,menu->name);
	attroff(COLOR_PAIR(1));

	if (should_scroll) {
		for (it=menu->item_list,sc=0;it;it=it->next,sc++) {
			/* only draw visible part of menu */
			if (sc>=disp_start && i < max_display) {
				wmove(menu_window, max_y/4+j++, max_x / 2 - 20);
				i++;
				snprintf(buf, sizeof(buf), "[%s] %s", it->enabled ? "*" : " ", it->name);
				waddstr(menu_window, buf);
				len=strlen(it->name);
				if (len > max_len)
					max_len=len;
			}
		}
	} else {
		for (it=menu->item_list,sc=0;it;it=it->next,sc++) {
			/* draw everything */
			wmove(menu_window, max_y/4+j++, max_x / 2 - 20);
			i++;
			snprintf(buf, sizeof(buf), "[%s] %s", it->enabled ? "*" : " ", it->name);
			waddstr(menu_window, buf);
			len=strlen(it->name);
			if (len > max_len)
				max_len=len;
		}

		/* marker is always in par with the selected option */
		actual_pos=curopt;
	}

	for(it=menu->item_list;it;it=it->next)
		if (k++ == curopt) {
			current=it;
			break;
		}

	/* print current item description */
	if (current->description) {
		attron(COLOR_PAIR(1));
		print_notice(NOTICE_Y,NOTICE_X,0,current->description);
		attroff(COLOR_PAIR(1));
	}

	move(max_y/4+actual_pos,max_x/2-19);

	/* draw box */
	wattron(menu_window,COLOR_PAIR(2));
	for (d=-1;d<i+1;d++) {
		wmove(menu_window,max_y/4+d,max_x/2-26);
		wprintw(menu_window,"|");
		wmove(menu_window,max_y/4+d,max_x/2-10+max_len);
		wprintw(menu_window,"|");
	}

	for (d=0;d<max_len+15;d++) {
		wmove(menu_window,max_y/4-2,max_x/2-25+d);
		wprintw(menu_window,"_");
		wmove(menu_window,max_y/4+i,max_x/2-25+d);
		wprintw(menu_window,"_");
	}

	/* show scrolling notifications if it's the case */
	if (should_scroll && disp_start > 0) {
		wmove(menu_window,max_y/4,max_x/2-5+max_len);
		wprintw(menu_window,"Scroll up for more");
	}

	if (should_scroll && disp_start + max_display < menu->item_no) {
		wmove(menu_window,max_y/4+max_display-1,max_x/2-5+max_len);
		wprintw(menu_window,"Scroll down for more");
	}

	wattroff(menu_window,COLOR_PAIR(2));

	wrefresh(menu_window);
	k=0;

	while ((c = getch())) {
		switch (c) {
			case KEY_UP:
				if (should_scroll && curopt != 0) {
					if (curopt == disp_start) {
						disp_start--;
						actual_pos=0;
					} else
						actual_pos--;
					curopt--;
				} else if (curopt!=0) {
					curopt--;
				}
				break;
			case KEY_DOWN:
				if (should_scroll && curopt < menu->item_no-1) {
					if (curopt == (disp_start+max_display-1)) {
						disp_start++;
						actual_pos=i-1;
					} else
						actual_pos++;
					curopt++;
				} else if (curopt < i-1) {
					curopt++;
				}
				break;
			case ' ':
				for (it=menu->item_list;it;it=it->next) {
					if (k++ == curopt) {
						it->enabled=it->enabled?0:1;
						menu->child_changed=CHILD_CHANGED;
					}
				}
				break;
			case KEY_LEFT:
			case 'q':
			case 'Q':
				wclear(menu_window);
				return 0;
		}

		goto again;
	}

	return 0;
}
コード例 #20
0
ファイル: index_game.c プロジェクト: Piyush13y/2048
/* Starts the program and prints the main menu */
int main(int qw) {
    static int mm = -1;
    mm++;
    initscr();
    curs_set(0);
    noecho();
    if(qw == 2)
        banner(4);
    else if(qw == 1)
        banner(3);
    ITEM **my_items;
    int c;
    MENU *my_menu;
    WINDOW *my_menu_win;
    int n_choices, i;
    ITEM *cur;
    /* Initialize curses */
    initscr();
    start_color();
    init_pair(5, COLOR_RED, COLOR_BLACK);
    init_pair(6, COLOR_BLACK, COLOR_RED);
    init_pair(7, COLOR_CYAN, COLOR_BLACK);
    cbreak();
    noecho();
    keypad(stdscr, TRUE);
    init_pair(1, COLOR_RED, COLOR_BLACK);
START:
    attrset(COLOR_PAIR(7));
    n_choices = ARRAY_SIZE(choices_index);
    my_items = (ITEM **)calloc(n_choices, sizeof(ITEM *));
    for(i = 0; i < n_choices; ++i) {
        my_items[i] = new_item(choices_index[i], NULL);
        if(i == 0)
            /* Set the user pointer */
            set_item_userptr(my_items[i], mains);
        else if(i == 1)
            set_item_userptr(my_items[i], race_menu);
        else if(i == 2)
            set_item_userptr(my_items[i], exitit);
    }
    my_items[n_choices] = (ITEM *)NULL;
    /* Crate menu */
    my_menu = new_menu((ITEM **)my_items);

    /* Create the window to be associated with the menu */
    my_menu_win = newwin(8, 25, 15, 70);
    keypad(my_menu_win, TRUE);

    /* Set main window and sub window */
    set_menu_win(my_menu, my_menu_win);
    set_menu_sub(my_menu, derwin(my_menu_win, 5, 19, 3, 1));

    /* Set menu mark to the string " * " */
    set_menu_mark(my_menu, "--> ");

    /* Print a border around the main window and print a title */
    box(my_menu_win, 0, 0);
    print_in_middle1(my_menu_win, 1, 0, 25, "CHOOSE A GAME", COLOR_PAIR(7));
    attrset(COLOR_PAIR(7));
    mvwaddch(my_menu_win, 2, 0, ACS_LTEE);
    mvwhline(my_menu_win, 2, 1, ACS_HLINE, 24);
    mvwaddch(my_menu_win, 2, 24, ACS_RTEE);
    mvprintw(LINES - 2, 1, " Press F1 to exit");
    /* Post the menu */
    mvprintw(LINES - 3, 1, " Press <ENTER> to see the option selected");
    mvprintw(LINES - 2, 1, " Up and Down arrow keys to navigate (F1 to Exit)");
    post_menu(my_menu);
    if(!mm)
        moto(0);
    else
        moto(1);
    refresh();

    /* Post the menu */
    post_menu(my_menu);
    wrefresh(my_menu_win);

    while((c = wgetch(my_menu_win)) != KEY_F(1))
    {   switch(c)
        {
        case KEY_DOWN:
            menu_driver(my_menu, REQ_DOWN_ITEM);
            break;
        case KEY_UP:
            menu_driver(my_menu, REQ_UP_ITEM);
            break;
        case 10:
            cur = current_item(my_menu);
            endwin();
            unpost_menu(my_menu);
            clear();
            refresh();
            void (*p)(char *);
            cur = current_item(my_menu);
            p = item_userptr(cur);
            p((char *)item_name(cur));
            pos_menu_cursor(my_menu);
            initscr();	/* Post the menu */
            attrset(COLOR_PAIR(7));
            mvprintw(LINES - 3, 1, " Press <ENTER> to see the option selected");
            mvprintw(LINES - 2, 1, " Up and Down arrow keys to naviage (F1 to Exit)");
            goto START;
            refresh();
            break;
        }
        wrefresh(my_menu_win);
    }

    /* Unpost and free all the memory taken up */
    for(i = 0; i < n_choices; ++i)
        free_item(my_items[i]);
    free_menu(my_menu);
    endwin();
    exit(1);
}
コード例 #21
0
ファイル: cmdline.c プロジェクト: ackeack/workenv
/*
 * op == 0 - draw
 * op < 0 - redraw
 * op > 0 - reset
 */
static void
draw_wild_menu(int op)
{
	static int last_pos;

	const char ** list = get_completion_list();
	int pos = get_completion_pos();
	int count = get_completion_count() - 1;
	int i;
	int len = getmaxx(stdscr);

	if(sub_mode == MENU_CMD_SUBMODE || input_stat.complete == NULL)
		return;

	if(count < 2)
		return;

	if(op > 0)
	{
		last_pos = 0;
		return;
	}

	if(pos == 0 || pos == count)
		last_pos = 0;
	if(last_pos == 0 && pos == count - 1)
		last_pos = count;
	if(pos < last_pos)
	{
		int l = len;
		while(last_pos > 0 && l > 2)
		{
			last_pos--;
			l -= strlen(list[last_pos]);
			if(last_pos != 0)
				l -= 2;
		}
		if(l < 2)
			last_pos++;
	}

	werase(stat_win);
	checked_wmove(stat_win, 0, 0);

	for(i = last_pos; i < count && len > 0; i++)
	{
		len -= strlen(list[i]);
		if(i != 0)
			len -= 2;

		if(i == last_pos && last_pos > 0)
		{
			wprintw(stat_win, "< ");
		}
		else if(i > last_pos)
		{
			if(len < 2)
			{
				wprintw(stat_win, " >");
				break;
			}
			wprintw(stat_win, "  ");
		}

		if(i == pos)
		{
			col_attr_t col;
			col = cfg.cs.color[STATUS_LINE_COLOR];
			mix_colors(&col, &cfg.cs.color[MENU_COLOR]);

			init_pair(DCOLOR_BASE + MENU_COLOR, col.fg, col.bg);
			wbkgdset(stat_win, COLOR_PAIR(DCOLOR_BASE + MENU_COLOR) | col.attr);
		}
		wprint(stat_win, list[i]);
		if(i == pos)
		{
			wbkgdset(stat_win, COLOR_PAIR(DCOLOR_BASE + STATUS_LINE_COLOR) |
					cfg.cs.color[STATUS_LINE_COLOR].attr);
			pos = -pos;
		}
	}
	if(pos > 0 && pos != count)
	{
		last_pos = pos;
		draw_wild_menu(op);
		return;
	}
	if(op == 0 && len < 2 && i - 1 == pos)
		last_pos = i;
	wrefresh(stat_win);

	update_cursor();
}
コード例 #22
0
void col_set(int kolor) {
	switch(kolor) {
		case 0:attrset(COLOR_PAIR(1));break;
		case 1:attrset(COLOR_PAIR(5));break;
		case 2:attrset(COLOR_PAIR(3));break;
		case 3:attrset(COLOR_PAIR(7));break;
		case 4:attrset(COLOR_PAIR(2));break;
		case 5:attrset(COLOR_PAIR(6));break;
		case 6:attrset(COLOR_PAIR(4));break;
		case 7:attrset(COLOR_PAIR(8));break;
		case 8:attrset(A_BOLD|COLOR_PAIR(1));break;
		case 9:attrset(A_BOLD|COLOR_PAIR(5));break;
		case 10:attrset(A_BOLD|COLOR_PAIR(3));break;
		case 11:attrset(A_BOLD|COLOR_PAIR(7));break;
		case 12:attrset(A_BOLD|COLOR_PAIR(2));break;
		case 13:attrset(A_BOLD|COLOR_PAIR(6));break;
		case 14:attrset(A_BOLD|COLOR_PAIR(4));break;
		case 15:attrset(A_BOLD|COLOR_PAIR(8));break;

		case 16:attrset(COLOR_PAIR(9));break;
		case 17:attrset(COLOR_PAIR(13));break;
		case 18:attrset(COLOR_PAIR(11));break;
		case 19:attrset(COLOR_PAIR(15));break;
		case 20:attrset(COLOR_PAIR(10));break;
		case 21:attrset(COLOR_PAIR(14));break;
		case 22:attrset(COLOR_PAIR(12));break;
		case 23:attrset(COLOR_PAIR(16));break;
		case 24:attrset(A_BOLD|COLOR_PAIR(9));break;
		case 25:attrset(A_BOLD|COLOR_PAIR(13));break;
		case 26:attrset(A_BOLD|COLOR_PAIR(11));break;
		case 27:attrset(A_BOLD|COLOR_PAIR(15));break;
		case 28:attrset(A_BOLD|COLOR_PAIR(10));break;
		case 29:attrset(A_BOLD|COLOR_PAIR(14));break;
		case 30:attrset(A_BOLD|COLOR_PAIR(12));break;
		case 31:attrset(A_BOLD|COLOR_PAIR(16));break;

		case 32:attrset(COLOR_PAIR(17));break;
		case 33:attrset(COLOR_PAIR(21));break;
		case 34:attrset(COLOR_PAIR(19));break;
		case 35:attrset(COLOR_PAIR(23));break;
		case 36:attrset(COLOR_PAIR(18));break;
		case 37:attrset(COLOR_PAIR(22));break;
		case 38:attrset(COLOR_PAIR(20));break;
		case 39:attrset(COLOR_PAIR(24));break;
		case 40:attrset(A_BOLD|COLOR_PAIR(17));break;
		case 41:attrset(A_BOLD|COLOR_PAIR(21));break;
		case 42:attrset(A_BOLD|COLOR_PAIR(19));break;
		case 43:attrset(A_BOLD|COLOR_PAIR(23));break;
		case 44:attrset(A_BOLD|COLOR_PAIR(18));break;
		case 45:attrset(A_BOLD|COLOR_PAIR(22));break;
		case 46:attrset(A_BOLD|COLOR_PAIR(20));break;
		case 47:attrset(A_BOLD|COLOR_PAIR(24));break;

		case 48:attrset(COLOR_PAIR(25));break;
		case 49:attrset(COLOR_PAIR(29));break;
		case 50:attrset(COLOR_PAIR(27));break;
		case 51:attrset(COLOR_PAIR(30));break;
		case 52:attrset(COLOR_PAIR(26));break;
		case 53:attrset(COLOR_PAIR(30));break;
		case 54:attrset(COLOR_PAIR(28));break;
		case 55:attrset(COLOR_PAIR(32));break;
		case 56:attrset(A_BOLD|COLOR_PAIR(25));break;
		case 57:attrset(A_BOLD|COLOR_PAIR(29));break;
		case 58:attrset(A_BOLD|COLOR_PAIR(27));break;
		case 59:attrset(A_BOLD|COLOR_PAIR(30));break;
		case 60:attrset(A_BOLD|COLOR_PAIR(26));break;
		case 61:attrset(A_BOLD|COLOR_PAIR(30));break;
		case 62:attrset(A_BOLD|COLOR_PAIR(28));break;
		case 63:attrset(A_BOLD|COLOR_PAIR(32));break;

		case 64:attrset(COLOR_PAIR(33));break;
		case 65:attrset(COLOR_PAIR(37));break;
		case 66:attrset(COLOR_PAIR(35));break;
		case 67:attrset(COLOR_PAIR(39));break;
		case 68:attrset(COLOR_PAIR(34));break;
		case 69:attrset(COLOR_PAIR(38));break;
		case 70:attrset(COLOR_PAIR(36));break;
		case 71:attrset(COLOR_PAIR(40));break;
		case 72:attrset(A_BOLD|COLOR_PAIR(33));break;
		case 73:attrset(A_BOLD|COLOR_PAIR(37));break;
		case 74:attrset(A_BOLD|COLOR_PAIR(35));break;
		case 75:attrset(A_BOLD|COLOR_PAIR(39));break;
		case 76:attrset(A_BOLD|COLOR_PAIR(34));break;
		case 77:attrset(A_BOLD|COLOR_PAIR(38));break;
		case 78:attrset(A_BOLD|COLOR_PAIR(36));break;
		case 79:attrset(A_BOLD|COLOR_PAIR(40));break;

		case 80:attrset(COLOR_PAIR(41));break;
		case 81:attrset(COLOR_PAIR(45));break;
		case 82:attrset(COLOR_PAIR(43));break;
		case 83:attrset(COLOR_PAIR(47));break;
		case 84:attrset(COLOR_PAIR(42));break;
		case 85:attrset(COLOR_PAIR(46));break;
		case 86:attrset(COLOR_PAIR(44));break;
		case 87:attrset(COLOR_PAIR(48));break;
		case 88:attrset(A_BOLD|COLOR_PAIR(41));break;
		case 89:attrset(A_BOLD|COLOR_PAIR(45));break;
		case 90:attrset(A_BOLD|COLOR_PAIR(43));break;
		case 91:attrset(A_BOLD|COLOR_PAIR(47));break;
		case 92:attrset(A_BOLD|COLOR_PAIR(42));break;
		case 93:attrset(A_BOLD|COLOR_PAIR(46));break;
		case 94:attrset(A_BOLD|COLOR_PAIR(44));break;
		case 95:attrset(A_BOLD|COLOR_PAIR(48));break;

		case 96:attrset(COLOR_PAIR(49));break;
		case 97:attrset(COLOR_PAIR(53));break;
		case 98:attrset(COLOR_PAIR(51));break;
		case 99:attrset(COLOR_PAIR(55));break;
		case 100:attrset(COLOR_PAIR(50));break;
		case 101:attrset(COLOR_PAIR(54));break;
		case 102:attrset(COLOR_PAIR(52));break;
		case 103:attrset(COLOR_PAIR(56));break;
		case 104:attrset(A_BOLD|COLOR_PAIR(49));break;
		case 105:attrset(A_BOLD|COLOR_PAIR(53));break;
		case 106:attrset(A_BOLD|COLOR_PAIR(51));break;
		case 107:attrset(A_BOLD|COLOR_PAIR(55));break;
		case 108:attrset(A_BOLD|COLOR_PAIR(50));break;
		case 109:attrset(A_BOLD|COLOR_PAIR(54));break;
		case 110:attrset(A_BOLD|COLOR_PAIR(52));break;
		case 111:attrset(A_BOLD|COLOR_PAIR(56));break;

		case 112:attrset(COLOR_PAIR(57));break;
		case 113:attrset(COLOR_PAIR(61));break;
		case 114:attrset(COLOR_PAIR(59));break;
		case 115:attrset(COLOR_PAIR(63));break;
		case 116:attrset(COLOR_PAIR(58));break;
		case 117:attrset(COLOR_PAIR(62));break;
		case 118:attrset(COLOR_PAIR(60));break;
		case 119:attrset(COLOR_PAIR(64));break;
		case 120:attrset(A_BOLD|COLOR_PAIR(57));break;
		case 121:attrset(A_BOLD|COLOR_PAIR(61));break;
		case 122:attrset(A_BOLD|COLOR_PAIR(59));break;
		case 123:attrset(A_BOLD|COLOR_PAIR(63));break;
		case 124:attrset(A_BOLD|COLOR_PAIR(58));break;
		case 125:attrset(A_BOLD|COLOR_PAIR(62));break;
		case 126:attrset(A_BOLD|COLOR_PAIR(60));break;
		case 127:attrset(A_BOLD|COLOR_PAIR(64));break;

		default:attrset(COLOR_PAIR(8)); 
	}
}
コード例 #23
0
ファイル: ins_wide.c プロジェクト: ysleu/RTL8685
static void
test_inserts(int level)
{
    static bool first = TRUE;

    int ch;
    int limit;
    int row = 1;
    int col;
    int row2, col2;
    int length;
    wchar_t buffer[BUFSIZ];
    WINDOW *look = 0;
    WINDOW *work = 0;
    WINDOW *show = 0;
    int margin = (2 * MY_TABSIZE) - 1;
    Options option = ((m_opt ? oMove : oDefault)
		      | ((w_opt || (level > 0)) ? oWindow : oDefault));

    if (first) {
	static char cmd[80];
	setlocale(LC_ALL, "");

	putenv(strcpy(cmd, "TABSIZE=8"));

	initscr();
	(void) cbreak();	/* take input chars one at a time, no wait for \n */
	(void) noecho();	/* don't echo input */
	keypad(stdscr, TRUE);
    }

    limit = LINES - 5;
    if (level > 0) {
	look = newwin(limit, COLS - (2 * (level - 1)), 0, level - 1);
	work = newwin(limit - 2, COLS - (2 * level), 1, level);
	show = newwin(4, COLS, limit + 1, 0);
	box(look, 0, 0);
	wnoutrefresh(look);
	limit -= 2;
    } else {
	work = stdscr;
	show = derwin(stdscr, 4, COLS, limit + 1, 0);
    }
    keypad(work, TRUE);

    for (col = margin + 1; col < COLS; col += MY_TABSIZE)
	MvWVLine(work, row, col, '.', limit - 2);

    MvWVLine(work, row, margin, ACS_VLINE, limit - 2);
    MvWVLine(work, row, margin + 1, ACS_VLINE, limit - 2);
    limit /= 2;

    MvWAddStr(work, 1, 2, "String");
    MvWAddStr(work, limit + 1, 2, "Chars");
    wnoutrefresh(work);

    buffer[length = 0] = '\0';
    legend(show, level, option, buffer, length);
    wnoutrefresh(show);

    doupdate();

    /*
     * Show the characters inserted in color, to distinguish from those that
     * are shifted.
     */
    if (has_colors()) {
	start_color();
	init_pair(1, COLOR_WHITE, COLOR_BLUE);
	wbkgdset(work, COLOR_PAIR(1) | ' ');
    }

    while ((ch = read_linedata(work)) != ERR && !isQUIT(ch)) {
	wmove(work, row, margin + 1);
	switch (ch) {
	case key_RECUR:
	    test_inserts(level + 1);

	    touchwin(look);
	    touchwin(work);
	    touchwin(show);

	    wnoutrefresh(look);
	    wnoutrefresh(work);
	    wnoutrefresh(show);

	    doupdate();
	    break;
	case key_NEWLINE:
	    if (row < limit) {
		++row;
		/* put the whole string in, all at once */
		col2 = margin + 1;
		switch (option) {
		case oDefault:
		    if (n_opt > 1) {
			for (col = 0; col < length; col += n_opt) {
			    col2 = ColOf(buffer, col, margin);
			    if (move(row, col2) != ERR) {
				InsNStr(buffer + col, LEN(col));
			    }
			}
		    } else {
			if (move(row, col2) != ERR) {
			    InsStr(buffer);
			}
		    }
		    break;
		case oMove:
		    if (n_opt > 1) {
			for (col = 0; col < length; col += n_opt) {
			    col2 = ColOf(buffer, col, margin);
			    MvInsNStr(row, col2, buffer + col, LEN(col));
			}
		    } else {
			MvInsStr(row, col2, buffer);
		    }
		    break;
		case oWindow:
		    if (n_opt > 1) {
			for (col = 0; col < length; col += n_opt) {
			    col2 = ColOf(buffer, col, margin);
			    if (wmove(work, row, col2) != ERR) {
				WInsNStr(work, buffer + col, LEN(col));
			    }
			}
		    } else {
			if (wmove(work, row, col2) != ERR) {
			    WInsStr(work, buffer);
			}
		    }
		    break;
		case oMoveWindow:
		    if (n_opt > 1) {
			for (col = 0; col < length; col += n_opt) {
			    col2 = ColOf(buffer, col, margin);
			    MvWInsNStr(work, row, col2, buffer + col, LEN(col));
			}
		    } else {
			MvWInsStr(work, row, col2, buffer);
		    }
		    break;
		}

		/* do the corresponding single-character insertion */
		row2 = limit + row;
		for (col = 0; col < length; ++col) {
		    col2 = ColOf(buffer, col, margin);
		    switch (option) {
		    case oDefault:
			if (move(row2, col2) != ERR) {
			    InsCh((chtype) buffer[col]);
			}
			break;
		    case oMove:
			MvInsCh(row2, col2, (chtype) buffer[col]);
			break;
		    case oWindow:
			if (wmove(work, row2, col2) != ERR) {
			    WInsCh(work, (chtype) buffer[col]);
			}
			break;
		    case oMoveWindow:
			MvWInsCh(work, row2, col2, (chtype) buffer[col]);
			break;
		    }
		}
	    } else {
		beep();
	    }
	    break;
	default:
	    buffer[length++] = ch;
	    buffer[length] = '\0';

	    /* put the string in, one character at a time */
	    col = ColOf(buffer, length - 1, margin);
	    switch (option) {
	    case oDefault:
		if (move(row, col) != ERR) {
		    InsStr(buffer + length - 1);
		}
		break;
	    case oMove:
		MvInsStr(row, col, buffer + length - 1);
		break;
	    case oWindow:
		if (wmove(work, row, col) != ERR) {
		    WInsStr(work, buffer + length - 1);
		}
		break;
	    case oMoveWindow:
		MvWInsStr(work, row, col, buffer + length - 1);
		break;
	    }

	    /* do the corresponding single-character insertion */
	    switch (option) {
	    case oDefault:
		if (move(limit + row, col) != ERR) {
		    InsCh((chtype) ch);
		}
		break;
	    case oMove:
		MvInsCh(limit + row, col, (chtype) ch);
		break;
	    case oWindow:
		if (wmove(work, limit + row, col) != ERR) {
		    WInsCh(work, (chtype) ch);
		}
		break;
	    case oMoveWindow:
		MvWInsCh(work, limit + row, col, (chtype) ch);
		break;
	    }

	    wnoutrefresh(work);

	    legend(show, level, option, buffer, length);
	    wnoutrefresh(show);

	    doupdate();
	    break;
	}
    }
    if (level > 0) {
	delwin(show);
	delwin(work);
	delwin(look);
    }
}
コード例 #24
0
ファイル: main.c プロジェクト: lukechampine/toxic
int main(int argc, char *argv[])
{
    char *user_config_dir = get_user_config_dir();
    int config_err = 0;

    f_loadfromfile = 1;
    int f_flag = 0;
    int i = 0;

    for (i = 0; i < argc; ++i) {
        if (argv[i] == NULL)
            break;
        else if (argv[i][0] == '-') {
            if (argv[i][1] == 'f') {
                if (argv[i + 1] != NULL)
                    DATA_FILE = strdup(argv[i + 1]);
                else
                    f_flag = -1;
            } else if (argv[i][1] == 'n') {
                f_loadfromfile = 0;
            }
        }
    }

    config_err = create_user_config_dir(user_config_dir);
    if (DATA_FILE == NULL ) {
        if (config_err) {
            DATA_FILE = strdup("data");
        } else {
            DATA_FILE = malloc(strlen(user_config_dir) + strlen(CONFIGDIR) + strlen("data") + 1);
            if (DATA_FILE != NULL) {
                strcpy(DATA_FILE, user_config_dir);
                strcat(DATA_FILE, CONFIGDIR);
                strcat(DATA_FILE, "data");
            } else {
                endwin();
                fprintf(stderr, "malloc() failed. Aborting...\n");
                exit(EXIT_FAILURE);
            }
        }
    }

    if (config_err) {
        SRVLIST_FILE = strdup(PACKAGE_DATADIR "/DHTservers");
    } else {
        SRVLIST_FILE = malloc(strlen(user_config_dir) + strlen(CONFIGDIR) + strlen("DHTservers") + 1);
        if (SRVLIST_FILE != NULL) {
            strcpy(SRVLIST_FILE, user_config_dir);
            strcat(SRVLIST_FILE, CONFIGDIR);
            strcat(SRVLIST_FILE, "DHTservers");
        } else {
            endwin();
            fprintf(stderr, "malloc() failed. Aborting...\n");
            exit(EXIT_FAILURE);
        }
    }

    free(user_config_dir);

    init_term();
    Tox *m = init_tox();

    if (m == NULL) {
        endwin();
        fprintf(stderr, "Failed to initialize network. Aborting...\n");
        exit(EXIT_FAILURE);
    }

    prompt = init_windows(m);

    if (f_loadfromfile)
        load_data(m, DATA_FILE);

    if (f_flag == -1) {
        attron(COLOR_PAIR(RED) | A_BOLD);
        wprintw(prompt->window, "You passed '-f' without giving an argument.\n"
                "defaulting to 'data' for a keyfile...\n");
        attroff(COLOR_PAIR(RED) | A_BOLD);
    }

    if (config_err) {
        attron(COLOR_PAIR(RED) | A_BOLD);
        wprintw(prompt->window, "Unable to determine configuration directory.\n"
                "defaulting to 'data' for a keyfile...\n");
        attroff(COLOR_PAIR(RED) | A_BOLD);
    }

    prompt_init_statusbar(prompt, m);

    while (true) {
        do_tox(m, prompt);
        do_file_senders(m);
        draw_active_window(m);
    }

    exit_toxic(m);
    return 0;
}
コード例 #25
0
int MessageBox(HWND *dummy, const char *text, const char *caption, UINT type)
{
  bool toggle_screen = false;
  int ret = IDOK;
  if (enabler.is_fullscreen()) {
    enabler.toggle_fullscreen();
    toggle_screen = true;
  }
# ifdef __APPLE__ // Cocoa code
  if (type & MB_YESNO) {
    ret = CocoaAlertPanel(caption, text, "Yes", "No", NULL);
    ret = (ret == 0 ? IDNO : IDYES);
  } else {
    CocoaAlertPanel(caption, text, "OK", NULL, NULL);
  }
# else // GTK code
#  ifdef HAVE_GTK2
  if (getenv("DISPLAY")) {
    // Have X, will dialog
    GtkWidget *dialog = gtk_message_dialog_new(NULL,
                                               GTK_DIALOG_DESTROY_WITH_PARENT,
                                               type & MB_YESNO ?
                                               GTK_MESSAGE_QUESTION :
                                               GTK_MESSAGE_ERROR,
                                               type & MB_YESNO ?
                                               GTK_BUTTONS_YES_NO :
                                               GTK_BUTTONS_OK,
                                               "%s", text);
    gtk_window_set_position((GtkWindow*)dialog, GTK_WIN_POS_CENTER_ALWAYS);
    gtk_window_set_title((GtkWindow*)dialog, caption);
    gint dialog_ret = gtk_dialog_run(GTK_DIALOG(dialog));
    gtk_widget_destroy(dialog);
    while (gtk_events_pending())
      gtk_main_iteration();
    
    if (type & MB_YESNO) {
      switch (dialog_ret) {
      default:
      case GTK_RESPONSE_DELETE_EVENT:
      case GTK_RESPONSE_NO:
        ret = IDNO;
        break;
      case GTK_RESPONSE_YES:
        ret = IDYES;
        break;
      }
    }
  } else {
#  endif //end ifdef HAVE_GTK2
    // Use curses
    init_curses();
    erase();
    gps.force_full_display_count = 1;
    wattrset(*stdscr_p, A_NORMAL | COLOR_PAIR(1));
    
    mvwaddstr(*stdscr_p, 0, 5, caption);
    mvwaddstr(*stdscr_p, 2, 2, text);
    nodelay(*stdscr_p, false);
    if (type & MB_YESNO) {
      mvwaddstr(*stdscr_p, 5, 0, "Press 'y' or 'n'.");
      refresh();
      while (1) {
        char i = wgetch(*stdscr_p);
        if (i == 'y') {
          ret = IDYES;
          break;
        }
        else if (i == 'n') {
          ret = IDNO;
          break;
        }
      }
    }
    else {
      mvwaddstr(*stdscr_p, 5, 0, "Press any key to continue.");
      refresh();
      wgetch(*stdscr_p);
    }
    nodelay(*stdscr_p, -1);
#  ifdef HAVE_GTK2
  }
#  endif
# endif
  
  if (toggle_screen) {
    enabler.toggle_fullscreen();
  }
	
  return ret;
}
コード例 #26
0
ファイル: screen.c プロジェクト: mtsuszycki/whowatch
void scr_clr_set(struct wdgt *w, int n)
{
	wattrset(CWND(w), COLOR_PAIR(n));
}
コード例 #27
0
ファイル: main.c プロジェクト: svilerino/Desarrollo-Tecnica3
void Laberinto(int **mat,int filas,int columnas,int f,int c){
if (f<filas){
	if(f>0){
		if(c>0){
			if(mat[f-1][c-1]==0){
				printw("  >>>  (%i;%i)=%i",(f-1),(c-1),mat[f-1][c-1]);refresh();
				mat[f-1][c-1]=2;
				Laberinto(mat,filas,columnas,(f-1),(c-1));
				mat[f-1][c-1]=0;

			}
		}
		if (mat[f-1][c]==0){
            printw("  >>>  (%i;%i)=%i",(f-1),c,mat[f-1][c]);refresh();
			mat[f-1][c]=2;
			Laberinto(mat,filas,columnas,(f-1),c);
            mat[f-1][c]=0;
		}
		if((c+1)<columnas){
            if(mat[f-1][c+1]==0){
            printw("  >>>  (%i;%i)=%i",(f-1),(c+1),mat[f-1][c+1]);refresh();
			mat[f-1][c+1]=2;
			Laberinto(mat,filas,columnas,(f-1),(c+1));
            mat[f-1][c+1]=0;
            }
		}
	}
	if(c>0){
        if(mat[f][c-1]==0){
            printw("  >>>  (%i;%i)=%i",f,(c-1),mat[f][c-1]);refresh();
			mat[f][c-1]=2;
			Laberinto(mat,filas,columnas,f,(c-1));
            mat[f][c-1]=0;
        }
	}
	if((c+1)<columnas){
        if(mat[f][c+1]==0){
            printw("  >>>  (%i;%i)=%i",f,(c+1),mat[f][c+1]);refresh();
			mat[f][c+1]=2;
			Laberinto(mat,filas,columnas,f,(c+1));
            mat[f][c+1]=0;
        }
	}
    if((f+1)<filas){
        if(c>0){
            if(mat[f+1][c-1]==0){
                printw("  >>>  (%i;%i)=%i",(f+1),(c-1),mat[f+1][c-1]);refresh();
                mat[f+1][c-1]=2;
                Laberinto(mat,filas,columnas,(f+1),(c-1));
                mat[f+1][c-1]=0;
            }
        }
        if(mat[f+1][c]==0){
            printw("  >>>  (%i;%i)=%i",(f+1),c,mat[f+1][c]);refresh();
            mat[f+1][c]=2;
            Laberinto(mat,filas,columnas,(f+1),c);
            mat[f+1][c]=0;
        }
        if((c+1)<columnas){
            if(mat[f+1][c+1]==0){
            printw("  >>>  (%i;%i)=%i",(f+1),(c+1),mat[f+1][c+1]);refresh();
            mat[f+1][c+1]=2;
            Laberinto(mat,filas,columnas,(f+1),(c+1));
            mat[f+1][c+1]=0;
        }
    }
    }
    sleep(2);
    printw("\n<<<(%i,%i)<<<Backtrack!! ==> ",f,c);refresh();
    Mostrar(mat,filas,columnas,f,c);
    sleep(1);


if(f==(filas-1)){
    attron(COLOR_PAIR(5));
    printw("\nSalida >>>(%i;%i)",f,c);refresh();
    sleep(1);
    attroff(COLOR_PAIR(5));
}
}
}
コード例 #28
0
ファイル: newtest.c プロジェクト: EdSchroedinger/PDCurses
/* Among other things,  'newtest' demonstrates how to make a Win32a
PDCurses app that is a for-real,  "pure Windows" version (instead of
a console application).  Doing this is quite easy,  and has certain
advantages.  If the app is invoked from a command prompt,  the only
difference you'll see is that the app runs separately (that is,  you
can continue to use the command prompt,  switching between it,  your
PDCurses/Win32a app,  and other processes).  Which is the main reason
I did it;  it meant that I could invoke a PDCurses-based text editor,
for example,  and still have use of the command line.

   (NOTE that,  for reasons I don't actually understand,  this happens
when the Visual C++ compiler is used.  With MinGW or OpenWatcom,  it's
still "really" a console app.)

   To do it,  we ensure that the usual main() function has an alternative
dummy_main() form,  taking the same arguments as main().  We add a
WinMain() function,  whose sole purpose is to reformulate lpszCmdLine
into argc/argv form,  and pass it on to dummy_main().  And,  of course,
we can switch back to a "normal" console app by removing the above
#define PURE_WINDOWS_VERSION line.             */

#ifdef PURE_WINDOWS_VERSION
#undef MOUSE_MOVED
#include <windows.h>

int dummy_main( int argc, char **argv);

int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    LPSTR lpszCmdLine, int nCmdShow)
{
   char *argv[30];
   int i, argc = 1;

   argv[0] = "newtest";
   for( i = 0; lpszCmdLine[i]; i++)
       if( lpszCmdLine[i] != ' ' && (!i || lpszCmdLine[i - 1] == ' '))
          argv[argc++] = lpszCmdLine + i;

   for( i = 0; lpszCmdLine[i]; i++)
       if( lpszCmdLine[i] == ' ')
          lpszCmdLine[i] = '\0';

   return dummy_main( argc, (char **)argv);
}

int dummy_main( int argc, char **argv)
#else       /* "usual",  console-app version: */
int main( int argc, char **argv)
#endif
{
    int quit = 0, i,  use_slk = 1;
    int fmt = 0xa;
    bool blink_state = FALSE;
    int cursor_state_1 = 2, cursor_state_2 = 3;
    int show_slk_index_line = 0;
    int redraw = 1;
    unsigned extra_character_to_show = 0;
#ifdef PDC_WIDE
    unsigned unicode_offset = 0x80;
#endif

/*  setlocale(LC_ALL, ".utf8");     */
    ttytype[0] = 25;   ttytype[1] = 90;         /* Allow 25 to 90 lines... */
    ttytype[2] = 80;   ttytype[3] = (char)200;  /* ...and 80 to 200 columns */
         /* (This program gets weird artifacts when smaller than 25x80.) */
    for( i = 1; i < argc; i++)
        if( argv[i][0] == '-')
            switch( argv[i][1])
            {
                case 's':
                    use_slk = 0;
                    break;
                case 'l':
                    setlocale( LC_ALL, argv[i] + 2);
                    break;
                case 'e':
                    sscanf( argv[i] + 2, "%x", &extra_character_to_show);
                    break;
                case 'f':
                    sscanf( argv[i] + 2, "%x", (unsigned *)&fmt);
                    break;
                case 'i':
                    show_slk_index_line = 1;
                    break;
                case 'r':     /* allow user-resizable windows */
                    {
                        int min_lines, max_lines, min_cols, max_cols;

                        if( sscanf( argv[i] + 2, "%d,%d,%d,%d",
                                       &min_lines, &max_lines,
                                       &min_cols, &max_cols) == 4)
                        {
                            ttytype[0] = min_lines;
                            ttytype[1] = max_lines;
                            ttytype[2] = min_cols;
                            ttytype[3] = max_cols;
                        }
                    }
                    break;
                case 'd':     /* set window size before initscr */
                    {
                        int n_lines, n_cols;

                        if( sscanf( argv[i] + 2, "%d,%d", &n_lines,
                                    &n_cols) == 2)
                            resize_term( n_lines, n_cols);
                    }
                    break;
#ifdef PDC_WIDE
                case 'u':
                    sscanf( argv[i] + 2, "%x", &unicode_offset);
                    break;
#endif
                default:
                    printf( "Option '%s' unrecognized\n", argv[i]);
                    break;
            }
    if( use_slk)
       slk_init( show_slk_index_line ? 3 : 0);
    Xinitscr(argc, argv);
    if( use_slk)
       slk_setup( show_slk_index_line ? -fmt : fmt);

    start_color();

# if defined(NCURSES_VERSION) || (defined(PDC_BUILD) && PDC_BUILD > 3000)
    use_default_colors();
# endif
    cbreak();
    noecho();
    clear();
    refresh();
#ifdef __PDCURSES__
    PDC_set_title( "NewTest: tests various PDCurses features");
#endif
    keypad( stdscr, TRUE);
    init_pair( 1, 15, COLOR_BLACK);
    init_pair( 2, COLOR_BLACK, COLOR_YELLOW);

    mousemask( ALL_MOUSE_EVENTS, NULL);
    attrset( COLOR_PAIR( 1));
    while( !quit)
    {
        char buff[80];
        const int xmax = getmaxx( stdscr);
        const int ymax = getmaxy( stdscr);
        int color_block_start = 54, c;
        int color_block_cols = (xmax - color_block_start) / 2;
        const int color_block_lines = 19;
        const char *cursor_state_text[N_CURSORS] = {
                  "Invisible (click to change) ",
                  "Underscore (click to change)",
                  "Block (click to change)     ",
                  "Outline (click to change)   ",
                  "Caret (click to change)     ",
                  "Half-block (click to change)",
                  "Central (click to change)   ",
                  "Cross (click to change)     ",
                  "Heavy box (click to change) " };

        if( color_block_cols < 0)
            color_block_cols = 0;
        if( redraw)
        {
            mvaddstr( 1, COL1, "'Normal' white-on-black");
            mvaddstr( 2, COL1, longname( ));
#if(CHTYPE_LONG >= 2)       /* "non-standard" 64-bit chtypes     */
            attron( A_DIM);
            mvaddstr( 15, 41, "Dimmed text");
            attroff( A_DIM);
#endif
#ifdef PDC_WIDE
            mvaddwstr( 3, COL1, L"'Normal' text,  but wide");
#endif
            attron( A_BLINK);
            mvaddstr( 6, 40, "Blinking");
            attron( A_BOLD);
            mvaddstr( 8, 40, "BlinkBold");
            attron( A_ITALIC);
            mvaddstr( 0, COL2, "BlinkBoldItalic");
            attrset( COLOR_PAIR( 3));
            attron( A_UNDERLINE);
#ifdef PDC_WIDE
            mvaddstr( 1, COL2, "Underlined");
            addwstr( L"WideUnder");
#endif
            attrset( COLOR_PAIR( 1));
            attron( A_UNDERLINE | A_ITALIC);
            mvaddstr( 2, COL2, "UnderlinedItalic");
            attrset( COLOR_PAIR( 2));
            attron( A_BLINK);
            mvaddstr( 4, COL1, "Black-on-yellow blinking");

            attrset( COLOR_PAIR( 1));
            move( 4, COL2);
            text_in_a_box( "Text in a box");

#ifdef CHTYPE_LONG
            attrset( COLOR_PAIR( 6));
            attron( A_STRIKEOUT);
            mvaddstr( 10, 40, "Strikeout");
            attrset( COLOR_PAIR( 1));
#endif

#ifdef PDC_WIDE
            move( 11, 40);
            text_in_a_box( "Next Ucode pg");
            if( unicode_offset)
               {
               move( 12, 40);
               text_in_a_box( "Prev Ucode pg");
               }
            mvprintw( 13, 40, "U+%04x ", unicode_offset);

#endif

            for( i = 0; i < 128; i++)
            {                 /* Show extended characters: */
#ifdef PDC_WIDE
                wchar_t buff[20];

                swprintf( buff, 20, L"%02x ",
                           (unsigned)( i + unicode_offset) & 0xff);
                mvaddwstr( 5 + i % 16, (i / 16) * 5, buff);
                if( i + unicode_offset > ' ')
                   addch( (chtype)( i + unicode_offset));
                else
                   addch( ' ');
                addch( ' ');
#else
                char buff[6];

                sprintf( buff, "%02x %c", i + 128, (char)(i + 128));
                mvaddstr( 5 + i % 16, (i / 16) * 5, buff);
#endif
            }

#if(CHTYPE_LONG >= 2)       /* "non-standard" 64-bit chtypes     */
            for( i = 0; i < 3 && i + 21 < ymax; i++)
            {                 /* Demonstrate full RGB color control: */
                int j;
                const char *output_text[3] = {
                    "Red on green to white on black   | (you can get full RGB colors when desired,",
                    "Blue on yellow to black on red | with palette coloring still being available)",
                    "White on red to green on blue,  underlined and italic" };
                const int len = (int)strlen( output_text[i]);

                move( 21 + i, 1);
                for( j = 0; j < len && j + 1 < xmax; j++)
                {
                    attr_t output_color;
                    const int oval = j * 31 / len;
                    const int reverse = 31 - oval;

                    if( !i)
                        output_color = A_RGB( 31, oval, oval, 0, reverse, 0);
                    else if( i == 1)
                        output_color = A_RGB( 0, 0, reverse, 31, reverse, 0);
                    else
                    {
                        output_color = A_RGB( reverse, 31, reverse,
                               reverse, 0, oval);
                        output_color |= A_UNDERLINE | A_ITALIC;
                    }
                    attrset( output_color);
                    addch( output_text[i][j]);
                }
            }
#endif         /* #if(CHTYPE_LONG >= 2) */
            redraw = 0;
            attrset( COLOR_PAIR( 1));
            if( extra_character_to_show && ymax > 23)
                mvaddch( 23, 63, (chtype)extra_character_to_show);

#ifdef PDC_WIDE
            for( i = 0; i < 6; i++)
            {
                static const wchar_t spanish[] = L"Espa\xf1ol";
                const int line = 24 + i / 3;
                const int col = 5 + 25 * (i % 3);

                static const wchar_t russian[] = {0x0420, 0x0443, 0x0441, 0x0441,
                   0x043a, 0x0438, 0x0439, L' ', 0x044f, 0x0437, 0x044b, 0x043a, 0};

                static const wchar_t greek[] = {0x0395, 0x03bb, 0x03bb, 0x03b7,
                   0x03bd, 0x03b9, 0x03ba, 0x03ac, 0};

                static const wchar_t georgian[] = {0x10e5, 0x10d0, 0x10e0, 0x10d7,
                   0x10e3, 0x10da, 0x10d8, L' ', 0x10d4, 0x10dc, 0x10d0, 0};

                static const wchar_t fullwidth[] = { 0xff26, 0xff55, 0xff4c, 0xff4c,
                   0xff57, 0xff49, 0xff44, 0xff54, 0xff48, 0 };  /* "Fullwidth" */

                static const wchar_t combining_marks[] = { L'C', L'o', 0x35c, L'm',
                   L'b', 0x30a, L'i', L'n', L'i', 0x304, L'n', 0x30b, 0x329,
                   L'g', 0x310,
                   L' ', L'C', 0x338, L'h', 0x306,  L'a', 0x361, L'r', L's',
                   0x30e, 0x348, 0 };

                static const wchar_t *texts[6] = { spanish, russian, greek,
                                georgian, fullwidth, combining_marks};

                if( line < ymax && col < xmax)
                   mvaddnwstr( line, 5 + 25 * (i % 3), texts[i], xmax - col);
            }
#endif

#ifdef MAYBE_TRY_THIS_SOMEWHERE_ELSE
        mvaddstr(  1, COL3, "Click on cursor descriptions to");
        mvaddstr(  2, COL3, "cycle through possible cursors");
        mvaddstr(  3, COL3, "Click on colors at left to change");
        mvaddstr(  4, COL3, "colors used for under/over/outlining");
        mvaddstr(  5, COL3, "Click 'Blink' at bottom to toggle");
        mvaddstr(  6, COL3, "'real' blinking vs. 'highlit' blink");
#endif
        }

        mvaddnstr( 19, color_block_start, cursor_state_text[cursor_state_1],
                                 xmax - color_block_start);
        mvaddnstr( 20, color_block_start, cursor_state_text[cursor_state_2],
                                 xmax - color_block_start);
        curs_set( (cursor_state_1 << 8) | cursor_state_2);
        for( i = 0; i < color_block_cols * color_block_lines; i++)
        {
            const int n_color_blocks = (COLOR_PAIRS < 256 ? COLOR_PAIRS : 256);

            attrset( COLOR_PAIR( i >= n_color_blocks ? 2 : i));
            if( i > 2 && i < n_color_blocks)
               init_pair((short)i, (short)i, COLOR_BLACK);
            if( !(i % color_block_cols))
               move( i / color_block_cols, color_block_start);
            attron( A_REVERSE);
            addstr( "  ");
        }
        move( 19, color_block_start - 3);
        refresh();
        c = getch( );
        attrset( COLOR_PAIR( 1));
        if( c == KEY_RESIZE)
        {
            redraw = 1;
            resize_term( 0, 0);
        }
        else if( c == KEY_F(1) || c == 27)
            quit = 1;
        else if( c == KEY_F(2))
        {
            blink_state ^= 1;
            PDC_set_blink( blink_state);
        }
        else if( c == KEY_F(3))   /* toggle SLKs */
        {
            use_slk ^= 1;
            if( use_slk)
                slk_restore( );
            else
                slk_clear( );
        }
        else if( c >= KEY_F(4) && c < KEY_F(12))
        {
            sscanf( labels[c - KEY_F(1)], "%x", (unsigned *)&fmt);
            if( use_slk)
                slk_setup( show_slk_index_line ? -fmt : fmt);
        }
        if( c != KEY_MOUSE)
        {
            sprintf( buff, "Key %s", keyname( c));
            if( !memcmp( buff + 4, "UNKNOWN", 7))
                sprintf( buff + 11, " (%x)", c);
            strcat( buff, " hit                 ");
            buff[COL2 - COL1] = '\0';
            mvaddstr( 0, COL1, buff);
        }
        else
        {
            MEVENT mouse_event;
#ifdef __PDCURSES__
            nc_getmouse( &mouse_event);
#else
            getmouse( &mouse_event);
#endif
            sprintf( buff, "Mouse at %d x %d: %x  ", mouse_event.x,
                              mouse_event.y, (unsigned)mouse_event.bstate);
            mvaddstr( 0, COL1, buff);
            if( mouse_event.x >= color_block_start
                            && mouse_event.y < color_block_lines)
            {
                int new_color = (mouse_event.x - color_block_start) / 2
                              + mouse_event.y * color_block_cols;

                if( new_color >= 256)
                    new_color = -1;
                PDC_set_line_color( (short)new_color);
            }
            else if( mouse_event.x >= color_block_start)
            {
                int shift = ((mouse_event.bstate & BUTTON_MODIFIER_SHIFT) ?
                           N_CURSORS - 1 : 1);

                if( mouse_event.y == 19)  /* blink/non-blink toggle */
                    cursor_state_1 = (cursor_state_1 + shift) % N_CURSORS;
                else if( mouse_event.y == 20)  /* cycle cursor state */
                    cursor_state_2 = (cursor_state_2 + shift) % N_CURSORS;
            }
#ifdef PDC_WIDE
            else if( mouse_event.x >= 40 && mouse_event.x < 40 + 10)
               {
               if( mouse_event.y == 11)
                  {
                  redraw = 1;
                  unicode_offset += 0x80;
                  }
               else if( mouse_event.y == 12 && unicode_offset)
                  {
                  redraw = 1;
                  unicode_offset -= 0x80;
                  }
               }
#endif
        }
    }

    endwin();

    return 0;
}
コード例 #29
0
ファイル: theme.c プロジェクト: demonking/profanity
int
theme_attrs(theme_item_t attrs)
{
    int result = 0;

    switch (attrs) {
    case THEME_TEXT:                    result = COLOR_PAIR(1); break;
    case THEME_TEXT_ME:                 result = COLOR_PAIR(2); break;
    case THEME_TEXT_THEM:               result = COLOR_PAIR(3); break;
    case THEME_SPLASH:                  result = COLOR_PAIR(4); break;
    case THEME_ERROR:                   result = COLOR_PAIR(5); break;
    case THEME_INCOMING:                result = COLOR_PAIR(6); break;
    case THEME_INPUT_TEXT:              result = COLOR_PAIR(7); break;
    case THEME_TIME:                    result = COLOR_PAIR(8); break;
    case THEME_TITLE_TEXT:              result = COLOR_PAIR(9); break;
    case THEME_TITLE_BRACKET:           result = COLOR_PAIR(10); break;
    case THEME_TITLE_UNENCRYPTED:       result = COLOR_PAIR(11); break;
    case THEME_TITLE_ENCRYPTED:         result = COLOR_PAIR(12); break;
    case THEME_TITLE_UNTRUSTED:         result = COLOR_PAIR(13); break;
    case THEME_TITLE_TRUSTED:           result = COLOR_PAIR(14); break;
    case THEME_TITLE_ONLINE:            result = COLOR_PAIR(15); break;
    case THEME_TITLE_OFFLINE:           result = COLOR_PAIR(16); break;
    case THEME_TITLE_AWAY:              result = COLOR_PAIR(17); break;
    case THEME_TITLE_CHAT:              result = COLOR_PAIR(18); break;
    case THEME_TITLE_DND:               result = COLOR_PAIR(19); break;
    case THEME_TITLE_XA:                result = COLOR_PAIR(20); break;
    case THEME_STATUS_TEXT:             result = COLOR_PAIR(21); break;
    case THEME_STATUS_BRACKET:          result = COLOR_PAIR(22); break;
    case THEME_STATUS_ACTIVE:           result = COLOR_PAIR(23); break;
    case THEME_STATUS_NEW:              result = COLOR_PAIR(24); break;
    case THEME_ME:                      result = COLOR_PAIR(25); break;
    case THEME_THEM:                    result = COLOR_PAIR(26); break;
    case THEME_RECEIPT_SENT:            result = COLOR_PAIR(27); break;
    case THEME_ROOMINFO:                result = COLOR_PAIR(28); break;
    case THEME_ROOMMENTION:             result = COLOR_PAIR(29); break;
    case THEME_ONLINE:                  result = COLOR_PAIR(30); break;
    case THEME_OFFLINE:                 result = COLOR_PAIR(31); break;
    case THEME_AWAY:                    result = COLOR_PAIR(32); break;
    case THEME_CHAT:                    result = COLOR_PAIR(33); break;
    case THEME_DND:                     result = COLOR_PAIR(34); break;
    case THEME_XA:                      result = COLOR_PAIR(35); break;
    case THEME_TYPING:                  result = COLOR_PAIR(36); break;
    case THEME_GONE:                    result = COLOR_PAIR(37); break;
    case THEME_SUBSCRIBED:              result = COLOR_PAIR(38); break;
    case THEME_UNSUBSCRIBED:            result = COLOR_PAIR(39); break;
    case THEME_OTR_STARTED_TRUSTED:     result = COLOR_PAIR(40); break;
    case THEME_OTR_STARTED_UNTRUSTED:   result = COLOR_PAIR(41); break;
    case THEME_OTR_ENDED:               result = COLOR_PAIR(42); break;
    case THEME_OTR_TRUSTED:             result = COLOR_PAIR(43); break;
    case THEME_OTR_UNTRUSTED:           result = COLOR_PAIR(44); break;
    case THEME_ROSTER_HEADER:           result = COLOR_PAIR(45); break;
    case THEME_OCCUPANTS_HEADER:        result = COLOR_PAIR(46); break;
    case THEME_WHITE:                   result = COLOR_PAIR(47); break;
    case THEME_WHITE_BOLD:              result = COLOR_PAIR(47); break;
    case THEME_GREEN:                   result = COLOR_PAIR(48); break;
    case THEME_GREEN_BOLD:              result = COLOR_PAIR(48); break;
    case THEME_RED:                     result = COLOR_PAIR(49); break;
    case THEME_RED_BOLD:                result = COLOR_PAIR(49); break;
    case THEME_YELLOW:                  result = COLOR_PAIR(50); break;
    case THEME_YELLOW_BOLD:             result = COLOR_PAIR(50); break;
    case THEME_BLUE:                    result = COLOR_PAIR(51); break;
    case THEME_BLUE_BOLD:               result = COLOR_PAIR(51); break;
    case THEME_CYAN:                    result = COLOR_PAIR(52); break;
    case THEME_CYAN_BOLD:               result = COLOR_PAIR(52); break;
    case THEME_BLACK:                   result = COLOR_PAIR(53); break;
    case THEME_BLACK_BOLD:              result = COLOR_PAIR(53); break;
    case THEME_MAGENTA:                 result = COLOR_PAIR(54); break;
    case THEME_MAGENTA_BOLD:            result = COLOR_PAIR(54); break;
    default:                            break;
    }

    if (g_hash_table_lookup(bold_items, GINT_TO_POINTER(attrs))) {
        return result | A_BOLD;
    } else {
        return result;

    }
}
コード例 #30
0
ファイル: App.cpp プロジェクト: Laizerox/TheLife
int TheLife::KeyHandle(int key, int keycolor) {

    int width, height, i;
    CommandHandler *Command;
    
    width = sUI->GetX(WINDOW_CONSOLE) - 1;
    height = 1;

    Debug(sLanguage->Get("DEBUG_KEY_HANDLE").c_str(), key);

    switch (key) {
        case KEY_LEFT:
            if (sUI->lwin[WINDOW_CONSOLE].field_ptr > 0)
                sUI->lwin[WINDOW_CONSOLE].field_ptr--;
            break;
        case KEY_RIGHT:
            if (sUI->lwin[WINDOW_CONSOLE].field_ptr < sUI->lwin[WINDOW_CONSOLE].field_length)
                sUI->lwin[WINDOW_CONSOLE].field_ptr++;
            break;
        case KEY_BACKSPACE:
        case 127:
            if (sUI->lwin[WINDOW_CONSOLE].field_ptr > 0) {
                sUI->lwin[WINDOW_CONSOLE].field_ptr--;
                sUI->lwin[WINDOW_CONSOLE].field_length--;
                for (i = sUI->lwin[WINDOW_CONSOLE].field_ptr; i < sUI->lwin[WINDOW_CONSOLE].field_length; i++)
                    sUI->lwin[WINDOW_CONSOLE].field_buf[i] = sUI->lwin[WINDOW_CONSOLE].field_buf[i + 1];
                sUI->lwin[WINDOW_CONSOLE].field_buf[i] = 0x00;
            }
            break;
        case '\n':
        case '\r':
            if (sUI->lwin[WINDOW_CONSOLE].field_buf[0] == 0x00)
               break;

            wattron(sUI->GetConsole(WINDOW_CONSOLE, 0), COLOR_PAIR(keycolor));
            Command->CommandProcess(sUI->lwin[WINDOW_CONSOLE].field_buf);
            wattroff(sUI->GetConsole(WINDOW_CONSOLE, 0), COLOR_PAIR(keycolor));

            sUI->lwin[WINDOW_CONSOLE].field_buf[0] = 0x00;
            sUI->lwin[WINDOW_CONSOLE].field_ptr = 0x00;
            sUI->lwin[WINDOW_CONSOLE].field_length = 0x00;
            werase(sUI->GetConsole(WINDOW_CONSOLE, 1));
            break;
        case -1:
        case KEY_RESIZE:
        case KEY_UP:
        case KEY_DOWN:
            return -1;
            break;
        default:
            if (sUI->lwin[WINDOW_CONSOLE].field_length >= FIELDBUFSIZE - 1)
                return -1;

            for (i = sUI->lwin[WINDOW_CONSOLE].field_length; i > sUI->lwin[WINDOW_CONSOLE].field_ptr && i > 0; i--)
                sUI->lwin[WINDOW_CONSOLE].field_buf[i] = sUI->lwin[WINDOW_CONSOLE].field_buf[i - 1];

            sUI->lwin[WINDOW_CONSOLE].field_buf[sUI->lwin[WINDOW_CONSOLE].field_ptr] = key;
            sUI->lwin[WINDOW_CONSOLE].field_buf[sUI->lwin[WINDOW_CONSOLE].field_length + 1] = 0x00;
            sUI->lwin[WINDOW_CONSOLE].field_ptr++;
            sUI->lwin[WINDOW_CONSOLE].field_length++;
            break;
        }
        Interface::ConsoleBuffer(sUI->GetConsole(WINDOW_CONSOLE, 1), sUI->lwin[WINDOW_CONSOLE].field_buf, height, width, sUI->lwin[WINDOW_CONSOLE].field_ptr);
        wrefresh(sUI->GetConsole(WINDOW_CONSOLE, 1));
        return 0;
}