#include <ncurses.h>

#define ctrl(x) (x & 0x1F) // Detection of ctrl+x presses please do not forget that in unix ctrl+c and ctrl+z are special commands. 


int main(int argv, char ** argc)
{
	//Init Ncurses
	initscr(); 
	noecho(); 
	cbreak(); 

	if(has_colors() == FALSE) 
	{
		printf("Colors cnat be used in this terminal\n"); 
		endwin();
	}	
	
	start_color(); 

	init_pair(1, COLOR_YELLOW, COLOR_BLACK); 
	init_pair(2, COLOR_RED, COLOR_BLACK); 
	init_pair(3, COLOR_BLUE, COLOR_WHITE);	

	// You can cumulate attributes in this speacil variable
	attr_t emphasis =  A_REVERSE | COLOR_PAIR(1);
	attr_t console = A_REVERSE | COLOR_PAIR(3); 
	// Hee is the example use case if that given variable
	attron(emphasis);
	mvprintw(1,0,"emphasis with reversed color pair 1");
	attroff(emphasis); 
	
	char c; 
	//Nwo if we want to create a char with attirbites on it ? 
	chtype cht = 'a' | A_UNDERLINE | COLOR_PAIR(2);	

	attron(console);
	mvprintw(4,0,"Every char for ncurses is a chtype");
	attroff(console);
	mvaddch(5,0,cht);

	while(c = getch())
	{
		attron(console);
		mvprintw(10,0,"KEY Name : %s - 0x%02x\n", keyname(c), c);
		if(c == ctrl('a')) 
		{
			mvprintw(9,0,"ctrl-a detected"); 
		}
	}
	
	endwin();	
}
