Exemplo n.º 1
0
int main(int argc, char *argv[]) {
int right[4], guess[4], backup[4];
int halfrights,rights;
int tmp,i;
int tries = 3;
int maxtries;
int place,color;
int x,y;
char charbuffer[10];
char question[2];
int pplace[4];
pplace[0] = 13;
pplace[1] = 15;
pplace[2] = 17;
pplace[3] = 19;

halfrights=rights=0;

srand(time(0));

printf("Can two places be the same color? (y/n) ");
scanf("%s",charbuffer);
strcpy(question,"n");
if (strcmp(charbuffer,question) == 0) {
	for (i=0;i<4;i++) {
		BACK:
		right[i] = (8.0*rand()/RAND_MAX+1.0);
		for (tmp=0;tmp<4;tmp++) {
			if (right[i] == right[tmp] && i != tmp) {
				goto BACK;
			}
		}
		guess[i] = 0;
	}
} else {
	for (i=0;i<4;i++) {
		right[i] = (8.0*rand()/RAND_MAX+1.0);
		guess[i] = 0;
	}
}


for (i=0;i<4;i++) {
	backup[i] = right[i];
}

printf("How many tries would you like? ");
scanf("%i",&maxtries);
printf("\n");
if (maxtries <= 0) {
printf("Ok, fine.\n");
return 1;
}

printf("\nI have come up with a color combination. Press enter to start the game.\n");

getchar();
getchar();

initscr();
start_color();

getmaxyx(stdscr,y,x);

if (y < 22) {
	endwin();
	printf("Terminal too small\n");
	return 1;
}

if (maxtries > (x/3-3)) {
endwin();
printf("You have too many tries to be on the screen.\n");
return 1;
}

/* Color definations: */
init_pair(1, COLOR_WHITE, COLOR_RED);
init_pair(2, COLOR_WHITE, COLOR_GREEN);
init_pair(3, COLOR_WHITE, COLOR_BLUE);
init_pair(4, COLOR_WHITE, COLOR_BLACK);
init_pair(5, COLOR_WHITE, COLOR_MAGENTA);
init_pair(6, COLOR_BLACK, COLOR_WHITE);
init_pair(7, COLOR_WHITE, COLOR_CYAN);
init_pair(8, COLOR_WHITE, COLOR_YELLOW);


mvprintw(5,0,"Colors: 1: Red, 2: Green, 3: Blue, 4: Black");
mvprintw(6,0,"Colors: 5: Magenta, 6: White, 7: Cyan, 8: Yellow");

mvprintw(8,0,"Right colors on right places:");
mvprintw(10,0,"Right colors on wrong places:");

mvprintw(pplace[0],0,"1:");
mvprintw(pplace[1],0,"2:");
mvprintw(pplace[2],0,"3:");
mvprintw(pplace[3],0,"4:");

mvprintw(0,x/2-10,"Tries left: %i ",maxtries);

GETPLACE:
mvprintw(0,0,"Place:");
mvprintw(1,2," ");
mvprintw(1,0,"? ");
scanw("%i",&place);
if (place < 1 || place > 4) { /* if the user types too many */
	for (i=2;i<=x;i++) {  /* cifers, we want to clean it up */
	mvprintw(1,i," ");
	}
goto GETPLACE;
}
GETCOLOR:
mvprintw(0,0,"Color:");
mvprintw(1,2," ");
move(1,2);
scanw("%i",&color);
if (color < 1 || color > 8) { /* same here */
	for (i=2;i<=x;i++) {
	mvprintw(1,i," ");
	}
goto GETCOLOR;
}

attrset(COLOR_PAIR(color));

mvprintw(pplace[place-1],tries,"%i",color);

attrset(A_NORMAL);

guess[place-1] = color;

tmp = 1;
for (i=0;i<4;i++) {
	if (guess[i] == 0) {
	tmp = 0;	
	}
}

if (tmp) { /* All fields are filled */
	mvprintw(pplace[3]+2,4,"Is that a guess? (y/n) ");
	refresh();
	scanw("%s",charbuffer);
	strcpy(question,"y");
	for (i=4;i<=x;i++) {
		mvprintw(pplace[3]+2,i," ");
	}

	if (strcmp(charbuffer,question) == 0) {
		for (i=0;i<4;i++) {
			if (right[i] == guess[i]) {  /* Finds out how many right colors on right places */
				rights++;	     /* the user has placed. */
				right[i] = guess[i] = 0; /* This line makes sure this guess is not counted again */
			}
		}
		for (i=0;i<4;i++) {
			for (tmp=0;tmp<4;tmp++) {

				if (guess[tmp] == right[i] && right[i] != 0) {
					halfrights++;
					guess[tmp] = right[i] = 0; /* This line makes sure this guess is not counted again */
				}

			}
		}

		if (rights == 4) {
			endwin();
			printf("CONGRATULATIONS!\n");
			printf("You guessed the right combination!\n");
			printf("You used %i tries\n", tries/3);

			return 0;
		}
	
		for (i=0;i<4;i++) {
			right[i] = backup[i];  /* We deleted the right[] array, we have to get it back for next check */
		}


		mvprintw(9,tries,"%i",rights);
		mvprintw(11,tries,"%i",halfrights);
		

		halfrights=rights=0;
		for (i=0;i<4;i++) {
			guess[i] = 0;
		}
		tries = tries+3;
		maxtries--;
		mvprintw(0,x/2-10,"Tries left: %i ",maxtries);
		if (maxtries == 0) {
			for (i=0;i<4;i++) {
				attrset(COLOR_PAIR(right[i]));

				mvprintw(pplace[i],0,"%i",right[i]);

				attrset(A_NORMAL);

			}
			mvprintw(y-2,0,"Wrong, and you are out of tries..\n");
			printw("Press enter to end program");
			refresh();
			getchar();
			endwin();
			return 1;
		}
	}
}


goto GETPLACE;

endwin();
return 0;
}
Exemplo n.º 2
0
int
optionsEditor(dialogMenuItem *self)
{
    int i, optcol, optrow, key;
    static int currOpt = 0;

    dialog_clear_norefresh();
    clear();

    while (1) {
	/* Whap up the header */
	attrset(A_REVERSE); mvaddstr(0, 0, "Options Editor"); attrset(A_NORMAL);
	for (i = 0; i < 2; i++) {
	    mvaddstr(OPT_START_ROW - 2, OPT_NAME_COL + (i * GROUP_OFFSET), "Name");
	    mvaddstr(OPT_START_ROW - 1, OPT_NAME_COL + (i * GROUP_OFFSET), "----");

	    mvaddstr(OPT_START_ROW - 2, OPT_VALUE_COL + (i * GROUP_OFFSET), "Value");
	    mvaddstr(OPT_START_ROW - 1, OPT_VALUE_COL + (i * GROUP_OFFSET), "-----");
	}
	/* And the footer */
	mvprintw(OPT_END_ROW + 1, 0, "Use SPACE to select/toggle an option, arrow keys to move,");
	mvprintw(OPT_END_ROW + 2, 0, "? or F1 for more help.  When you're done, type Q to Quit.");

	optrow = OPT_START_ROW;
	optcol = OPT_NAME_COL;
	for (i = 0; Options[i].name; i++) {
	    /* Names are painted somewhat gratuitously each time, but it's easier this way */
	    mvprintw(optrow, OPT_NAME_COL + optcol, Options[i].name);
	    if (currOpt == i)
		attrset(ATTR_SELECTED);
	    mvprintw(optrow++, OPT_VALUE_COL + optcol, value_of(Options[i]));
	    if (currOpt == i)
		attrset(A_NORMAL);
	    if (optrow == OPT_END_ROW) {
		optrow = OPT_START_ROW;
		optcol += GROUP_OFFSET;
	    }
	    clrtoeol();
	}
	attrset(ATTR_TITLE);
	mvaddstr(OPT_END_ROW + 4, 0, Options[currOpt].desc);
	attrset(A_NORMAL);
	clrtoeol();
	move(0, 14);
        refresh();

	/* Start the edit loop */
	key = toupper(getch());
	switch (key) {
	case KEY_F(1):
	case '?':
	    systemDisplayHelp("options");
	    clear();
	    break;

	case '\020':	/* ^P */
	case KEY_UP:
	    if (currOpt)
		--currOpt;
	    else
		for (currOpt = 0; Options[currOpt + 1].name; currOpt++);
	    continue;

	case '\016':	/* ^N */
	case KEY_DOWN:
	    if (Options[currOpt + 1].name)
		++currOpt;
	    else
		currOpt = 0;
	    continue;

	case KEY_HOME:
	    currOpt = 0;
	    continue;

	case KEY_END:
	    while (Options[currOpt + 1].name)
		++currOpt;
	    continue;

	case ' ':
	    if (fire(Options[currOpt]))
	    	clear();
	    continue;

	case '\033':	/* ESC */
	case 'Q':
	    clear();
	    dialog_clear();
	    return DITEM_SUCCESS | DITEM_RESTORE;

	default:
	    beep();
	}
    }
    /* NOTREACHED */
    return DITEM_SUCCESS | DITEM_RESTORE;
}
Exemplo n.º 3
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)); 
	}
}
Exemplo n.º 4
0
void get_color(void)
{
    chtype bold = (rand() % 2) ? A_BOLD : A_NORMAL;
    attrset(COLOR_PAIR(rand() % 8) | bold);
}
Exemplo n.º 5
0
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();
    }
Exemplo n.º 6
0
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();
}
Exemplo n.º 7
0
static void draw_node(node_t *node, void *arg)
{
	int i, *cnt = (int *) arg;

	if (cnt) {
		if (*cnt) {
			int n;
			NEXT_ROW;
			for (n = 1; n < cols; n += 2)
				mvaddch(row, n, ACS_HLINE);
			move(row, 28);
			addch(ACS_VLINE);
			move(row, 54);
			addch(ACS_VLINE);
		}
		(*cnt)++;
	}

	attrset(A_BOLD);
	NEXT_ROW; 
	if (c_nosource)
		putl("%s", node->n_name);
	else
		putl("%s (%s)", node->n_name,
			node->n_from ? node->n_from : "local");

	move(row, 30);
	putl("     Rate         #   %%        Rate         #   %%");
	attroff(A_BOLD);

	move(row, 28);
	addch(ACS_VLINE);
	move(row, 54);
	addch(ACS_VLINE);

	if (c_use_colors)
		attrset(COLOR_PAIR(LAYOUT_LIST) | layout[LAYOUT_LIST].attr);

	for (i = 0; i < node->n_nitems; i++)
		draw_item(node, &node->n_items[i]);

	if (!c_nototal) {
		int rx_maj_prec, tx_maj_prec, rx_min_prec, tx_min_prec;
		double rx_maj, tx_maj, rx_min, tx_min;
		char *rx_maj_u, *tx_maj_u, *rx_min_u, *tx_min_u;
		
		rx_maj = cancel_down(node->n_rx_maj_total, U_BYTES, &rx_maj_u, &rx_maj_prec);
		tx_maj = cancel_down(node->n_tx_maj_total, U_BYTES, &tx_maj_u, &tx_maj_prec);

		rx_min = cancel_down(node->n_rx_min_total, U_NUMBER, &rx_min_u, &rx_min_prec);
		tx_min = cancel_down(node->n_tx_min_total, U_NUMBER, &tx_min_u, &tx_min_prec);

		NEXT_ROW;
		putl("  %-26s %8.*f%s %8.*f%s     %8.*f%s %8.*f%s    ", "Total",
		    rx_maj_prec, rx_maj, rx_maj_u, rx_min_prec, rx_min, rx_min_u,
		    tx_maj_prec, tx_maj, tx_maj_u, tx_min_prec, tx_min, tx_min_u);

		move(row, 28);
		addch(ACS_VLINE);
		move(row, 54);
		addch(ACS_VLINE);
	}

	if (c_use_colors)
		attrset(COLOR_PAIR(LAYOUT_DEFAULT) | layout[LAYOUT_DEFAULT].attr);
}
Exemplo n.º 8
0
int WDL_CursesEditor::onChar(int c)
{
  if (m_state == -3 || m_state == -4)
  {
    switch (c)
    {
       case '\r': case '\n':
         m_state=0;
         runSearch();
       break;
       case 27: 
         m_state=0; 
         draw();
         draw_message("Find cancelled.");
         setCursor();
       break;
       case KEY_BACKSPACE: if (s_search_string[0]) s_search_string[strlen(s_search_string)-1]=0; m_state=-4; break;
       default: 
         if (VALIDATE_TEXT_CHAR(c)) 
         { 
           int l=m_state == -3 ? 0 : strlen(s_search_string); 
           m_state = -4;
           if (l < (int)sizeof(s_search_string)-1) { s_search_string[l]=c; s_search_string[l+1]=0; } 
         } 
        break;
     }
     if (m_state)
     {
       attrset(m_color_message);
       bkgdset(m_color_message);
       mvaddstr(LINES-1,29,s_search_string);
       clrtoeol(); 
       attrset(0);
       bkgdset(0);
     }
     return 0;
  }
  if (c==KEY_DOWN || c==KEY_UP || c==KEY_PPAGE||c==KEY_NPAGE || c==KEY_RIGHT||c==KEY_LEFT||c==KEY_HOME||c==KEY_END)
  {
    if (GetAsyncKeyState(VK_SHIFT)&0x8000)      
    {
      if (!m_selecting)
      {
        m_select_x2=m_select_x1=m_curs_x; m_select_y2=m_select_y1=m_curs_y;
        m_selecting=1;
      }
    }
    else if (m_selecting) { m_selecting=0; draw(); }
  }

  switch(c)
  {
    case 407:
    case 'Z'-'A'+1:
      if (!(GetAsyncKeyState(VK_SHIFT)&0x8000))
      {
        if (m_undoStack_pos > 0)
        {
           m_undoStack_pos--;
           loadUndoState(m_undoStack.Get(m_undoStack_pos));
           draw();
           char buf[512];
           snprintf(buf,sizeof(buf),"Undid action -- %d items in undo buffer",m_undoStack_pos);
           draw_message(buf);
           setCursor();
        }
        else draw_message("Can't Undo");

        break;
      }
      // fall through
    case 'Y'-'A'+1:
      if (m_undoStack_pos < m_undoStack.GetSize()-1)
      {
        m_undoStack_pos++;
        loadUndoState(m_undoStack.Get(m_undoStack_pos));
        draw();
        char buf[512];
        snprintf(buf,sizeof(buf),"Redid action -- %d items in redo buffer",m_undoStack.GetSize()-m_undoStack_pos-1);
        draw_message(buf);
        setCursor();
      }
      else draw_message("Can't Redo");  
    break;
    case KEY_IC:
      if (!(GetAsyncKeyState(VK_SHIFT)&0x8000))
      {
        s_overwrite=!s_overwrite;
        setCursor();
        break;
      }
      // fqll through
    case 'V'-'A'+1:
      {
        // generate a m_clipboard using win32 clipboard data
        WDL_PtrList<const char> lines;
        WDL_String buf;
#ifdef WDL_IS_FAKE_CURSES
        if (CURSES_INSTANCE)
        {
          OpenClipboard(CURSES_INSTANCE->m_hwnd);
          HANDLE h=GetClipboardData(CF_TEXT);
          if (h)
          {
            char *t=(char *)GlobalLock(h);
            int s=GlobalSize(h);
            buf.Set(t,s);
            GlobalUnlock(t);        
          }
          CloseClipboard();
        }
        else
#endif
        {
          buf.Set(s_fake_clipboard.Get());
        }

        if (buf.Get() && buf.Get()[0])
        {
          char *src=buf.Get();
          while (*src)
          {
            char *seek=src;
            while (*seek && *seek != '\r' && *seek != '\n') seek++;
            char hadclr=*seek;
            if (*seek) *seek++=0;
            lines.Add(src);

            if (hadclr == '\r' && *seek == '\n') seek++;

            if (hadclr && !*seek)
            {
              lines.Add("");
            }
            src=seek;
          }
        }
        if (lines.GetSize())
        {
          removeSelect();
          // insert lines at m_curs_y,m_curs_x
          if (m_curs_y >= m_text.GetSize()) m_curs_y=m_text.GetSize()-1;
          if (m_curs_y < 0) m_curs_y=0;

          preSaveUndoState();
          WDL_FastString poststr;
          int x;
          int indent_to_pos = -1;
          for (x = 0; x < lines.GetSize(); x ++)
          {
            WDL_FastString *str=m_text.Get(m_curs_y);
            const char *tstr=lines.Get(x);
            if (!tstr) tstr="";
            if (!x)
            {
              if (str)
              {
                if (m_curs_x < 0) m_curs_x=0;
                int tmp=str->GetLength();
                if (m_curs_x > tmp) m_curs_x=tmp;
  
                poststr.Set(str->Get()+m_curs_x);
                str->SetLen(m_curs_x);

                const char *p = str->Get();
                while (*p == ' ' || *p == '\t') p++;
                if (!*p && p > str->Get())
                {
                  if (lines.GetSize()>1)
                  {
                    while (*tstr == ' ' || *tstr == '\t') tstr++;
                  }
                  indent_to_pos = m_curs_x;
                }

                str->Append(tstr);
              }
              else
              {
                m_text.Insert(m_curs_y,(str=new WDL_FastString(tstr)));
              }
              if (lines.GetSize() > 1)
              {
                m_curs_y++;
              }
              else
              {
                m_curs_x = str->GetLength();
                str->Append(poststr.Get());
              }
           }
           else if (x == lines.GetSize()-1)
           {
             WDL_FastString *s=newIndentedFastString(tstr,indent_to_pos);
             m_curs_x = s->GetLength();
             s->Append(poststr.Get());
             m_text.Insert(m_curs_y,s);
           }
           else
           {
             m_text.Insert(m_curs_y,newIndentedFastString(tstr,indent_to_pos));
             m_curs_y++;
           }
         }
         draw();
         draw_message("Pasted");
         saveUndoState();
         setCursor();
       }
       else 
       {
         draw_message("Clipboard empty");
         setCursor();
       }
     }
  break;

  case KEY_DC:
    if (!(GetAsyncKeyState(VK_SHIFT)&0x8000))
    {
      WDL_FastString *s;
      if (m_selecting)
      {
        preSaveUndoState();
        removeSelect();
        draw();
        saveUndoState();
        setCursor();
      }
      else if ((s=m_text.Get(m_curs_y)))
      {
        if (m_curs_x < s->GetLength())
        {
          preSaveUndoState();

          bool hadCom = LineCanAffectOtherLines(s->Get(),m_curs_x,1); 
          s->DeleteSub(m_curs_x,1);
          if (!hadCom) hadCom = LineCanAffectOtherLines(s->Get(),-1,-1);
          draw(hadCom ? -1 : m_curs_y);
          saveUndoState();
          setCursor();
        }
        else // append next line to us
        {
          if (m_curs_y < m_text.GetSize()-1)
          {
            preSaveUndoState();

            WDL_FastString *nl=m_text.Get(m_curs_y+1);
            if (nl)
            {
              s->Append(nl->Get());
            }
            m_text.Delete(m_curs_y+1,true);

            draw();
            saveUndoState();
            setCursor();
          }
        }
      }
      break;
    }
  case 'C'-'A'+1:
  case 'X'-'A'+1:
    if (m_selecting)
    {
      if (c!= 'C'-'A'+1) m_selecting=0;
      int miny,maxy,minx,maxx;
      int x;
      getselectregion(minx,miny,maxx,maxy);
      const char *status="";
      char statusbuf[512];

      if (minx != maxx|| miny != maxy) 
      {
        int bytescopied=0;
        s_fake_clipboard.Set("");

        int lht=0,fht=0;
        if (c != 'C'-'A'+1) preSaveUndoState();

        for (x = miny; x <= maxy; x ++)
        {
          WDL_FastString *s=m_text.Get(x);
          if (s) 
          {
            const char *str=s->Get();
            int sx,ex;
            if (x == miny) sx=max(minx,0);
            else sx=0;
            int tmp=s->GetLength();
            if (sx > tmp) sx=tmp;
      
            if (x == maxy) ex=min(maxx,tmp);
            else ex=tmp;
      
            bytescopied += ex-sx + (x!=maxy);
            if (s_fake_clipboard.Get() && s_fake_clipboard.Get()[0]) s_fake_clipboard.Append("\r\n");
            s_fake_clipboard.Append(ex-sx?str+sx:"",ex-sx);

            if (c != 'C'-'A'+1)
            {
              if (sx == 0 && ex == tmp) // remove entire line
              {
                m_text.Delete(x,true);
                if (x==miny) miny--;
                x--;
                maxy--;
              }
              else { if (x==miny) fht=1; if (x == maxy) lht=1; s->DeleteSub(sx,ex-sx); }
            }
          }
        }
        if (fht && lht && miny+1 == maxy)
        {
          m_text.Get(miny)->Append(m_text.Get(maxy)->Get());
          m_text.Delete(maxy,true);
        }
        if (c != 'C'-'A'+1)
        {
          m_curs_y=miny;
          if (m_curs_y < 0) m_curs_y=0;
          m_curs_x=minx;
          saveUndoState();
          snprintf(statusbuf,sizeof(statusbuf),"Cut %d bytes",bytescopied);
        }
        else
          snprintf(statusbuf,sizeof(statusbuf),"Copied %d bytes",bytescopied);

#ifdef WDL_IS_FAKE_CURSES
        if (CURSES_INSTANCE)
        {
          int l=s_fake_clipboard.GetLength()+1;
          HANDLE h=GlobalAlloc(GMEM_MOVEABLE,l);
          void *t=GlobalLock(h);
          memcpy(t,s_fake_clipboard.Get(),l);
          GlobalUnlock(h);
          OpenClipboard(CURSES_INSTANCE->m_hwnd);
          EmptyClipboard();
          SetClipboardData(CF_TEXT,h);
          CloseClipboard();
        }
#endif

        status=statusbuf;
      }
      else status="No selection";

      draw();
      draw_message(status);
      setCursor();
    }
  break;
  case 'A'-'A'+1:
    m_selecting=1;
    m_select_x1=0;
    m_select_y1=0;
    m_select_y2=m_text.GetSize()-1;
    m_select_x2=0;
    if (m_text.Get(m_select_y2))
      m_select_x2=m_text.Get(m_select_y2)->GetLength();
    draw();
    setCursor();
  break;
  case 27:
    if (m_selecting)
    {
      m_selecting=0;
      draw();
      setCursor();
      break;
    }
  return 0;
  case KEY_F3:
  case 'G'-'A'+1:
    if (s_search_string[0])
    {
      runSearch();
      return 0;
    }
  case 'F'-'A'+1:
    draw_message("");
    attrset(m_color_message);
    bkgdset(m_color_message);
    mvaddstr(LINES-1,0,"Find string (ESC to cancel): ");
    addstr(s_search_string);
    clrtoeol();
    attrset(0);
    bkgdset(0);
    m_state=-3; // find, initial (m_state=4 when we've typed something)
  return 0;
  case KEY_DOWN:
    {
      if (GetAsyncKeyState(VK_CONTROL)&0x8000)      
      {
        if (m_offs_y < m_text.GetSize() - 4) 
        {
          m_offs_y++;
          if (m_curs_y < m_offs_y) m_curs_y = m_offs_y;
          draw();
        }
      }
      else
      {
        m_curs_y++;
        if(m_curs_y>=m_text.GetSize()) m_curs_y=m_text.GetSize()-1;
        if(m_curs_y < 0) m_curs_y=0;
      }
      if (m_selecting) { setCursor(1); m_select_x2=m_curs_x; m_select_y2=m_curs_y; draw(); }
      setCursor(1);
    }
  break;
  case KEY_UP:
    {
      if (GetAsyncKeyState(VK_CONTROL)&0x8000)      
      {
        if (m_offs_y>0) 
        {
          m_offs_y--;
          if (m_curs_y>m_offs_y + getVisibleLines() - 1) m_curs_y = m_offs_y + getVisibleLines() - 1;
          if (m_curs_y < 0) m_curs_y=0;
          draw();
        }
      }
      else
      {
        if(m_curs_y>0) m_curs_y--;
      }
      if (m_selecting) { setCursor(1); m_select_x2=m_curs_x; m_select_y2=m_curs_y; draw(); }
      setCursor(1);
    }
  break;
  case KEY_PPAGE:
    {
      if (m_curs_y > m_offs_y) 
      {
        m_curs_y=m_offs_y;
        if (m_curs_y < 0) m_curs_y=0;
      }
      else 
      {
        m_curs_y -= getVisibleLines();
        if (m_curs_y < 0) m_curs_y=0;
        m_offs_y=m_curs_y;
      }
      if (m_selecting) { setCursor(1); m_select_x2=m_curs_x; m_select_y2=m_curs_y; }
      draw();
      setCursor(1);
    }
  break;
  case KEY_NPAGE:
    {
      if (m_curs_y >= m_offs_y+getVisibleLines() - 1) m_offs_y=m_curs_y+1;
      m_curs_y = m_offs_y+getVisibleLines() - 1;
      if (m_curs_y >= m_text.GetSize()) m_curs_y=m_text.GetSize()-1;
      if (m_curs_y < 0) m_curs_y=0;
      if (m_selecting) { setCursor(1); m_select_x2=m_curs_x; m_select_y2=m_curs_y; }
      draw();
      setCursor(1);
    }
  break;
  case KEY_RIGHT:
    {
      if (1) // wrap across lines
      {
        WDL_FastString *s = m_text.Get(m_curs_y);
        if (s && m_curs_x >= s->GetLength() && m_curs_y < m_text.GetSize()) { m_curs_y++; m_curs_x = -1; }
      }

      if(m_curs_x<0) 
      {
        m_curs_x=0;
      }
      else
      {
        if (GetAsyncKeyState(VK_CONTROL)&0x8000)      
        {
          WDL_FastString *s = m_text.Get(m_curs_y);
          if (!s||m_curs_x >= s->GetLength()) break;
          int lastType = categorizeCharForWordNess(s->Get()[m_curs_x++]);
          while (m_curs_x < s->GetLength())
          {
            int thisType = categorizeCharForWordNess(s->Get()[m_curs_x]);
            if (thisType != lastType && thisType != 0) break;
            lastType=thisType;
            m_curs_x++;
          }
        }
        else 
        {
          m_curs_x++;
        }
      }
      if (m_selecting) { setCursor(); m_select_x2=m_curs_x; m_select_y2=m_curs_y; draw(); }
      setCursor();
    }
  break;
  case KEY_LEFT:
    {
      bool doMove=true;
      if (1) // wrap across lines
      {
        WDL_FastString *s = m_text.Get(m_curs_y);
        if (s && m_curs_y>0 && m_curs_x == 0) 
        { 
          s = m_text.Get(--m_curs_y);
          if (s) 
          {
            m_curs_x = s->GetLength(); 
            doMove=false;
          }
        }
      }

      if(m_curs_x>0 && doMove) 
      {
        if (GetAsyncKeyState(VK_CONTROL)&0x8000)      
        {
          WDL_FastString *s = m_text.Get(m_curs_y);
          if (!s) break;
          if (m_curs_x > s->GetLength()) m_curs_x = s->GetLength();
          m_curs_x--;

          int lastType = categorizeCharForWordNess(s->Get()[m_curs_x--]);
          while (m_curs_x >= 0)
          {
            int thisType = categorizeCharForWordNess(s->Get()[m_curs_x]);
            if (thisType != lastType && lastType != 0) break;
            lastType=thisType;
            m_curs_x--;
          }
          m_curs_x++;
        }
        else 
        {
          m_curs_x--;
        }
      }
      if (m_selecting) { setCursor(); m_select_x2=m_curs_x; m_select_y2=m_curs_y; draw(); }
      setCursor();
    }
  break;
  case KEY_HOME:
    {
      m_curs_x=0;
      if (m_selecting) { setCursor(); m_select_x2=m_curs_x; m_select_y2=m_curs_y; draw(); }
      setCursor();
    }
  break;
  case KEY_END:
    {
      if (m_text.Get(m_curs_y)) m_curs_x=m_text.Get(m_curs_y)->GetLength();
      if (m_selecting) { setCursor(); m_select_x2=m_curs_x; m_select_y2=m_curs_y; draw(); }
      setCursor();
    }
  break;
  case KEY_BACKSPACE: // backspace, baby
    if (m_selecting)
    {
      preSaveUndoState();
      removeSelect();
      draw();
      saveUndoState();
      setCursor();
    }
    else if (m_curs_x > 0)
    {
      WDL_FastString *tl=m_text.Get(m_curs_y);
      if (tl)
      {
        preSaveUndoState();

        bool hadCom = LineCanAffectOtherLines(tl->Get(), m_curs_x-1,1);
        tl->DeleteSub(--m_curs_x,1);
        if (!hadCom) hadCom = LineCanAffectOtherLines(tl->Get(),-1,-1);
        draw(hadCom?-1:m_curs_y);
        saveUndoState();
        setCursor();
      }
    }
    else // append current line to previous line
    {
      WDL_FastString *fl=m_text.Get(m_curs_y-1), *tl=m_text.Get(m_curs_y);
      if (!tl) 
      {
        m_curs_y--;
        if (fl) m_curs_x=fl->GetLength();
        draw();
        saveUndoState();
        setCursor();
      }
      else if (fl)
      {
        preSaveUndoState();
        m_curs_x=fl->GetLength();
        fl->Append(tl->Get());

        m_text.Delete(m_curs_y--,true);
        draw();
        saveUndoState();
        setCursor();
      }
    }
  break;
  case 'L'-'A'+1:
    draw();
    setCursor();
  break;
  case 13: //KEY_ENTER:
    //insert newline
    preSaveUndoState();

    if (m_selecting) { removeSelect(); draw(); setCursor(); }
    if (m_curs_y >= m_text.GetSize())
    {
      m_curs_y=m_text.GetSize();
      m_text.Add(new WDL_FastString);
    }
    if (s_overwrite)
    {
      WDL_FastString *s = m_text.Get(m_curs_y);
      int plen=0;
      const char *pb=NULL;
      if (s)
      {
        pb = s->Get();
        while (plen < m_curs_x && (pb[plen]== ' ' || pb[plen] == '\t')) plen++;
      }
      if (++m_curs_y >= m_text.GetSize())
      {
        m_curs_y = m_text.GetSize();
        WDL_FastString *ns=new WDL_FastString;
        if (plen>0) ns->Set(pb,plen);
        m_text.Insert(m_curs_y,ns);
      }
      s = m_text.Get(m_curs_y);
      if (s && plen > s->GetLength()) plen=s->GetLength();
      m_curs_x=plen;
    }
    else 
    {
      WDL_FastString *s = m_text.Get(m_curs_y);
      if (s)
      {
        if (m_curs_x > s->GetLength()) m_curs_x = s->GetLength();
        WDL_FastString *nl = new WDL_FastString();
        int plen=0;
        const char *pb = s->Get();
        while (plen < m_curs_x && (pb[plen]== ' ' || pb[plen] == '\t')) plen++;

        if (plen>0) nl->Set(pb,plen);

        nl->Append(pb+m_curs_x);
        m_text.Insert(++m_curs_y,nl);
        s->SetLen(m_curs_x);
        m_curs_x=plen;
      }
    }
    m_offs_x=0;

    draw();
    saveUndoState();
    setCursor();
  break;
  case '\t':
    if (m_selecting)
    {
      preSaveUndoState();

      bool isRev = !!(GetAsyncKeyState(VK_SHIFT)&0x8000);
      indentSelect(isRev?-m_indent_size:m_indent_size);
      // indent selection:
      draw();
      setCursor();
      saveUndoState();
      break;
    }
  default:
    //insert char
    if(VALIDATE_TEXT_CHAR(c))
    { 
      preSaveUndoState();

      if (m_selecting) { removeSelect(); draw(); setCursor(); }
      if (!m_text.Get(m_curs_y)) m_text.Insert(m_curs_y,new WDL_FastString);

      WDL_FastString *ss;
      if ((ss=m_text.Get(m_curs_y)))
      {
        char str[64];
        int slen ;
        if (c == '\t') 
        {
          slen = min(m_indent_size,64);
          if (slen<1) slen=1;
          int x; 
          for(x=0;x<slen;x++) str[x]=' ';
        }
        else
        {
          str[0]=c;
          slen = 1;
        }


        bool hadCom = LineCanAffectOtherLines(ss->Get(),-1,-1);
        if (s_overwrite)
        {
          if (!hadCom) hadCom = LineCanAffectOtherLines(ss->Get(),m_curs_x,slen);
          ss->DeleteSub(m_curs_x,slen);
        }
        ss->Insert(str,m_curs_x,slen);
        if (!hadCom) hadCom = LineCanAffectOtherLines(ss->Get(),m_curs_x,slen);

        m_curs_x += slen;
        draw(hadCom ? -1 : m_curs_y);
      }
      saveUndoState();
      setCursor();
    }
    break;
  }
  return 0;
}
Exemplo n.º 9
0
void setcolor (int n,int m)
{
   if (m==1) attr_set (A_BOLD,0,0);
   else attr_set (A_NORMAL,0,0);
   color_set (n,0);
   if ((nocolor==1) && ((n==2) || (n==3) || (n==5) || (n==7) || (n==10) || (n==11) || (n==12) || (n==13))) attrset (A_REVERSE);
}
Exemplo n.º 10
0
static void draw_item_list_entry(item_t *intf, node_t *node)
{
	int rxprec, txprec, rxpprec, txpprec;
	stat_attr_t *bytes, *packets;
	double rx, tx, rxp, txp;
	char *rx_u, *tx_u, *rxp_u, *txp_u;
	char pad[23];

	bytes = lookup_attr(intf, intf->i_major_attr);
	packets = lookup_attr(intf, intf->i_minor_attr);

	if (bytes == NULL || packets == NULL)
		return;

	rx = cancel_down(attr_get_rx_rate(bytes), bytes->a_unit, &rx_u, &rxprec);
	tx = cancel_down(attr_get_tx_rate(bytes), bytes->a_unit, &tx_u, &txprec);

	rxp = cancel_down(attr_get_rx_rate(packets), packets->a_unit, &rxp_u, &rxpprec);
	txp = cancel_down(attr_get_tx_rate(packets), packets->a_unit, &txp_u, &txpprec);

	memset(pad, 0, sizeof(pad));
	memset(pad, ' ', intf->i_level < 15 ? intf->i_level : 15);

	strncat(pad, intf->i_name, sizeof(pad) - strlen(pad) - 1);

	if (intf->i_desc) {
		strncat(pad, " (", sizeof(pad) - strlen(pad) - 1);
		strncat(pad, intf->i_desc, sizeof(pad) - strlen(pad) - 1);
		strncat(pad, ")", sizeof(pad) - strlen(pad) - 1);
	}
	NEXT_ROW;

	if (intf->i_index == node->n_selected && node == get_current_node()) {
		if (c_use_colors)
			attrset(COLOR_PAIR(LAYOUT_SELECTED) | layout[LAYOUT_SELECTED].attr);
		else
			attron(A_REVERSE);
	}
	
	printw("  %-3d%s", intf->i_index, (intf->i_flags & ITEM_FLAG_FOLDED) ? "+" : " ");

	if (intf->i_index == node->n_selected && node == get_current_node()) {
		if (c_use_colors)
			attrset(COLOR_PAIR(LAYOUT_LIST) | layout[LAYOUT_LIST].attr);
		else
			attroff(A_REVERSE);
	}

	putl("%-22s %8.*f%s %8.*f%s %2d%% %8.*f%s %8.*f%s %2d%%", pad,
		rxprec, rx, rx_u, rxpprec, rxp, rxp_u, intf->i_rx_usage,
		txprec, tx, tx_u, txpprec, txp, txp_u, intf->i_tx_usage);

	if (intf->i_rx_usage == -1) {
		move(row, 51);
		addstr("   ");
	}

	if (intf->i_tx_usage == -1) {
		move(row, 77);
		addstr("   ");
	}

	move(row, 28);
	addch(ACS_VLINE);
	move(row, 54);
	addch(ACS_VLINE);
}
Exemplo n.º 11
0
int main()
{
int a[200][200];
x1=0;
y1=0;
initscr();
start_color();
init_pair(2,COLOR_GREEN,COLOR_BLACK);
init_pair(3,6,COLOR_BLACK);
init_pair(4,COLOR_RED,COLOR_BLACK);
attrset(A_BOLD);
noecho();
c=0;
x=0;
y=0;
clear();
refresh();
color_set(2,0);
move(0,0);
addstr("+");
refresh();
while(c!='*')
{

x1=0;
y1=0;
while(y1<COLS-1)
{
while(x1<LINES-1)
{
if(a[x1][y1]==1)
{
move(x1,y1);
if((x1==x)&&(y1==y))
{
color_set(4,0);
addstr("+");
refresh();
}
else
{
color_set(3,0);
addstr("o");
refresh();
}
}
x1+=1;
}
x1=0;
y1+=1;
}
c=getchar();
if(c=='c')
{
x1=0;
y1=0;
while(y1<COLS)
{
while(x1<LINES)
{
a[x1][y1]=0;
x1+=1;
}
x1=0;
y1+=1;
}
clear();
color_set(2,0);
move(x,y);
addstr("+");
refresh();
}

if(c=='i')
{
x1=0;
y1=0;
while(y1<COLS-1)
{
while(x1<LINES-1)
{
if(a[x1][y1]==1)
{
a[x1][y1]=0;
}
else
{
a[x1][y1]=1;
}
x1+=1;
}
x1=0;
y1+=1;
}
x1=0;
y1=0;
while(y1<COLS-1)
{
while(x1<LINES-1)
{
if(a[x1][y1]==1)
{
move(x1,y1);
if((x1==x)&&(y1==y))
{
color_set(4,0);
addstr("+");
refresh();
}
else
{
color_set(3,0);
addstr("o");
refresh();
}
}
else
{
move(x1,y1);
if((x1==x)&&(y1==y))
{
color_set(2,0);
addstr("+");
refresh();
}
else
{
color_set(3,0);
addstr(" ");
refresh();
}
}
x1+=1;
}
y1+=1;
x1=0;
}
}

if(c=='o')
{
x1=0;
y1=0;
while(y1<COLS)
{
while(x1<LINES)
{
a[x1][y1]=1;
x1+=1;
}
x1=0;
y1+=1;
}
x1=0;
y1=0;
while(y1<COLS-1)
{
while(x1<LINES-1)
{
if(a[x1][y1]==1)
{
move(x1,y1);
if((x1==x)&&(y1==y))
{
color_set(4,0);
addstr("+");
refresh();
}
else
{
color_set(3,0);
addstr("o");
refresh();
}
}
x1+=1;
}
x1=0;
y1+=1;
}
}

if(c==13)
{
if(a[x][y]==0)
{
a[x][y]=1;
continue;
}
if(a[x][y]==1)
{
a[x][y]=0;
color_set(2,0);
move(x,y);
addstr("+");
}
}
if(c==68)
{
if(y>0)
{
yy=(y-1);
color_set(2,0);
move(x,y);
addstr(" ");
move(x,yy);
addstr("+");
refresh();
y=yy;
}
}

if(c==67)
{
if(y<COLS-1)
{
yy=(y+1);
color_set(2,0);
move(x,y);
addstr(" ");
move(x,yy);
addstr("+");
refresh();
y=yy;
}
}

if(c==66)
{
if(x<LINES-1)
{
xx=(x+1);
color_set(2,0);
move(x,y);
addstr(" ");
move(xx,y);
addstr("+");
refresh();
x=xx;
}
}

if(c==65)
{
if(x>0)
{
xx=(x-1);
color_set(2,0);
move(x,y);
addstr(" ");
move(xx,y);
addstr("+");
refresh();
x=xx;
}
}

}
endwin();

}
Exemplo n.º 12
0
void
tty_setcolor (int color)
{
    attrset (COLOR_PAIR (color) | color_get_attr (color));
}
Exemplo n.º 13
0
int main(int argc, char* argv[]){
  /* Initialize pseudo random number generator */
  srand(time(NULL));

  /* Read command line arguments */
  struct basic_options op;
  struct multi_options mop;
  if (get_options(argc, argv, &op, &mop) == 1) return 1;
 
  /* Setup signal handlers */
  struct sigaction newhandler;            /* new settings         */
  sigset_t         blocked;               /* set of blocked sigs  */
  newhandler.sa_flags = SA_RESTART;       /* options     */
  sigemptyset(&blocked);                  /* clear all bits       */
  newhandler.sa_mask = blocked;           /* store blockmask      */
  newhandler.sa_handler = on_timer;      /* handler function     */
  if ( sigaction(SIGALRM, &newhandler, NULL) == -1 )
    perror("sigaction");


  /* prepare the terminal for the animation */
  setlocale(LC_ALL, "");
  initscr();     /* initialize the library and screen */
  cbreak();      /* put terminal into non-blocking input mode */
  noecho();      /* turn off echo */
  start_color();
  clear();       /* clear the screen */
  curs_set(0);   /* hide the cursor */

  use_default_colors();
  init_pair(0, COLOR_WHITE, COLOR_BLACK);
  init_pair(1, COLOR_WHITE, COLOR_BLACK);
  init_pair(2, COLOR_BLACK, COLOR_BLACK);
  init_pair(3, COLOR_RED, COLOR_BLACK);
  init_pair(4, COLOR_GREEN, COLOR_BLACK);
  init_pair(5, COLOR_BLUE, COLOR_BLACK);
  init_pair(6, COLOR_YELLOW, COLOR_BLACK);
  init_pair(7, COLOR_MAGENTA, COLOR_BLACK);
  init_pair(8, COLOR_CYAN, COLOR_BLACK);
 
  color_set(0, NULL);
  assume_default_colors(COLOR_WHITE, COLOR_BLACK);
  clear();
    
  struct state st;
  struct ui ui;

  /* Initialize the parameters of the program */
  attrset(A_BOLD | COLOR_PAIR(2));
  mvaddstr(0,0,"Map is generated. Please wait.");
  refresh();

  state_init(&st, &op, &mop);
 
  ui_init(&st, &ui);

  clear();
 
  /* non-blocking input */
  int fd_flags = fcntl(0, F_GETFL);
  fcntl(0, F_SETFL, (fd_flags|O_NONBLOCK));

  /* Start the real time interval timer with delay interval size */
  struct itimerval it;
  it.it_value.tv_sec = 0;
  it.it_value.tv_usec = 10000;
  it.it_interval.tv_sec = 0;
  it.it_interval.tv_usec = 10000;
  setitimer(ITIMER_REAL, &it, NULL);
  
  refresh();        
  input_ready = 0;
  time_to_redraw = 1;

  if (!mop.multiplayer_flag) {
    /* Run the game */
    run(&st, &ui);
  }
  else {
    if (mop.server_flag) run_server(&st, mop.clients_num, mop.val_server_port);
    else run_client(&st, &ui, mop.val_server_addr, mop.val_server_port, mop.val_client_port);
  }

  /* Restore the teminal state */
  echo();
  curs_set(1);
  clear();
  endwin();

  if (!mop.multiplayer_flag || mop.server_flag)
    printf ("Random seed was %i\n", st.map_seed);

  free(mop.val_server_addr);
  free(mop.val_server_port);
  free(mop.val_client_port);
  return 0;
}
Exemplo n.º 14
0
int window_online_print()
{
  int y,x;
  char buf[250];
  curseson(); cbreak(); noecho(); nonl(); keypad(stdscr,TRUE);

  getmaxyx(stdscr,y,x);
  attrset(A_NORMAL);
  attrset(COLOR_PAIR(14));

  snprintf(buf, x,
	   "whoIam   :   %s %140.140s", cfg.identity, " ");
  mvaddnstr(y+gui_window_online.y0,
	    0,
	    buf,
	    x-1);

  if (josua_online_status==EXOSIP_NOTIFY_UNKNOWN)
    snprintf(buf, x,
	     "IM status:   %s %140.140s", "unknown", " ");
  else if (josua_online_status==EXOSIP_NOTIFY_PENDING)
    snprintf(buf, x,
	     "IM status:   %s %140.140s", "pending", " ");
  else if (josua_online_status==EXOSIP_NOTIFY_ONLINE)
    snprintf(buf, x,
	     "IM status:   %s %140.140s", "Online", " ");
  else if (josua_online_status==EXOSIP_NOTIFY_BUSY)
    snprintf(buf, x,
	     "IM status:   %s %140.140s", "Busy", " ");
  else if (josua_online_status==EXOSIP_NOTIFY_BERIGHTBACK)
    snprintf(buf, x,
	     "IM status:   %s %140.140s", "Be Right Back", " ");
  else if (josua_online_status==EXOSIP_NOTIFY_AWAY)
    snprintf(buf, x,
	     "IM status:   %s %140.140s", "Away", " ");
  else if (josua_online_status==EXOSIP_NOTIFY_ONTHEPHONE)
    snprintf(buf, x,
	     "IM status:   %s %140.140s", "On The Phone", " ");
  else if (josua_online_status==EXOSIP_NOTIFY_OUTTOLUNCH)
    snprintf(buf, x,
	     "IM status:   %s %140.140s", "Out To Lunch", " ");
  else if (josua_online_status==EXOSIP_NOTIFY_CLOSED)
    snprintf(buf, x,
	     "IM status:   %s %140.140s", "Closed", " ");
  else
    snprintf(buf, x,
	     "IM status:   ?? %140.140s" , " ");
  mvaddnstr(y+gui_window_online.y0+1,
	    0,
	    buf,
	    x-1);

  if (josua_registration_status==-1)
    {
      snprintf(buf, x,
	       "registred:   --Not registred-- %140.140s", " ");
      mvaddnstr(y+gui_window_online.y0+2,
		0,
		buf,
		x-1);
    }
  else if (199<josua_registration_status && josua_registration_status<300)
    {
      snprintf(buf, x,
	       "registred:   [%i %s] %s %140.140s",
	       josua_registration_status,
	       josua_registration_reason_phrase,
	       josua_registration_server, " ");
      mvaddnstr(y+gui_window_online.y0+2,
		0,
		buf,
		x-1);
    }
  else if (josua_registration_status>299)
    {
      snprintf(buf, x,
	       "registred:   [%i %s] %s %140.140s",
	       josua_registration_status,
	       josua_registration_reason_phrase,
	       josua_registration_server, " ");
      mvaddnstr(y+gui_window_online.y0+2,
		0,
		buf,
		x-1);
    }
  else if (josua_registration_status==0)
    {
      snprintf(buf, x,
	       "registred:   [no answer] %s %140.140s",
	       josua_registration_server, " ");
      mvaddnstr(y+gui_window_online.y0+2,
		0,
		buf,
		x-1);
    }

  return 0;
}
Exemplo n.º 15
0
static void curses_draw(void)
{
	if (NULL == get_current_node()) {
		first_node();
		first_item();
	}

	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_item()) {
		putl(" %s on %s",
			get_current_item()->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) {
		if (help_page == 0)
			draw_help();
		else
			draw_help_2();
	}

	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);

	if (1) {
		char s[27];
		time_t t = time(0);
		double d;
		int h, m;

		asctime_r(localtime(&t), s);
		s[strlen(s) - 1] = '\0';
		d = difftime(time(0), start_time);

		if (d / 3600) {
			h = (int) d / 3600;
			m = (int) d % 3600;
			m /= 60;
		} else {
			h = 0;
			m = (int) d / 60;
		}
		
		putl(" %s (%dh/%dm)", s, h, m);
		move(row, COLS - strlen("Press ? for help") - 1);
		putl("%s", "Press ? for help");
		move(row, 0);
	}
	
	attrset(0);
	refresh();
}
Exemplo n.º 16
0
static duc_dir *do_dir(duc_dir *dir, int depth)
{
	int top = 0;
	int cur = 0;

	for(;;) {

		int attr_size, attr_name, attr_class, attr_graph, attr_bar, attr_cursor;

		if(opt_color) {
			attr_size = COLOR_PAIR(PAIR_SIZE);
			attr_name = COLOR_PAIR(PAIR_NAME);
			attr_bar = COLOR_PAIR(PAIR_BAR);
			attr_cursor = COLOR_PAIR(PAIR_CURSOR);
			attr_graph = COLOR_PAIR(PAIR_GRAPH);
			attr_class = COLOR_PAIR(PAIR_CLASS);
		} else {
			attr_size = 0;
			attr_name = A_BOLD;
			attr_class = 0;
			attr_graph = 0;
			attr_bar = A_REVERSE;
			attr_cursor = A_REVERSE;
			use_default_colors();
		}
	
		duc_size_type st = opt_apparent ? DUC_SIZE_TYPE_APPARENT : DUC_SIZE_TYPE_ACTUAL;

		/* Iterate all dirents to find largest size */

		duc_dir_seek(dir, 0);

		off_t size_max = 1;
		struct duc_dirent *e;
		while( (e = duc_dir_read(dir, st)) != NULL) {
			off_t size = opt_apparent ? e->size.apparent : e->size.actual;
			if(size > size_max) size_max = size;
		}

		int count = duc_dir_get_count(dir);
		int pgsize = rows - 2;
		
		/* Check boundaries */

		if(cur < 0) cur = 0;
		if(cur > count - 1) cur = count - 1;
		if(cur < top) top = cur;
		if(cur > top + pgsize - 1) top = cur - pgsize + 1;
		if(top < 0) top = 0;


		/* Draw header */

		char *path = duc_dir_get_path(dir);
		attrset(attr_bar);
		mvhline(0, 0, ' ', cols);
		mvprintw(0, 1, " %s ", path);
		attrset(0);
		free(path);


		/* Draw footer */

		struct duc_size size;
		duc_dir_get_size(dir, &size);
		char siz[32], cnt[32];
		duc_human_size(&size, st, opt_bytes, siz, sizeof siz);
		duc_human_number(count, opt_bytes, cnt, sizeof cnt);
		attrset(attr_bar);
		mvhline(rows-1, 0, ' ', cols);
		mvprintw(rows-1, 0, " Total %sB in %s files/directories", siz, cnt);
		attrset(0);

		/* Draw dirents */
	
		duc_dir_seek(dir, top);

		int i;
		int y = 1;

		for(i=top; i<top + pgsize; i++) {
			
			struct duc_dirent *e = duc_dir_read(dir, st);

			attrset(cur == i ? attr_cursor : 0);
			mvhline(y, 0, ' ', cols);

			if(e) {

				off_t size = opt_apparent ? e->size.apparent : e->size.actual;
		
				size_t max_size_len = opt_bytes ? 12 : 7;

				char class = duc_file_type_char(e->type);

				char siz[32];
				duc_human_size(&e->size, st, opt_bytes, siz, sizeof siz);
				if(cur != i) attrset(attr_size);
				printw("%*s", max_size_len, siz);

				printw(" ");
				char *p = e->name;
				if(cur != i) attrset(attr_name);
				while(*p) {
					if(*(uint8_t *)p >= 32) {
						printw("%c", *p);
					} else {
						printw("^%c", *p+64);
					}
					p++;
				}
				if(cur != i) attrset(attr_class);
				printw("%c", class);

				int w = cols - 30;
				if(w > cols / 2) w = cols / 2;
				if(opt_graph && w > 2) {
					int j;
					off_t g = w * size / size_max;
					if(cur != i) attrset(attr_graph);
					mvprintw(y, cols - w - 4, " [");
					for(j=0; j<w; j++) printw("%s", j < g ? "=" : " ");
					printw("] ");
				}

			} else {

				attrset(A_DIM);
				mvprintw(y, 0, "~");
			}

			y++;
		}

		duc_dir *dir2 = NULL;

		/* Handle key */

		int c = getch();

		switch(c) {
			case 'k':
			case KEY_UP: cur--; break;
			case 'j':
			case KEY_DOWN: cur++; break;
			case 21: cur -= pgsize/2; break;
			case KEY_PPAGE: cur -= pgsize; break;
			case 4: cur += pgsize/2; break;
			case KEY_NPAGE: cur += pgsize; break;
			case KEY_RESIZE: getmaxyx(stdscr, rows, cols); break;
			case 'a': opt_apparent ^= 1; break;
			case 'b': opt_bytes ^= 1; break;
			case 'c': opt_color ^= 1; break;
			case 'g': opt_graph ^= 1; break;
			case 'h': help(); break;

			case 27:
			case 'q': 
				  exit(0); break;

			case KEY_BACKSPACE:
			case KEY_LEFT:
				  if(depth > 0) {
					  return NULL;
				  } else {
					  dir2 = duc_dir_openat(dir, "..");
					  if(dir2) {
						  do_dir(dir2, 0);
						  duc_dir_close(dir2);
					  }
				  }
				  break;

			case KEY_RIGHT:
			case '\r':
			case '\n': 
				  duc_dir_seek(dir, cur);
				  struct duc_dirent *e = duc_dir_read(dir, st);
				  if(e->type == DUC_FILE_TYPE_DIR) {
					dir2 = duc_dir_openent(dir, e);
					if(dir2) {
						do_dir(dir2, depth + 1);
						duc_dir_close(dir2);
					}
				  }
				  break;
			default:
				  break;
		}

	}
Exemplo n.º 17
0
static void
cob_screen_attr (cob_field *fgc, cob_field *bgc, const int attr)
{
	size_t		i;
	int		styles = 0;
	int		line;
	int		column;
	short		fgcolor;
	short		bgcolor;
	short		fgdef;
	short		bgdef;

	attrset (A_NORMAL);
	if (attr & COB_SCREEN_REVERSE) {
		styles |= A_REVERSE;
	}
	if (attr & COB_SCREEN_HIGHLIGHT) {
		styles |= A_BOLD;
	}
	if (attr & COB_SCREEN_BLINK) {
		styles |= A_BLINK;
	}
	if (attr & COB_SCREEN_UNDERLINE) {
		styles |= A_UNDERLINE;
	}
	if (styles) {
		attron (styles);
	}
	if (cob_has_color) {
		fgcolor = fore_color;
		bgcolor = back_color;
		if (fgc) {
			switch (cob_get_int (fgc)) {
			case COB_SCREEN_BLACK:
				fgcolor = COLOR_BLACK;
				break;
			case COB_SCREEN_BLUE:
				fgcolor = COLOR_BLUE;
				break;
			case COB_SCREEN_GREEN:
				fgcolor = COLOR_GREEN;
				break;
			case COB_SCREEN_CYAN:
				fgcolor = COLOR_CYAN;
				break;
			case COB_SCREEN_RED:
				fgcolor = COLOR_RED;
				break;
			case COB_SCREEN_MAGENTA:
				fgcolor = COLOR_MAGENTA;
				break;
			case COB_SCREEN_YELLOW:
				fgcolor = COLOR_YELLOW;
				break;
			case COB_SCREEN_WHITE:
				fgcolor = COLOR_WHITE;
				break;
			default:
				break;
			}
		}
		if (bgc) {
			switch (cob_get_int (bgc)) {
			case COB_SCREEN_BLACK:
				bgcolor = COLOR_BLACK;
				break;
			case COB_SCREEN_BLUE:
				bgcolor = COLOR_BLUE;
				break;
			case COB_SCREEN_GREEN:
				bgcolor = COLOR_GREEN;
				break;
			case COB_SCREEN_CYAN:
				bgcolor = COLOR_CYAN;
				break;
			case COB_SCREEN_RED:
				bgcolor = COLOR_RED;
				break;
			case COB_SCREEN_MAGENTA:
				bgcolor = COLOR_MAGENTA;
				break;
			case COB_SCREEN_YELLOW:
				bgcolor = COLOR_YELLOW;
				break;
			case COB_SCREEN_WHITE:
				bgcolor = COLOR_WHITE;
				break;
			default:
				break;
			}
		}
		for (i = 0; i < (size_t)COLOR_PAIRS; i++) {
			pair_content ((short)i, &fgdef, &bgdef);
			if (fgdef == fgcolor && bgdef == bgcolor) {
				break;
			}
			if (fgdef == 0 && bgdef == 0) {
				init_pair ((short)i, fgcolor, bgcolor);
				break;
			}
		}
		if (i != (size_t)COLOR_PAIRS) {
#ifdef	HAVE_COLOR_SET
			color_set (COLOR_PAIR((short)i), (void *)0);
#else
			attrset (COLOR_PAIR(i));
#endif
			bkgdset (COLOR_PAIR(i));
		} else {
			attrset (A_NORMAL);
		}
	}
	if (attr & COB_SCREEN_BLANK_SCREEN) {
		getyx (stdscr, line, column);
		clear ();
		move (line, column);
	}
	if (attr & COB_SCREEN_BLANK_LINE) {
		getyx (stdscr, line, column);
		move (line, 0);
		clrtoeol ();
		move (line, column);
	}
	if (attr & COB_SCREEN_ERASE_EOL) {
		clrtoeol ();
	}
	if (attr & COB_SCREEN_ERASE_EOS) {
		clrtobot ();
	}
	if (attr & COB_SCREEN_BELL) {
		beep ();
	}
}
Exemplo n.º 18
0
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();
}
Exemplo n.º 19
0
void Container::Print_Object_Name()
{
  attrset(COLOR_PAIR(Blue_Green));
  addstr(Name);
}
Exemplo n.º 20
0
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);
	}
}
Exemplo n.º 21
0
/* visual mode */
void visualmode(void){
	int c;

	currmode = PM_VISUAL;
	//attrset(A_REVERSE);
	if(currtab == 0){
	}else if(currtab == 1){
		highlight_firstx = trackx;
		highlight_lastx = trackx;
		highlight_firsty = tracky;
		highlight_lasty = tracky;
	}else if(currtab == 2){
	}else{
		highlight_firstx = -1;
		highlight_lastx = -1;
		highlight_firsty = -1;
		highlight_lasty = -1;
	}

	while(currmode == PM_VISUAL){
		if((c = getch()) != ERR) switch(c){
			case 'v':
			case KEY_ESCAPE:
				currmode = PM_NORMAL;
				break;
			case 'V':
				visuallinemode();
				break;
			case 'h':
				act_mvleft();
				if(currtab==0){
				}else if(currtab==1){
					highlight_lastx = trackx;
				}else if(currtab==2){
				}
				break;
			case 'j':
				act_mvdown();
				if(currtab==0){
				}else if(currtab==1){
					highlight_lasty = tracky;
				}else if(currtab==2){
				}
				break;
			case 'k':
				act_mvup();
				if(currtab==0){
				}else if(currtab==1){
					highlight_lasty = tracky;
				}else if(currtab==2){
				}
				break;
			case 'l':
				act_mvright();
				if(currtab==0){
				}else if(currtab==1){
					highlight_lastx = trackx;
				}else if(currtab==2){
				}
				break;
		}
		drawgui();
	}
	attrset(A_BOLD);
	return;
}
Exemplo n.º 22
0
/* 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);
}
Exemplo n.º 23
0
void colorTest(WINDOW *win)
{
    static const short colors[] =
    {
        COLOR_BLACK, COLOR_RED, COLOR_GREEN, COLOR_BLUE,
        COLOR_CYAN, COLOR_MAGENTA, COLOR_YELLOW, COLOR_WHITE
    };

    static const char *colornames[] =
    {
        "COLOR_BLACK", "COLOR_RED", "COLOR_GREEN", "COLOR_BLUE",
        "COLOR_CYAN", "COLOR_MAGENTA", "COLOR_YELLOW", "COLOR_WHITE"
    };

    chtype fill = ACS_BLOCK;

    int i, j, tmarg, col1, col2, col3, col4, ch;

    if (!has_colors())
        return;

    do
    {
        tmarg = (LINES - 19) / 2;
        col1 = (COLS - 60) / 2;
        col2 = col1 + 15;
        col3 = col2 + 15;
        col4 = col3 + 15;

        attrset(A_BOLD);
        mvaddstr(tmarg, (COLS - 22) / 2, "Color Attribute Macros");
        attrset(A_NORMAL);

        mvaddstr(tmarg + 3, col2 + 2, "A_NORMAL");
        mvaddstr(tmarg + 3, col3 + 3, "A_BOLD");
        mvaddstr(tmarg + 3, col4 + 3, "A_BLINK");

        for (i = 0; i < 8; i++)
        {
            init_pair((short)(i + 4), colors[i], background_index);
            mvaddstr(tmarg + i + 5, col1, colornames[i]);

            for (j = 0; j < 12; j++)
            {
                mvaddch(tmarg + i + 5, col2 + j, fill | COLOR_PAIR(i + 4));
                mvaddch(tmarg + i + 5, col3 + j, fill | COLOR_PAIR(i + 4) | A_BOLD);
                mvaddch(tmarg + i + 5, col4 + j, fill | COLOR_PAIR(i + 4) | A_BLINK);
            }
            attrset( COLOR_PAIR( i + 4) | A_BLINK);
            mvaddstr( tmarg + i + 5, col4 + 5, "Text");
            attrset( COLOR_PAIR( i + 4) | A_BOLD);
            mvaddstr( tmarg + i + 5, col3 + 5, "Text");
            attroff( A_BOLD);
            mvaddstr( tmarg + i + 5, col2 + 5, "Text");
            attrset( A_NORMAL);
        }

        mvprintw(tmarg + 15, col1, "COLORS = %d", COLORS);
        mvprintw(tmarg + 16, col1, "COLOR_PAIRS = %d", COLOR_PAIRS);

/* BJG additions: */
        attrset(A_ITALIC);
        mvprintw( tmarg + 15, col3, "Italic");
        attrset(A_BOLD);
        mvprintw( tmarg + 16, col3, "Bold");
        attrset(A_BLINK);
        mvprintw( tmarg + 17, col3, "Blink");

        attrset(A_ITALIC | A_BLINK);
        mvprintw( tmarg + 15, col4, "Italic Blink");
        attrset(A_BLINK | A_BOLD);
        mvprintw( tmarg + 16, col4, "Blink Bold");
        attrset(A_BOLD | A_ITALIC);
        mvprintw( tmarg + 17, col4, "Italic Bold");
        attrset(A_BOLD | A_ITALIC | A_BLINK);
        mvprintw( tmarg + 18, col4, "Italic Blink Bold");
/* end BJG addenda */
        attrset(A_NORMAL);

        mvaddstr(tmarg + 19, 3, "Press any key to continue");
        ch = getch();
# ifdef PDCURSES
        if( ch == KEY_RESIZE)
        {
            erase();
            resize_term(0, 0);
        }
# endif
    }  while( ch == KEY_RESIZE);

    if (can_change_color())
    {
        struct
        {
            short red, green, blue;
        } orgcolors[16];

        int MAXCOL = (COLORS >= 16) ? 16 : 8;

        if (MAXCOL < 8)
            return;

        for (i = 0; i < MAXCOL; i++)
            color_content((short)i, &(orgcolors[i].red),
                                    &(orgcolors[i].green),
                                    &(orgcolors[i].blue));

        attrset(A_BOLD);
        mvaddstr(tmarg, (COLS - 22) / 2, " init_color() Example ");
        attrset(A_NORMAL);

        refresh();

        for (i = 0; i < 8; i++)
        {
            init_color(colors[i], (short)(i * 125), 0, (short)(i * 125));

            if (MAXCOL == 16)
                init_color((short)(colors[i] + 8), 0, (short)(i * 125), 0);
        }

        mvaddstr(tmarg + 19, 3, "Press any key to continue");
        getch();
        for (i = 0; i < MAXCOL; i++)
            init_color((short)i, orgcolors[i].red,
                                 orgcolors[i].green,
                                 orgcolors[i].blue);
    }
/* BJG additions: */
    if( COLORS == 256 && LINES >= 18) do  /* show off all 256 colors */
    {
       tmarg = LINES / 2 - 8;
       erase( );
       for( i = 0; i < 256; i++)
           {
           char tbuff[4];
           const int col = COLS / 2 - 24;

           if( i >= 16)
              init_pair((short)i, (short)i, COLOR_BLACK);
           attrset( COLOR_PAIR( i) | A_REVERSE);
           sprintf( tbuff, "%02x ", i);
           mvaddstr( tmarg + i / 16, col + (i % 16) * 3, tbuff);
           }
       attrset( A_LEFTLINE);
       mvaddstr( tmarg + 17, col1, "A_LEFTLINE");
       attrset( A_UNDERLINE);
       mvaddstr( tmarg + 18, col1, "A_UNDERLINE");
       attrset( A_RIGHTLINE);
       mvaddstr( tmarg + 19, col1, "A_RIGHTLINE");
# if(CHTYPE_LONG >= 2)        /* following types don't exist otherwise: */
       attrset( A_OVERLINE);
       mvaddstr( tmarg + 17, col2, "A_OVERLINE");
       attrset( A_STRIKEOUT);
       mvaddstr( tmarg + 18, col2, "A_STRIKEOUT");
       attrset( A_OVERLINE | A_UNDERLINE);
       mvaddstr( tmarg + 19, col2, "Over/underlined");
#endif
       attrset(A_NORMAL);
       refresh( );
       ch = getch( );
# ifdef PDCURSES
        if( ch == KEY_RESIZE)
            resize_term(0, 0);
# endif
    } while( ch == KEY_RESIZE);
}
Exemplo n.º 24
0
/* 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;
}
Exemplo n.º 25
0
void acsTest(WINDOW *win)
{
#ifdef ACS_S3
# define ACSNUM 32
#else
# define ACSNUM 25
#endif
    static const char *acs_names[] =
    {
        "ACS_ULCORNER", "ACS_URCORNER", "ACS_LLCORNER", "ACS_LRCORNER",
        "ACS_LTEE", "ACS_RTEE", "ACS_TTEE", "ACS_BTEE", "ACS_HLINE",
        "ACS_VLINE", "ACS_PLUS",

        "ACS_S1", "ACS_S9", "ACS_DIAMOND", "ACS_CKBOARD", "ACS_DEGREE",
        "ACS_PLMINUS", "ACS_BULLET",

        "ACS_LARROW", "ACS_RARROW", "ACS_UARROW", "ACS_DARROW",
        "ACS_BOARD", "ACS_LANTERN", "ACS_BLOCK"
#ifdef ACS_S3
        , "ACS_S3", "ACS_S7", "ACS_LEQUAL", "ACS_GEQUAL",
        "ACS_PI", "ACS_NEQUAL", "ACS_STERLING"
#endif
    };

    chtype acs_values[ACSNUM];

#if HAVE_WIDE
    cchar_t *wacs_values[] =
    {
        WACS_ULCORNER, WACS_URCORNER, WACS_LLCORNER, WACS_LRCORNER,
        WACS_LTEE, WACS_RTEE, WACS_TTEE, WACS_BTEE, WACS_HLINE,
        WACS_VLINE, WACS_PLUS,

        WACS_S1, WACS_S9, WACS_DIAMOND, WACS_CKBOARD, WACS_DEGREE,
        WACS_PLMINUS, WACS_BULLET,

        WACS_LARROW, WACS_RARROW, WACS_UARROW, WACS_DARROW, WACS_BOARD,
        WACS_LANTERN, WACS_BLOCK
# ifdef WACS_S3
        , WACS_S3, WACS_S7, WACS_LEQUAL, WACS_GEQUAL, WACS_PI,
        WACS_NEQUAL, WACS_STERLING
# endif
    };

    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};
#endif

    int i, tmarg = (LINES - 22) / 2;

    attrset(A_BOLD);
    mvaddstr(tmarg, (COLS - 23) / 2, "Alternate Character Set");
    attrset(A_NORMAL);

    tmarg += 3;

#define A(b,c) acs_values[b] = ACS_##c

    A(0,ULCORNER); A(1,URCORNER); A(2,LLCORNER); A(3,LRCORNER);
    A(4,LTEE);     A(5,RTEE);     A(6,TTEE);     A(7,BTEE);
    A(8,HLINE);    A(9,VLINE);    A(10,PLUS);    A(11,S1);
    A(12,S9);      A(13,DIAMOND); A(14,CKBOARD); A(15,DEGREE);

    A(16,PLMINUS); A(17,BULLET);  A(18,LARROW);  A(19,RARROW);
    A(20,UARROW);  A(21,DARROW);  A(22,BOARD);   A(23,LANTERN);
    A(24,BLOCK);
#ifdef ACS_S3
    A(25,S3);      A(26,S7);      A(27,LEQUAL);  A(28,GEQUAL);
    A(29,PI);      A(30,NEQUAL);  A(31,STERLING);
#endif

#undef A

    for (i = 0; i < ACSNUM; i++)
    {
        move((i % 8) * 2 + tmarg, (i / 8) * (COLS / 4) + (COLS / 8 - 7));
        addch(acs_values[i]);
        printw(" %s", acs_names[i]);
    }

    mvaddstr(tmarg + 18, 3, "Press any key to continue");
    getch();

#if HAVE_WIDE
    clear();

    attrset(A_BOLD);
    mvaddstr(tmarg - 3, (COLS - 28) / 2, "Wide Alternate Character Set");
    attrset(A_NORMAL);

    for (i = 0; i < ACSNUM; i++)
    {
        move((i % 8) * 2 + tmarg, (i / 8) * (COLS / 4) + (COLS / 8 - 7));
        add_wch(wacs_values[i]);
        printw(" W%s", acs_names[i]);
    }

    /* Spanish, Russian, Greek, Georgian */

    mvaddwstr(tmarg + 16, COLS / 8 - 5, L"Espa\xf1ol");
    mvaddwstr(tmarg + 16, 3 * (COLS / 8) - 5, russian);
    mvaddwstr(tmarg + 16, 5 * (COLS / 8) - 5, greek);
    mvaddwstr(tmarg + 16, 7 * (COLS / 8) - 5, georgian);

    mvaddstr(tmarg + 18, 3, "Press any key to continue");
    getch();
#endif
}
Exemplo n.º 26
0
int main(int argc, char **argv)
{
    int i, start, end, row, diff, flag, direction;
    const unsigned seed = (unsigned)time((time_t *)0);

#ifdef XCURSES
    Xinitscr(argc, argv);
#else
    initscr();
#endif
    nodelay(stdscr, TRUE);
    noecho();

    if (has_colors())
        start_color();

    for (i = 0; i < 8; i++)
        init_pair((short)i, color_table[i], COLOR_BLACK);

    srand(seed);
    flag = 0;

    while (getch() == ERR)      /* loop until a key is hit */
    {
        do {
            start = rand() % (COLS - 3);
            end = rand() % (COLS - 3);
            start = (start < 2) ? 2 : start;
            end = (end < 2) ? 2 : end;
            direction = (start > end) ? -1 : 1;
            diff = abs(start - end);

        } while (diff < 2 || diff >= LINES - 2);

        attrset(A_NORMAL);

        for (row = 0; row < diff; row++)
        {
            mvaddstr(LINES - row, row * direction + start,
                (direction < 0) ? "\\" : "/");

            if (flag++)
            {
                myrefresh();
                erase();
                flag = 0;
            }
        }

        if (flag++)
        {
            myrefresh();
            flag = 0;
        }

        explode(LINES - row, diff * direction + start);
        erase();
        myrefresh();
    }

    endwin();

    return 0;
}
Exemplo n.º 27
0
void main() {

	#define PALSIZE 8
	char *palette=" -=*O@@@@_";
	
	srand(time(NULL));
	// Needed
	initscr(); cbreak(); noecho();
	// Optional
	nonl(); intrflush(stdscr,FALSE); keypad(stdscr,FALSE);
	printf("%i x %i\n",COLS,LINES);

	if (has_colors()) {
		start_color();
		init_pair(0,COLOR_BLACK,COLOR_BLACK);
		init_pair(1,COLOR_BLUE,COLOR_BLACK);
		init_pair(2,COLOR_RED,COLOR_BLACK);
		init_pair(3,COLOR_MAGENTA,COLOR_BLACK);
		init_pair(4,COLOR_GREEN,COLOR_BLACK);
		init_pair(5,COLOR_CYAN,COLOR_BLACK);
		init_pair(6,COLOR_YELLOW,COLOR_BLACK);
		init_pair(7,COLOR_WHITE,COLOR_BLACK);
	}

	frames=0;

	cls();

	while (true) {
		
		// doSummat(&lonewriteToPoint);

		cenx = COLS / 2;
		ceny = LINES / 2;
		swirlang = (float)frames * M_PI / 800.0;
		// Zooming in and out over time
		spacePerSwirl = 0.08+0.03*cos(0.000638*(float)frames);

		move(0,0);
		attrset(COLOR_PAIR(2) | A_BOLD);

		for (int y = 0;y<LINES;y++) {
			for (int x = 0;x<COLS;x++) {

				float swirlHeight=getSwirlHeight(x,y);
				{
					int c=
							( getSwirlHeight(x+1,y+1) > 0 ? 1 : 0 )
						+	( getSwirlHeight(x,y+1) > 0 ? 1 : 0 )
						+	( getSwirlHeight(x+1,y) > 0 ? 1 : 0 )
						+	( getSwirlHeight(x,y) > 0 ? 1 : 0 )
						+	( getSwirlHeight((float)x+0.5,(float)y+0.5) > 0 ? 1 : 0 );
					char ch = palette[c];
					// mvaddch(y,x,32);
					addch(ch);
				}

			}
		}

		// int x = frames%COLS;
		// int y = (frames/COLS)%LINES;
		// move(y,x);
		// attrset(COLOR_PAIR(7));
		// char *str;
		// sprintf(str," (- %i -) ",frames);
		// addstr(str);
		// printf("%i ",frames);
		// move(1,0);
		// attrset(COLOR_PAIR(0));
		// printf("%i ",frames);
		wrefresh(stdscr);

		frames += 10;

	}

	cls();

	// Needed
	endwin();
}