void dcpu_initterm(dcpu *dcpu, bool display) { term.tickns = 1000000000 / DISPLAY_HZ; term.nexttick = dcpu_now(); term.keyns = 1000000000 / KBD_BAUD; term.nextkey = dcpu_now(); term.curborder = 0; term.nextborder = 0; term.vram = 0; term.keybufwrite = 0; term.keybufread = 0; term.kbdints = 0; // set up hardware descriptors device *kbd = dcpu_addhw(dcpu); kbd->id = 0x30cf7406; kbd->version = 1; kbd->mfr = 0x01220423; kbd->hwi = &kbd_hwi; kbd->tick = &kbd_tick; kbd->on_debug = NULL; if (display) { // TODO this is pretty hokey device *lem = dcpu_addhw(dcpu); lem->id = 0x7349f615; lem->version = 0x1802; lem->mfr = 0x1c6c8b36; lem->hwi = &lem_hwi; lem->tick = &lem_tick; lem->on_debug = &lem_redraw; } // set up curses... initscr(); start_color(); cbreak(); keypad(stdscr, true); term.border = subwin(stdscr, 14, 36, 0, 0); term.vidwin = subwin(stdscr, 12, 32, 1, 2); term.dbgwin = subwin(stdscr, LINES - (SCR_HEIGHT+3), COLS, SCR_HEIGHT+2, 0); keypad(term.vidwin, true); keypad(term.border, true); scrollok(term.dbgwin, true); keypad(term.dbgwin, true); // set up colors... if (COLORS > 8) { // nice terminals... int colors[] = {0, 4, 2, 6, 1, 5, 3, 7, 8, 12, 10, 14, 9, 13, 11, 15}; for (int i = 0; i < 16; i++) for (int j = 0; j < 16; j++) init_pair(color(i, j), colors[i], colors[j]); } else { // crappy terminals at least get something... int colors[] = {0, 4, 2, 6, 1, 5, 3, 7}; for (int i = 0; i < 8; i++) for (int j = 0; j < 8; j++) init_pair(color(i, j), colors[i], colors[j]); } dcpu_msg("terminal colors: %d, pairs %d, %s change colors: \n", COLORS, COLOR_PAIRS, can_change_color() ? "*can*" : "*cannot*"); }
void *InitRender(void) { int gcol[] = { COLOR_RED, COLOR_GREEN, COLOR_MAGENTA, COLOR_CYAN, }; int i; initscr(); cbreak(); noecho(); nodelay(stdscr, TRUE); curs_set(0); if (has_colors()) { fprintf(stderr, "Color console in use\n"); start_color(); init_pair(PC_PACMAN, COLOR_YELLOW, COLOR_BLACK); init_pair(PC_WALL, COLOR_BLUE, COLOR_BLACK); init_pair(PC_EDIBLE_GHOST, COLOR_MAGENTA, COLOR_BLACK); init_pair(PC_PILL, COLOR_CYAN, COLOR_BLACK); init_pair(PC_POWERPILL, COLOR_WHITE, COLOR_BLACK); init_pair(PC_WHITE, COLOR_WHITE, COLOR_BLACK); if (can_change_color()) { init_color(COLOR_GREEN, 1000,644,888); init_color(COLOR_MAGENTA, 1000,888,970); init_color(COLOR_CYAN, 1000,644,285); } else { fprintf(stderr, "Ghosts colors will not be accurate because TTY doesn't support init_color\n"); } for(i=0; i<MAX_GHOSTS; i++) init_pair(PC_GHOST+i, gcol[i%sizeof(gcol)], COLOR_BLACK); } else { fprintf(stderr, "Black and white console in use\n"); } return NULL; }
void initTT() { // initialize screen initscr(); if ((has_colors() == FALSE) && (can_change_color() == FALSE)) { endwin(); std::cout << "Your terminal does not support color" << std::endl; exit(1); } start_color(); use_default_colors(); init_pair(COLOR_ID_ERROR, COLOR_MAGENTA, -1); init_pair(COLOR_ID_DEFAULT, -1, -1); getmaxyx(stdscr, screenH, screenW); raw(); keypad(stdscr, TRUE); noecho(); // buffersize is odd if screen width is odd and vice versa buffersize = screenW*3/4; buffersize += (screenW % 2) ? ((buffersize % 2) + 1) : (buffersize % 2); resetStatistics(); srand((unsigned int)time(NULL)); }
TUI_BOOL t_can_change_colors() { if (can_change_color() == TRUE) return TUI_TRUE; else return TUI_FALSE; }
static void term_refresh() { // to set up a 256-color terminal, see: // http://push.cx/2008/256-color-xterms-in-ubuntu if (0 && can_change_color()) { int i; for (i = 0; i < 16; i++) { short r = palette[i].r * 1000; short g = palette[i].g * 1000; short b = palette[i].b * 1000; if (r < 0) r = 0; if (g < 0) g = 0; if (b < 0) b = 0; init_color(i + 1, r, g, b); } } if (0) { int i; short r, g, b; for (i = 0; i < 8; i++) { color_content(i, &r, &g, &b); palette[i].r = r * .001; palette[i].g = g * .001; palette[i].b = b * .001; } } if (colormode == coerce_256) { buffer_render_256(); } refresh(); }
void init_colored_cursing () { TRACEIN; if (has_colors() == false) { terminate_cursing(); fprintf(stderr, "Your terminal does not support colors.\n"); fail(); } if (can_change_color() == false) { terminate_cursing(); fprintf(stderr, "Your terminal does not support change_color.\n"); fail(); } start_color (); assert (COLOR_PAIRS > 10); /* RGB vals found in http://cloford.com/resources/colours/500col.htm */ init_color(BLUE1, 202, 225, 255); init_color(BLUE2, 72, 118, 255); init_color(BLUE3, 65, 105, 225); init_color(BLUE4, 61, 89, 171); init_color(BLUE5, 25, 25, 112); init_pair(COLPAIR4TEXT, COLOR_BLACK, -1); init_pair(COLPAIR1VAL, BLUE1, -1); init_pair(COLPAIR2VAL, BLUE2, -1); init_pair(COLPAIR3VAL, BLUE3, -1); init_pair(COLPAIR4VAL, BLUE4, -1); init_pair(COLPAIR5VAL, BLUE5, -1); attron(COLOR_PAIR(COLPAIR4TEXT)); TRACEOUT; }
PRIVATE void viewP_initColor() { short bg, fg, i; colorSupport = (has_colors() << 0) | (can_change_color() << 1); if (!colorSupport) return; start_color(); /* Colores por defecto en el '0' */ use_default_colors(); init_pair(0, -1, -1); /* Paleta de colores basicos, definidos en la cabezera */ init_color(0, 0, 0, 0); /* BLACK */ init_color(1, 1000, 0, 0); /* RED */ init_color(2, 0, 1000, 0); /* GREEN */ init_color(3, 1000, 1000, 0); /* YELLOW */ init_color(4, 0, 0, 1000); /* BLUE */ init_color(5, 1000, 0, 1000); /* MAGENTA */ init_color(6, 0, 1000, 1000); /* CYAN */ init_color(7, 1000, 1000, 1000); /* WHITE */ /* Inicializacion colores de usuario */ for (i = 0; i < 8; i++) viewG_defColor(i, 0, 0, 0); /* Creacion de paleta de colores (256 en total) */ for (bg=0x0; bg <= 0xF; bg++) for (fg=0x0; fg <= 0xF; fg++) { if (fg || bg) init_pair((short)((bg<<4)|fg), fg, bg); } }
int main() { WINDOW* win = initscr(); //start_color(); //waddch(win, '\n'); //waddch(win, '\n'); //wrefresh(win); endwin(); printf("%d %d %d\n", has_colors(), can_change_color(), COLOR_PAIRS); }
void curses_init_nhcolors() { #ifdef TEXTCOLOR if (has_colors()) { use_default_colors(); init_pair(1, COLOR_BLACK, -1); init_pair(2, COLOR_RED, -1); init_pair(3, COLOR_GREEN, -1); init_pair(4, COLOR_YELLOW, -1); init_pair(5, COLOR_BLUE, -1); init_pair(6, COLOR_MAGENTA, -1); init_pair(7, COLOR_CYAN, -1); init_pair(8, -1, -1); if (COLORS >= 16) { init_pair(9, COLOR_WHITE, -1); init_pair(10, COLOR_RED + 8, -1); init_pair(11, COLOR_GREEN + 8, -1); init_pair(12, COLOR_YELLOW + 8, -1); init_pair(13, COLOR_BLUE + 8, -1); init_pair(14, COLOR_MAGENTA + 8, -1); init_pair(15, COLOR_CYAN + 8, -1); init_pair(16, COLOR_WHITE + 8, -1); } if (can_change_color()) { init_color(COLOR_YELLOW, 500, 300, 0); init_color(COLOR_WHITE, 600, 600, 600); if (COLORS >= 16) { init_color(COLOR_RED + 8, 1000, 500, 0); init_color(COLOR_GREEN + 8, 0, 1000, 0); init_color(COLOR_YELLOW + 8, 1000, 1000, 0); init_color(COLOR_BLUE + 8, 0, 0, 1000); init_color(COLOR_MAGENTA + 8, 1000, 0, 1000); init_color(COLOR_CYAN + 8, 0, 1000, 1000); init_color(COLOR_WHITE + 8, 1000, 1000, 1000); #ifdef USE_DARKGRAY if (COLORS > 16) { init_color(CURSES_DARK_GRAY, 300, 300, 300); } #endif } else { /* Set flag to use bold for bright colors */ } } } #endif }
void initgui() { int f, b; initscr(); clear(); cbreak(); start_color(); if (!can_change_color()) { mvprintw(0, 0, "Your terminal does not support 256 colors, the screen " "output will not look like it's supposed to look like!"); } nodelay(stdscr, TRUE); noecho(); keypad(stdscr, TRUE); signal(SIGWINCH, handleresize); init_pair(1, COLOR_BLUE, COLOR_WHITE); cpuscreen = newwin(14, 34, 2, 1); status = newwin(14, 24, 2, 37); wbkgd(status, COLOR_PAIR(1)); wbkgd(cpuscreen, COLOR_PAIR(1)); curs_set(0); /* * Initialize colors */ init_color(127, 0, 0, 0); init_color(128, 0, 0, 666); init_color(129, 0, 666, 0); init_color(130, 0, 666, 666); init_color(131, 666, 0, 0); init_color(132, 666, 0, 666); init_color(133, 666, 333, 0); init_color(134, 1000, 1000, 1000); init_color(135, 333, 333, 333); init_color(136, 333, 333, 1000); init_color(137, 333, 1000, 333); init_color(138, 333, 1000, 1000); init_color(139, 1000, 333, 1000); init_color(140, 1000, 1000, 333); init_color(141, 1000, 1000, 1000); /* Initialize all possible color combinations */ for (f = 0; f < 16; ++f) for (b = 0; b < 16; b++) init_pair(((f << 4) | b) + 16, f+127, b+127); refresh(); wrefresh(cpuscreen); }
void init_term_gui(void) { /* Fix ESC key */ set_escdelay(25); initscr(); start_color(); cbreak(); noecho(); if (can_change_color()) { init_color(XS_COLOR_BLUE, 43, 180, 349); init_color(XS_COLOR_RED, 886, 27, 124); init_pair(XS_COLOR_PAIR_1, COLOR_WHITE, XS_COLOR_RED); init_pair(XS_COLOR_PAIR_2, COLOR_WHITE, XS_COLOR_BLUE); } else{ init_pair(XS_COLOR_PAIR_1, COLOR_WHITE, COLOR_RED); init_pair(XS_COLOR_PAIR_2, COLOR_WHITE, COLOR_BLUE); } /* int max_rows; */ /* int max_cols; */ /* getmaxyx(stdscr, max_rows, max_cols); */ show_recent_apps(); prepare_for_new_results(False); mvprintw(0, 0, "$"); mvwprintw(window, MAX_Y - 2, 0, "Loading paths..."); refresh(); field[0] = new_field( 1, // columns 20, // width 0, // pos y 2, // pos x 0, 0 ); /* Hide cursor */ curs_set(0); set_field_fore(field[0], COLOR_PAIR(XS_COLOR_PAIR_2)); field[1] = NULL; form = new_form(field); post_form(form); wrefresh(window); }
static void parse_color(char* color_string, struct colors* color) { if (color_string[0] == '#') { if (!can_change_color()) { cleanup_terminal_ncurses(); fprintf(stderr, "Your terminal can not change color definitions, " "please use one of the predefined colors.\n"); exit(EXIT_FAILURE); } color->color = COLOR_REDEFINITION; sscanf(++color_string, "%02hx%02hx%02hx", &color->R, &color->G, &color->B); } }
void init_color_schemes( void ) { if(can_change_color()) { init_color(COLOR_BLACK, 1000, 1000, 600); } init_pair(1, COLOR_BLACK, COLOR_RED); init_pair(2, COLOR_BLACK, COLOR_YELLOW); init_pair(3, COLOR_WHITE, COLOR_BLUE); init_pair(4, COLOR_BLACK, COLOR_WHITE); init_pair(5, COLOR_WHITE, COLOR_MAGENTA); init_pair(6, COLOR_BLACK, COLOR_CYAN); init_pair(7, COLOR_WHITE, COLOR_RED); init_pair(8, COLOR_WHITE, COLOR_WHITE); }
static int new_colordef (const int line_num, const char *name, const short red, const short green, const short blue, const int errors_are_fatal) { short color = find_color_name (name); if (color == -1) { if (errors_are_fatal) theme_parse_error (line_num, "bad color name"); return 0; } if (can_change_color()) init_color (color, red, green, blue); return 1; }
void NYView::initialiseAttributesMap() { attributesMapInitialised = true; if(!has_colors()) { yzWarning() << "Terminal doesn't have color capabilities, disabling syntax highlighting" << endl; return ; } bool changecolorok = (can_change_color() == true); yzWarning() << "Terminal can"; if(!changecolorok) { yzWarning() << " _not_"; } yzWarning() << " change colors" << endl; dbg() << "COLOR_PAIRS is : " << COLOR_PAIRS << endl; dbg() << "COLORS is : " << COLORS << endl; #undef MAP #define RAWMAP( nb, rawcolor, color, attributes ) \ YASSERT( ERR != init_pair( nb, (color), -1 /*COLOR_BLACK*/ ) ); \ mAttributesMap[(rawcolor)] = COLOR_PAIR((nb)) | (attributes); #define MAP( nb, qtcolor, color, attributes ) \ RAWMAP((nb),YColor(qtcolor).rgb() & RGB_MASK,(color),(attributes)) // first arg is the new rawcolor, second arg is the one that should be used #define ALIASMAP(rawcolor1,rawcolor2) \ YASSERT( ! mAttributesMap.contains( rawcolor1) ); \ mAttributesMap[(rawcolor1)] = mAttributesMap[(rawcolor2)]; MAP(1, Qt::red, COLOR_RED, A_BOLD); // red = 1, is used to display info on statusbar.. YASSERT(ERR != init_pair(2, COLOR_WHITE, COLOR_BLUE)); \ MAP(3, Qt::yellow, COLOR_YELLOW, A_BOLD); MAP(4, Qt::lightGray, COLOR_WHITE, A_NORMAL); MAP(5, Qt::gray, COLOR_WHITE, A_NORMAL); MAP(6, Qt::white, COLOR_WHITE, A_BOLD); MAP(7, Qt::magenta, COLOR_MAGENTA, A_BOLD); MAP(8, Qt::green, COLOR_GREEN, A_BOLD); MAP(9, Qt::cyan, COLOR_CYAN, A_BOLD); MAP(10, Qt::black, COLOR_BLACK, A_NORMAL); MAP(11, Qt::blue, COLOR_BLUE, A_BOLD); MAP(12, Qt::darkGreen, COLOR_GREEN, A_NORMAL); MAP(13, Qt::darkMagenta, COLOR_MAGENTA, A_NORMAL); MAP(14, Qt::darkCyan, COLOR_CYAN, A_NORMAL); // ALIASMAP(0xc0c0c0); // already here (lightGray) ALIASMAP(0xDD0000, 0xff0000); // red }
int startup(void) { int i; srand(time(0)); setlocale(LC_ALL, ""); initscr(); raw(); noecho(); noqiflush(); curs_set(0); atexit((void(*)(void))endwin); if(has_colors()) { start_color(); #ifdef COLORVALS if(can_change_color()) { num_colors = sizeof(colorvals) / sizeof(*colorvals); for(i = 0; i < num_colors && i < COLORS && i < COLOR_PAIRS; ++i) { init_color(i + 1, colorvals[i][0], colorvals[i][1], colorvals[i][2]); init_pair(i + 1, COLOR_BLACK, i + 1); } num_colors = i - 1; } else #endif { num_colors = 6; init_pair(1, COLOR_BLACK, COLOR_RED); init_pair(2, COLOR_BLACK, COLOR_GREEN); init_pair(3, COLOR_BLACK, COLOR_YELLOW); init_pair(4, COLOR_BLACK, COLOR_BLUE); init_pair(5, COLOR_BLACK, COLOR_MAGENTA); init_pair(6, COLOR_BLACK, COLOR_CYAN); } } return 0; }
/** * Setup the colors used in the game. */ static void init_colors(void) { if (has_colors() != FALSE) { start_color(); } if (can_change_color()) { init_color(COLOR_MAGENTA, 1000, 600, 1000); init_color(COLOR_GREY, 300, 300, 300); } /* define used color pairs */ init_pair(ColorMagenta, COLOR_MAGENTA, COLOR_BLACK); init_pair(ColorRed, COLOR_RED, COLOR_BLACK); init_pair(ColorYellow, COLOR_YELLOW, COLOR_BLACK); init_pair(ColorBlue, COLOR_BLUE, COLOR_BLACK); init_pair(ColorGrey, COLOR_GREY, COLOR_BLACK); }
int main(void) { initscr(); start_color(); if(!can_change_color()) addstr("This probably won't work, but anyway:\n"); init_color(NEW_COLOR,RED,GREEN,BLUE); init_pair(1,NEW_COLOR,COLOR_BLACK); attrset(COLOR_PAIR(1)); printw("This is the new color %d.\n",NEW_COLOR); refresh(); getch(); endwin(); return 0; }
void curses_cleanup() { #ifdef TEXTCOLOR if (has_colors() && can_change_color()) { init_color(COLOR_YELLOW, orig_yellow.r, orig_yellow.g, orig_yellow.b); init_color(COLOR_WHITE, orig_white.r, orig_white.g, orig_white.b); if (COLORS >= 16) { init_color(COLOR_RED + 8, orig_hired.r, orig_hired.g, orig_hired.b); init_color(COLOR_GREEN + 8, orig_higreen.r, orig_higreen.g, orig_higreen.b); init_color(COLOR_YELLOW + 8, orig_hiyellow.r, orig_hiyellow.g, orig_hiyellow.b); init_color(COLOR_BLUE + 8, orig_hiblue.r, orig_hiblue.g, orig_hiblue.b); init_color(COLOR_MAGENTA + 8, orig_himagenta.r, orig_himagenta.g, orig_himagenta.b); init_color(COLOR_CYAN + 8, orig_hicyan.r, orig_hicyan.g, orig_hicyan.b); init_color(COLOR_WHITE + 8, orig_hiwhite.r, orig_hiwhite.g, orig_hiwhite.b); # ifdef USE_DARKGRAY if (COLORS > 16) { init_color(CURSES_DARK_GRAY, orig_darkgray.r, orig_darkgray.g, orig_darkgray.b); } # endif } } #endif }
int main(int argc, char** argv) { initscr(); cbreak(); noecho(); curs_set(FALSE); if (has_colors() == TRUE) { start_color(); init_pair(1, COLOR_GREEN, COLOR_BLACK); init_pair(2, COLOR_YELLOW, COLOR_BLACK); init_pair(3, COLOR_MAGENTA, COLOR_BLACK); init_pair(4, COLOR_RED, COLOR_BLACK); init_pair(5, COLOR_BLACK, COLOR_BLACK); init_pair(6, COLOR_CYAN, COLOR_BLACK); if (can_change_color() == TRUE) { init_color(COLOR_WHITE, 1000, 0, 0); init_pair(7, COLOR_WHITE, COLOR_BLACK); } } int height = 20; int width = 30; WINDOW *mapwin; mapwin = create_newwin(height, width, (LINES - height) / 2, (COLS - width) / 2); Framework * fm = new Framework("Player_A", "Test_Dungeon", stdscr); fm->play(); endwin(); return 0; }
struct cols parse_color(char *col) { struct cols ret; if (col[0] == '#') { if (can_change_color() != TRUE) { cleanup_terminal_ncurses(); fprintf(stderr, "Your terminal can not change color definitions, please use one of the predefined colors.\n"); exit(EXIT_FAILURE); } // Set to -2 to indicate color_redefinition ret.col = -2; ++col; sscanf(col, "%02x%02x%02x", &ret.R, &ret.G, &ret.B); return ret; } else { //using predefined colors ret.col = 0; return ret; } }
void info(void) { NEWWIN *mywin = create_popup(19, 60); int line = 7; struct utsname uinfo; int proc_u_line; char *term = getenv("TERM"); mvwprintw(mywin -> win, 1, 2, "-=* MultiTail " VERSION " *=-"); mvwprintw(mywin -> win, 3, 2, "Written by [email protected]"); mvwprintw(mywin -> win, 4, 2, "Website: http://www.vanheusden.com/multitail/"); if (!use_colors) mvwprintw(mywin -> win, line++, 2, "Your terminal doesn't support colors"); if (uname(&uinfo) == -1) error_popup("Retrieving system information", -1, "uname() failed\n"); else { line++; mvwprintw(mywin -> win, line++, 2, "Running on:"); #ifdef _GNU_SOURCE mvwprintw(mywin -> win, line++, 2, "%s/%s %s %s", uinfo.nodename, uinfo.sysname, uinfo.machine, uinfo.domainname); #else mvwprintw(mywin -> win, line++, 2, "%s/%s %s", uinfo.nodename, uinfo.sysname, uinfo.machine); #endif mvwprintw(mywin -> win, line++, 2, "%s %s", uinfo.release, uinfo.version); line++; } if (has_colors()) mvwprintw(mywin -> win, line++, 2, "colors: %d, colorpairs: %d (%d), change colors: %s", COLORS, COLOR_PAIRS, cp.n_def, can_change_color()?"yes":"no"); else mvwprintw(mywin -> win, line++, 2, "Terminal does not support colors."); if (term) mvwprintw(mywin -> win, line++, 2, "Terminal size: %dx%d, terminal: %s", max_x, max_y, term); else mvwprintw(mywin -> win, line++, 2, "Terminal size: %dx%d", max_x, max_y); if (beep_interval > 0) mvwprintw(mywin -> win, line++, 2, "Did %d beeps.", did_n_beeps); proc_u_line = line++; escape_print(mywin, 16, 2, "_Press any key to exit this screen_"); #if defined(__FreeBSD__) || defined(linux) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__) || defined(sun) || defined(__sun) || defined(__GNU__) || defined(__CYGWIN__) for(;;) { dtime_t run_time = get_ts() - mt_started; #ifndef __CYGWIN__ double v1, v2, v3; get_load_values(&v1, &v2, &v3); mvwprintw(mywin -> win, 6, 2, "Current load of system: %f %f %f", v1, v2, v3); #endif if (run_time) { struct rusage usage; if (getrusage(RUSAGE_SELF, &usage) == -1) error_exit(TRUE, FALSE, "getrusage() failed\n"); mvwprintw(mywin -> win, proc_u_line, 2, "Runtime: %02d:%02d:%02d, avg.proc.usage: %.2f%% ints/s: %.1f", (int)(run_time / 3600), ((int)run_time / 60) % 60, (int)run_time % 60, ((double)usage.ru_utime.tv_sec + (double)usage.ru_utime.tv_usec / 1000000.0 + (double)usage.ru_stime.tv_sec + (double)usage.ru_stime.tv_usec / 1000000.0) * 100.0 / run_time, (double)total_wakeups / run_time); } mydoupdate(); if (wait_for_keypress(-1, popup_refresh_interval, mywin, 0) != -1) break; } #else mydoupdate(); wait_for_keypress(-1, 0, mywin, 0); #endif delete_popup(mywin); }
void interactive(machine *m) { /* Set up the ncurses interface */ ui_info ui; initscr(); start_color(); raw(); noecho(); keypad(stdscr, true); /* Figure out the level of color support, choose attributes accordingly */ if (has_colors()) { if (can_change_color()) { /* Best case, programmable colors */ init_color(CLR_WHITEGRAY, 800, 800, 800); /* dull text */ init_color(CLR_DARKGRAY, 400, 400, 400); /* highlighted metal */ init_color(CLR_DARKESTGRAY, 250, 250, 250); /* darkest metal */ init_color(CLR_BRIGHTRED, 1000, 400, 400); /* coded text */ init_pair(CP_WHEEL_PLAIN, CLR_WHITEGRAY, CLR_DARKESTGRAY); init_pair(CP_WHEEL_ACTIV, COLOR_WHITE, CLR_DARKGRAY); init_pair(CP_PLAIN, COLOR_WHITE, COLOR_BLACK); init_pair(CP_CODED, CLR_BRIGHTRED, COLOR_BLACK); init_pair(CP_BTN, COLOR_RED, CLR_DARKESTGRAY); init_pair(CP_BTNH, COLOR_RED, CLR_DARKGRAY); } else { /* Second best, 8 color ncurses */ init_pair(CP_WHEEL_PLAIN, COLOR_YELLOW, COLOR_BLUE); init_pair(CP_WHEEL_ACTIV, COLOR_WHITE, COLOR_RED); init_pair(CP_PLAIN, COLOR_WHITE, COLOR_BLACK); init_pair(CP_CODED, COLOR_RED, COLOR_BLACK); init_pair(CP_BTN, COLOR_RED, COLOR_BLUE); init_pair(CP_BTNH, COLOR_BLUE, COLOR_RED); } ui.attr_plain = COLOR_PAIR(CP_PLAIN); ui.attr_coded = COLOR_PAIR(CP_CODED); ui.attr_wheel_plain = COLOR_PAIR(CP_WHEEL_PLAIN); ui.attr_wheel_activ = COLOR_PAIR(CP_WHEEL_ACTIV) | A_BOLD; ui.attr_btn = COLOR_PAIR(CP_BTN); ui.attr_btnh = COLOR_PAIR(CP_BTNH); } else { /* No color fallback */ ui.attr_plain = A_NORMAL; ui.attr_coded = A_BOLD; ui.attr_wheel_plain = A_REVERSE; ui.attr_wheel_activ = A_REVERSE | A_BOLD | A_UNDERLINE; ui.attr_btn = A_REVERSE | A_BOLD; ui.attr_btnh = ui.attr_btn; } ui.attr_lbl = A_NORMAL; ui.attr_lblh = A_BOLD; ui.chosen_wheel = -1; /* Make the windows */ int topheight = 10 + m->wheelslots; int longestname = strlen("ring settings"); if (longestname < m->longest_wheelname) longestname = m->longest_wheelname; int topwidth = 4 * m->wheelslots + 1 + longestname; int namelen = wcslen(m->name); if (namelen > topwidth) topwidth = namelen; ui.w_wheels = newwin(topheight, topwidth, 0, COLS-topwidth); int botheight = ((LINES - topheight) / 3) * 3 - 1; int botwidth = COLS; ui.w_code = newwin(botheight, botwidth, topheight, 0); ui.w_pop = newwin(botheight, botwidth, topheight, 0); draw_wheels(m, &ui); bool enciphering = true; /* enchiper or dechiper */ wchar_t plaintext[MAXLINE+1]; /* typed/dechipered text */ wchar_t ciphertxt[MAXLINE+1]; /* typed/enchipered text */ memset(plaintext, 0, sizeof(wchar_t)*(MAXLINE+1)); memset(ciphertxt, 0, sizeof(wchar_t)*(MAXLINE+1)); int textpos = 0; int maxpos = COLS - 2 > MAXLINE ? MAXLINE : COLS - 2; curses_bug_workaround(); wmove(ui.w_code, 1, 1); /* main loop. The first event has to be the KEY_RESIZE, it creates the display! */ int rc = KEY_CODE_YES; wint_t wch = KEY_RESIZE; for (bool active = true; active; rc = active ? get_wch(&wch) : 0) { switch (rc) { case KEY_CODE_YES: /* specials */ switch (wch) { case KEY_F(1): highlight_wheel(m, &ui, 0); break; case KEY_F(2): highlight_wheel(m, &ui, 1); break; case KEY_F(3): highlight_wheel(m, &ui, 2); break; case KEY_F(4): highlight_wheel(m, &ui, 3); break; case KEY_F(5): highlight_wheel(m, &ui, 4); break; case KEY_F(6): highlight_wheel(m, &ui, 5); break; case KEY_F(7): highlight_wheel(m, &ui, 6); break; case KEY_F(8): highlight_wheel(m, &ui, 7); break; case KEY_F(9): highlight_wheel(m, &ui, 8); break; case KEY_LEFT: highlight_left(m, &ui); break; case KEY_RIGHT: highlight_right(m, &ui); break; case KEY_F(10): highlight_wheel(m, &ui, 9); break; case KEY_NPAGE: next_wheel(m, &ui); break; case KEY_UP: if (ui.chosen_wheel == -1) { /* switch to encoding */ enciphering = true; wmove(ui.w_code, 1, textpos+1); wnoutrefresh(ui.w_code); } else wheel_turn(m, &ui, -1); break; case KEY_DOWN: if (ui.chosen_wheel == -1) { /* switch to decoding */ enciphering = false; wmove(ui.w_code, 2, textpos+1); wnoutrefresh(ui.w_code); } else wheel_turn(m, &ui, 1); break; case KEY_RESIZE: /* user resized the xterm - redraw all! */ curses_bug_workaround();//Remove, and top window blanks out /* Must repaint all, as downsizing may blank the terminal */ /* Deal with the code wheel window */ botheight = ((LINES - topheight) / 3) * 3 - 1; botwidth = COLS; wresize(ui.w_code, botheight, botwidth); wresize(ui.w_pop, botheight, botwidth); int oldx = getbegx(ui.w_wheels); int newx = COLS-topwidth; mvwin(ui.w_wheels, 0, COLS-topwidth); /* move the window */ /* now clear out the exposed screen area */ if (newx > oldx) { int xlen = newx-oldx; char *spc = malloc(xlen+1); memset(spc, ' ', xlen); spc[xlen] = 0; for (int i=0; i < topheight; ++i) mvprintw(i, oldx, spc); free(spc); } wnoutrefresh(ui.w_wheels); curses_bug_workaround(); //Remove, and the cursor will misplaced when upsizing /* Now the code text window */ maxpos = COLS - 2 > MAXLINE ? MAXLINE : COLS - 2; if (textpos > maxpos) { leftcut(plaintext, textpos - maxpos, maxpos+1); leftcut(ciphertxt, textpos - maxpos, maxpos+1); textpos = maxpos; wattrset(ui.w_code, ui.attr_plain); mvwprintw(ui.w_code, 1, 1, "%ls", plaintext);wclrtoeol(ui.w_code); wattrset(ui.w_code, ui.attr_coded); mvwprintw(ui.w_code, 2, 1, "%ls", ciphertxt);wclrtoeol(ui.w_code); if (enciphering) wmove(ui.w_code, 1, textpos+1); } wnoutrefresh(ui.w_code); break; } break; case OK: if (iscntrl(wch)) switch (wch) { /* ctrl tv change ring settings */ case 20: ringstellung(m, &ui, -1); break; case 22: ringstellung(m, &ui, 1); break; /* quit on ctrl+c */ case 3: active = false; break; /* unselect wheel on enter */ case '\n': highlight_wheel(m, &ui, -1); wnoutrefresh(ui.w_code); break; } /* plain typing */ else { if (ui.chosen_wheel > -1) highlight_wheel(m, &ui, -1); /* Need a line break first? */ if (textpos >= maxpos) { /* add scrolling later !!! for now, just clear */ textpos = 0; memset(plaintext, 0, sizeof(wchar_t)*(MAXLINE+1)); memset(ciphertxt, 0, sizeof(wchar_t)*(MAXLINE+1)); if (enciphering) { wmove(ui.w_code, 2, textpos+1); wclrtoeol(ui.w_code); wmove(ui.w_code, 1, textpos+1); wclrtoeol(ui.w_code); } else { wmove(ui.w_code, 1, textpos+1); wclrtoeol(ui.w_code); wmove(ui.w_code, 2, textpos+1); wclrtoeol(ui.w_code); } } if (enciphering) { plaintext[textpos] = wch; ciphertxt[textpos] = encipher(m, wch, &ui); wattrset(ui.w_code, ui.attr_coded); mvwprintw(ui.w_code, 2, 1, "%ls", ciphertxt); wattrset(ui.w_code, ui.attr_plain); mvwprintw(ui.w_code, 1, 1, "%ls", plaintext); } else { ciphertxt[textpos] = wch; plaintext[textpos] = decipher(m, wch, &ui); wattrset(ui.w_code, ui.attr_plain); mvwprintw(ui.w_code, 1, 1, "%ls", plaintext); wattrset(ui.w_code, ui.attr_coded); mvwprintw(ui.w_code, 2, 1, "%ls", ciphertxt); } textpos++; wnoutrefresh(ui.w_wheels); wnoutrefresh(ui.w_code); break; } } doupdate(); } endwin(); }
/* * Prepare "curses" for use by the file "z-term.c" * * Installs the "hook" functions defined above, and then activates * the main screen "term", which clears the screen and such things. * * Someone should really check the semantics of "initscr()" */ errr init_gcu(int argc, char **argv) { int i; int num_term = MAX_TERM_DATA, next_win = 0; bool use_big_screen = FALSE; /* Parse args */ for (i = 1; i < argc; i++) { if (prefix(argv[i], "-b")) { use_big_screen = TRUE; continue; } plog_fmt("Ignoring option: %s", argv[i]); } /* Extract the normal keymap */ keymap_norm_prepare(); /* Initialize */ if (initscr() == NULL) return (-1); /* Activate hooks */ quit_aux = hook_quit; core_aux = hook_quit; /* Require standard size screen */ if ((LINES < 24) || (COLS < 80)) { quit(GAME_NAME " needs at least an 80x24 'curses' screen"); } #ifdef USE_GRAPHICS /* Set graphics flag */ use_graphics = arg_graphics; #endif #ifdef A_COLOR /*** Init the Color-pairs and set up a translation table ***/ /* Do we have color, and enough color, available? */ can_use_color = ((start_color() != ERR) && has_colors() && (COLORS >= 8) && (COLOR_PAIRS >= 8)); #ifdef REDEFINE_COLORS /* Can we change colors? */ can_fix_color = (can_use_color && can_change_color() && (COLORS >= 16) && (COLOR_PAIRS > 8)); #endif /* Attempt to use customized colors */ if (can_fix_color) { /* Prepare the color pairs */ for (i = 1; i <= 8; i++) { /* Reset the color */ if (init_pair(i, i - 1, 0) == ERR) { quit("Color pair init failed"); } /* Set up the colormap */ colortable[i - 1] = (COLOR_PAIR(i) | A_NORMAL); colortable[i + 7] = (COLOR_PAIR(i) | A_BRIGHT); } /* Take account of "gamma correction" XXX XXX XXX */ /* Prepare the "Angband Colors" */ Term_xtra_gcu_react(); } /* Attempt to use colors */ else if (can_use_color) { /* Color-pair 0 is *always* WHITE on BLACK */ /* Prepare the color pairs */ init_pair(1, COLOR_RED, COLOR_BLACK); init_pair(2, COLOR_GREEN, COLOR_BLACK); init_pair(3, COLOR_YELLOW, COLOR_BLACK); init_pair(4, COLOR_BLUE, COLOR_BLACK); init_pair(5, COLOR_MAGENTA, COLOR_BLACK); init_pair(6, COLOR_CYAN, COLOR_BLACK); init_pair(7, COLOR_BLACK, COLOR_BLACK); /* Prepare the "Angband Colors" -- Bright white is too bright */ colortable[0] = (COLOR_PAIR(7) | A_NORMAL); /* Black */ colortable[1] = (COLOR_PAIR(0) | A_NORMAL); /* White */ colortable[2] = (COLOR_PAIR(6) | A_NORMAL); /* Grey XXX */ colortable[3] = (COLOR_PAIR(1) | A_BRIGHT); /* Orange XXX */ colortable[4] = (COLOR_PAIR(1) | A_NORMAL); /* Red */ colortable[5] = (COLOR_PAIR(2) | A_NORMAL); /* Green */ colortable[6] = (COLOR_PAIR(4) | A_NORMAL); /* Blue */ colortable[7] = (COLOR_PAIR(3) | A_NORMAL); /* Umber */ colortable[8] = (COLOR_PAIR(7) | A_BRIGHT); /* Dark-grey XXX */ colortable[9] = (COLOR_PAIR(6) | A_BRIGHT); /* Light-grey XXX */ colortable[10] = (COLOR_PAIR(5) | A_NORMAL); /* Purple */ colortable[11] = (COLOR_PAIR(3) | A_BRIGHT); /* Yellow */ colortable[12] = (COLOR_PAIR(5) | A_BRIGHT); /* Light Red XXX */ colortable[13] = (COLOR_PAIR(2) | A_BRIGHT); /* Light Green */ colortable[14] = (COLOR_PAIR(4) | A_BRIGHT); /* Light Blue */ colortable[15] = (COLOR_PAIR(3) | A_NORMAL); /* Light Umber XXX */ } #endif /*** Low level preparation ***/ #ifdef USE_GETCH /* Paranoia -- Assume no waiting */ nodelay(stdscr, FALSE); #endif /* Prepare */ cbreak(); noecho(); nonl(); /* Extract the game keymap */ keymap_game_prepare(); /*** Now prepare the term(s) ***/ /* Big screen -- one big term */ if (use_big_screen) { /* Create a term */ term_data_init_gcu(&data[0], LINES, COLS, 0, 0); /* Remember the term */ windows[0].term = &data[0].t; } /* No big screen -- create as many term windows as possible */ else { /* Create several terms */ for (i = 0; i < num_term; i++) { int rows, cols, y, x; /* Decide on size and position */ switch (i) { /* Upper left */ case 0: { rows = 24; cols = 80; y = x = 0; break; } /* Lower left */ case 1: { rows = LINES - 25; cols = 80; y = 25; x = 0; break; } /* Upper right */ case 2: { rows = 24; cols = COLS - 81; y = 0; x = 81; break; } /* Lower right */ case 3: { rows = LINES - 25; cols = COLS - 81; y = 25; x = 81; break; } /* XXX */ default: { rows = cols = y = x = 0; break; } } /* Skip non-existant windows */ if (rows <= 0 || cols <= 0) continue; /* Create a term */ term_data_init_gcu(&data[next_win], rows, cols, y, x); /* Remember the term */ windows[next_win].term = &data[next_win].t; /* One more window */ next_win++; } } /* Activate the "Angband" window screen */ Term_activate(&data[0].t); /* Remember the active screen */ term_screen = &data[0].t; /* Success */ return (0); }
/* * Prepare "curses" for use by the file "z-term.c" * * Installs the "hook" functions defined above, and then activates * the main screen "term", which clears the screen and such things. * * Someone should really check the semantics of "initscr()" */ errr init_gcu(int argc, char **argv) { int i; int num_term = MAX_TERM_DATA, next_win = 0; bool use_big_screen = FALSE; /* Parse args */ for (i = 1; i < argc; i++) { if (prefix(argv[i], "-b")) { use_big_screen = TRUE; continue; } plog_fmt("Ignoring option: %s", argv[i]); } /* Extract the normal keymap */ keymap_norm_prepare(); /* Initialize */ if (initscr() == NULL) return (-1); /* Activate hooks */ quit_aux = hook_quit; core_aux = hook_quit; /* Require standard size screen */ if ((LINES < 24) || (COLS < 80)) { quit("Angband needs at least an 80x24 'curses' screen"); } #ifdef USE_GRAPHICS /* Set graphics */ if (arg_graphics) { use_graphics = GRAPHICS_PSEUDO; ANGBAND_GRAF = "pseudo"; } #endif /* USE_GRAPHICS */ #ifdef A_COLOR /*** Init the Color-pairs and set up a translation table ***/ /* Do we have color, and enough color, available? */ can_use_color = ((start_color() != ERR) && has_colors() && (COLORS >= 8) && (COLOR_PAIRS >= 8)); #ifdef REDEFINE_COLORS /* Can we change colors? */ can_fix_color = (can_use_color && can_change_color() && (COLORS >= 16) && (COLOR_PAIRS > 8)); #endif /* Attempt to use customized colors */ if (can_fix_color) { /* Prepare the color pairs */ for (i = 1; i <= 8; i++) { /* Reset the color */ if (init_pair(i, i - 1, 0) == ERR) { quit("Color pair init failed"); } /* Set up the colormap */ colortable[i - 1] = (COLOR_PAIR(i) | A_NORMAL); colortable[i + 7] = (COLOR_PAIR(i) | A_BRIGHT); } /* Take account of "gamma correction" XXX XXX XXX */ /* Prepare the "Angband Colors" */ Term_xtra_gcu_react(); } /* Attempt to use colors */ else if (can_use_color) { /* Color-pair 0 is *always* WHITE on BLACK */ /* Prepare the color pairs */ init_pair(1, COLOR_RED, COLOR_BLACK); init_pair(2, COLOR_GREEN, COLOR_BLACK); init_pair(3, COLOR_YELLOW, COLOR_BLACK); init_pair(4, COLOR_BLUE, COLOR_BLACK); init_pair(5, COLOR_MAGENTA, COLOR_BLACK); init_pair(6, COLOR_CYAN, COLOR_BLACK); init_pair(7, COLOR_BLACK, COLOR_BLACK); /* Prepare the colors */ colortable[0] = (COLOR_PAIR(7) | A_NORMAL); /* Black */ colortable[1] = (COLOR_PAIR(0) | A_BRIGHT); /* White */ colortable[2] = (COLOR_PAIR(0) | A_NORMAL); /* Grey XXX */ colortable[3] = (COLOR_PAIR(1) | A_BRIGHT); /* Orange XXX */ colortable[4] = (COLOR_PAIR(1) | A_NORMAL); /* Red */ colortable[5] = (COLOR_PAIR(2) | A_NORMAL); /* Green */ colortable[6] = (COLOR_PAIR(4) | A_NORMAL); /* Blue */ colortable[7] = (COLOR_PAIR(3) | A_NORMAL); /* Umber */ colortable[8] = (COLOR_PAIR(7) | A_BRIGHT); /* Dark-grey XXX */ colortable[9] = (COLOR_PAIR(0) | A_NORMAL); /* Light-grey XXX */ colortable[10] = (COLOR_PAIR(5) | A_NORMAL); /* Purple */ colortable[11] = (COLOR_PAIR(3) | A_BRIGHT); /* Yellow */ colortable[12] = (COLOR_PAIR(5) | A_BRIGHT); /* Light Red XXX */ colortable[13] = (COLOR_PAIR(2) | A_BRIGHT); /* Light Green */ colortable[14] = (COLOR_PAIR(4) | A_BRIGHT); /* Light Blue */ colortable[15] = (COLOR_PAIR(3) | A_NORMAL); /* Light Umber XXX */ } #endif /*** Low level preparation ***/ #ifdef USE_GETCH /* Paranoia -- Assume no waiting */ nodelay(stdscr, FALSE); #endif /* Prepare */ cbreak(); noecho(); nonl(); /* Extract the game keymap */ keymap_game_prepare(); /*** Now prepare the term(s) ***/ /* Big screen -- one big term */ if (use_big_screen) { /* Create a term */ term_data_init_gcu(&data[0], LINES, COLS, 0, 0); /* Remember the term */ angband_term[0] = &data[0].t; } /* No big screen -- create as many term windows as possible */ else { /* * If we have a REALLY big screen, try to put any * extra real estate into the upper-left window. * Hack -- these constants rely on a-priori knowledge * of the sort of things that go in the windows. * * This patch is by 'bron' from the Angband Forum * under the directions: 'Feel free to use this (or not) as you see fit.' */ /* Minimum size for UpperLeft window */ const int ul_min_rows = 24; const int ul_min_cols = 80; /* Maximum (useful) columns for UpperRight window */ const int ur_max_cols = 80; /* Maximum (useful) rows for LowerLeft window */ const int ll_max_rows = 26; /* Actual size of UpperLeft window */ int ul_rows = MAX(ul_min_rows, LINES - (ll_max_rows + 1)); int ul_cols = MAX(ul_min_cols, COLS - (ur_max_cols + 1)); /* Create several terms */ for (i = 0; i < num_term; i++) { int rows, cols, y, x; /* Decide on size and position */ switch (i) { /* Upper left */ case 0: { rows = ul_rows; cols = ul_cols; y = x = 0; break; } /* Lower left */ case 1: { rows = LINES - (ul_rows + 1); cols = ul_cols; y = ul_rows + 1; x = 0; break; } /* Upper right */ case 2: { rows = ul_rows; cols = COLS - (ul_cols + 1); y = 0; x = ul_cols + 1; break; } /* Lower right */ case 3: { rows = LINES - (ul_rows + 1); cols = COLS - (ul_cols + 1); y = ul_rows + 1; x = ul_cols + 1; break; } /* XXX */ default: { rows = cols = y = x = 0; break; } } /* Skip non-existant windows */ if (rows <= 0 || cols <= 0) continue; /* Create a term */ term_data_init_gcu(&data[next_win], rows, cols, y, x); /* Remember the term */ angband_term[next_win] = &data[next_win].t; /* One more window */ next_win++; } } /* Activate the "Angband" window screen */ Term_activate(&data[0].t); /* Remember the active screen */ term_screen = &data[0].t; /* Success */ return (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); #ifdef CHTYPE_LONG #if( CHTYPE_LONG >= 2) /* "non-standard" 64-bit chtypes */ attrset(A_ITALIC); mvprintw( tmarg + 15, col3, "Italic"); attrset(A_ITALIC | A_BLINK); mvprintw( tmarg + 15, col4, "Italic Blink"); 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"); #endif #endif attrset(A_BOLD); mvprintw( tmarg + 16, col3, "Bold"); attrset(A_BLINK); mvprintw( tmarg + 17, col3, "Blink"); attrset(A_BLINK | A_BOLD); mvprintw( tmarg + 16, col4, "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); } #ifdef A_LEFTLINE attrset( A_LEFTLINE); mvaddstr( tmarg + 17, col1, "A_LEFTLINE"); #endif #ifdef A_UNDERLINE attrset( A_UNDERLINE); mvaddstr( tmarg + 18, col1, "A_UNDERLINE"); #endif #ifdef A_RIGHTLINE attrset( A_RIGHTLINE); mvaddstr( tmarg + 19, col1, "A_RIGHTLINE"); #endif # 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); }
void console_init_graphics(Console* con, point resolution, font* fnt) { (void) resolution; (void) fnt; char org_term[64]; struct NcConsole *self = &con->backend.nc; snprintf(org_term, sizeof org_term, "%s", getenv("TERM")); if(!strcmp(org_term, "xterm")) { setenv("TERM", "xterm-256color", 1); self->flags |= NC_SUPPORTSCOLORREADER; } else if(!strcmp(org_term, "rxvt-unicode")) { setenv("TERM", "rxvt-unicode-256color", 1); self->flags |= NC_SUPPORTSCOLORREADER; } else if(!strcmp(org_term, "xterm-256color")) { self->flags |= NC_SUPPORTSCOLORREADER; } self->active.fgcol = -1; self->active.fgcol = -1; self->lastattr = 0; console_inittables(con); initscr(); noecho(); cbreak(); keypad(stdscr, TRUE); nonl(); // get return key events // the ncurses table is apparently only initialised after initscr() oslt ncurses_chartab_init(); #ifdef CONSOLE_DEBUG dbg = fopen("console.log", "w"); #endif if(!getenv("CONCOL_NO_COLORS")) { if (has_colors()) self->flags |= NC_HASCOLORS; } if (self_hasColors(self) && can_change_color()) self->flags |= NC_CANCHANGECOLORS; if (self_hasColors(self)) start_color(); self->maxcolors = get_maxcolors(org_term); if (self_canChangeColors(self)) console_savecolors(self); if(mousemask(ALL_MOUSE_EVENTS | BUTTON1_PRESSED | BUTTON2_PRESSED | BUTTON3_PRESSED | BUTTON1_RELEASED | BUTTON2_RELEASED | BUTTON3_RELEASED | REPORT_MOUSE_POSITION | BUTTON_SHIFT | BUTTON_ALT | BUTTON_CTRL, NULL) != (mmask_t) ERR) { mouseinterval(0) /* prevent ncurses from making click events. this way we always get an event for buttondown and up. we won't get any mouse movement events either way. */; self->flags |= NC_HASMOUSE; } PDEBUG("hasmouse: %d\n", self_hasMouse(self)); self->lastattr = 0; self->maxcolor = 0; self->lastused.fgcol = -1; self->lastused.bgcol = -1; getmaxyx(stdscr, con->dim.y, con->dim.x); }
void curses_toggle_color_attr(WINDOW *win, int color, int attr, int onoff) { #ifdef TEXTCOLOR int curses_color; /* Map color disabled */ if ((!iflags.wc_color) && (win == mapwin)) { return; } /* GUI color disabled */ if ((!iflags.wc2_guicolor) && (win != mapwin)) { return; } if (color == 0) /* make black fg visible */ { #ifdef USE_DARKGRAY if (can_change_color() && (COLORS > 16)) { color = CURSES_DARK_GRAY - 1; } else /* Use bold for a bright black */ { wattron(win, A_BOLD); } #else color = CLR_BLUE; #endif /* USE_DARKGRAY */ } curses_color = color + 1; if (COLORS < 16) { if (curses_color > 8) curses_color -= 8; } if (onoff == ON) /* Turn on color/attributes */ { if (color != NONE) { if ((color > 7) && (COLORS < 16)) { wattron(win, A_BOLD); } wattron(win, COLOR_PAIR(curses_color)); } if (attr != NONE) { wattron(win, attr); } } else /* Turn off color/attributes */ { if (color != NONE) { if ((color > 7) && (COLORS < 16)) { wattroff(win, A_BOLD); } #ifdef USE_DARKGRAY if ((color == 0) && (!can_change_color() || (COLORS <= 16))) { wattroff(win, A_BOLD); } #else if (iflags.use_inverse) { wattroff(win, A_REVERSE); } #endif /* DARKGRAY */ wattroff(win, COLOR_PAIR(curses_color)); } if (attr != NONE) { wattroff(win, attr); } } #endif /* TEXTCOLOR */ }
void curses_init_nhcolors() { #ifdef TEXTCOLOR if (has_colors()) { use_default_colors(); init_pair(1, COLOR_BLACK, -1); init_pair(2, COLOR_RED, -1); init_pair(3, COLOR_GREEN, -1); init_pair(4, COLOR_YELLOW, -1); init_pair(5, COLOR_BLUE, -1); init_pair(6, COLOR_MAGENTA, -1); init_pair(7, COLOR_CYAN, -1); init_pair(8, -1, -1); if (COLORS >= 16) { init_pair(9, COLOR_WHITE, -1); init_pair(10, COLOR_RED + 8, -1); init_pair(11, COLOR_GREEN + 8, -1); init_pair(12, COLOR_YELLOW + 8, -1); init_pair(13, COLOR_BLUE + 8, -1); init_pair(14, COLOR_MAGENTA + 8, -1); init_pair(15, COLOR_CYAN + 8, -1); init_pair(16, COLOR_WHITE + 8, -1); } if (can_change_color()) { /* Preserve initial terminal colors */ color_content(COLOR_YELLOW, &orig_yellow.r, &orig_yellow.g, &orig_yellow.b); color_content(COLOR_WHITE, &orig_white.r, &orig_white.g, &orig_white.b); /* Set colors to appear as NetHack expects */ init_color(COLOR_YELLOW, 500, 300, 0); init_color(COLOR_WHITE, 600, 600, 600); if (COLORS >= 16) { /* Preserve initial terminal colors */ color_content(COLOR_RED + 8, &orig_hired.r, &orig_hired.g, &orig_hired.b); color_content(COLOR_GREEN + 8, &orig_higreen.r, &orig_higreen.g, &orig_higreen.b); color_content(COLOR_YELLOW + 8, &orig_hiyellow.r, &orig_hiyellow.g, &orig_hiyellow.b); color_content(COLOR_BLUE + 8, &orig_hiblue.r, &orig_hiblue.g, &orig_hiblue.b); color_content(COLOR_MAGENTA + 8, &orig_himagenta.r, &orig_himagenta.g, &orig_himagenta.b); color_content(COLOR_CYAN + 8, &orig_hicyan.r, &orig_hicyan.g, &orig_hicyan.b); color_content(COLOR_WHITE + 8, &orig_hiwhite.r, &orig_hiwhite.g, &orig_hiwhite.b); /* Set colors to appear as NetHack expects */ init_color(COLOR_RED + 8, 1000, 500, 0); init_color(COLOR_GREEN + 8, 0, 1000, 0); init_color(COLOR_YELLOW + 8, 1000, 1000, 0); init_color(COLOR_BLUE + 8, 0, 0, 1000); init_color(COLOR_MAGENTA + 8, 1000, 0, 1000); init_color(COLOR_CYAN + 8, 0, 1000, 1000); init_color(COLOR_WHITE + 8, 1000, 1000, 1000); #ifdef USE_DARKGRAY if (COLORS > 16) { init_color(CURSES_DARK_GRAY, 300, 300, 300); } #endif } else { /* Set flag to use bold for bright colors */ } } } #endif }
/* * Prepare "curses" for use by the file "z-term.c" * * Installs the "hook" functions defined above, and then activates * the main screen "term", which clears the screen and such things. * * Someone should really check the semantics of "initscr()" */ errr init_gcu(int argc, char **argv) { int i; int rows, cols, y, x; int next_win = 0; /* Initialize info about terminal capabilities */ termtype = getenv("TERM"); loaded_terminfo = termtype && tgetent(0, termtype) == 1; /* Let's learn about our terminal */ use_alt_charset = loaded_terminfo && tgetstr("acs_chars", NULL); /* Parse args */ for (i = 1; i < argc; i++) { if (prefix(argv[i], "-b")) use_big_screen = TRUE; #ifdef A_ALTCHARSET else if (prefix(argv[i], "-a")) use_alt_charset = 0; else if (prefix(argv[i], "-g")) use_alt_charset = 1; #endif else plog_fmt("Ignoring option: %s", argv[i]); } /* Extract the normal keymap */ keymap_norm_prepare(); /* We do it like this to prevent a link error with curseses that * lack ESCDELAY. */ if (!getenv("ESCDELAY")) putenv("ESCDELAY=20"); /* Initialize */ if (initscr() == NULL) return (-1); /* Activate hooks */ quit_aux = hook_quit; /* Require standard size screen */ if ((LINES < 24) || (COLS < 80)) { quit("Angband needs at least an 80x24 'curses' screen"); } #ifdef A_COLOR /*** Init the Color-pairs and set up a translation table ***/ /* Do we have color, and enough color, available? */ can_use_color = ((start_color() != ERR) && has_colors() && (COLORS >= 8) && (COLOR_PAIRS >= 8)); #ifdef HAVE_USE_DEFAULT_COLORS /* Should we use curses' "default color" */ if (use_default_colors() == OK) bg_color = -1; #endif #ifdef HAVE_CAN_CHANGE_COLOR /* Can we change colors? */ can_fix_color = (can_use_color && can_change_color() && orig_colors && (COLORS >= 16) && (COLOR_PAIRS > 8)); #endif /* Attempt to use customized colors */ if (can_fix_color) { /* Prepare the color pairs */ for (i = 0; i < (BASIC_COLORS / 2); i++) { /* Reset the color */ if (init_pair(i + 1, i, bg_color) == ERR) { quit("Color pair init failed"); } /* Set up the colormap */ colortable[i] = (COLOR_PAIR(i + 1) | A_NORMAL); colortable[i + (BASIC_COLORS / 2)] = (COLOR_PAIR(i + 1) | A_BRIGHT); } /* Take account of "gamma correction" XXX XXX XXX */ /* Prepare the "Angband Colors" */ Term_xtra_gcu_react(); } /* Attempt to use colors */ else if (can_use_color) { /* Prepare the color pairs */ /* PAIR_WHITE (pair 0) is *always* WHITE on BLACK */ init_pair(PAIR_RED, COLOR_RED, bg_color); init_pair(PAIR_GREEN, COLOR_GREEN, bg_color); init_pair(PAIR_YELLOW, COLOR_YELLOW, bg_color); init_pair(PAIR_BLUE, COLOR_BLUE, bg_color); init_pair(PAIR_MAGENTA, COLOR_MAGENTA, bg_color); init_pair(PAIR_CYAN, COLOR_CYAN, bg_color); init_pair(PAIR_BLACK, COLOR_BLACK, bg_color); /* Prepare the colors */ colortable[TERM_DARK] = (COLOR_PAIR(PAIR_BLACK)); colortable[TERM_WHITE] = (COLOR_PAIR(PAIR_WHITE) | A_BRIGHT); colortable[TERM_SLATE] = (COLOR_PAIR(PAIR_WHITE)); colortable[TERM_ORANGE] = (COLOR_PAIR(PAIR_RED) | A_BRIGHT); colortable[TERM_RED] = (COLOR_PAIR(PAIR_RED)); colortable[TERM_GREEN] = (COLOR_PAIR(PAIR_GREEN)); colortable[TERM_BLUE] = (COLOR_PAIR(PAIR_BLUE)); colortable[TERM_UMBER] = (COLOR_PAIR(PAIR_YELLOW)); colortable[TERM_L_DARK] = (COLOR_PAIR(PAIR_BLACK) | A_BRIGHT); colortable[TERM_L_WHITE] = (COLOR_PAIR(PAIR_WHITE)); colortable[TERM_L_PURPLE] = (COLOR_PAIR(PAIR_MAGENTA)); colortable[TERM_YELLOW] = (COLOR_PAIR(PAIR_YELLOW) | A_BRIGHT); colortable[TERM_L_RED] = (COLOR_PAIR(PAIR_MAGENTA) | A_BRIGHT); colortable[TERM_L_GREEN] = (COLOR_PAIR(PAIR_GREEN) | A_BRIGHT); colortable[TERM_L_BLUE] = (COLOR_PAIR(PAIR_BLUE) | A_BRIGHT); colortable[TERM_L_UMBER] = (COLOR_PAIR(PAIR_YELLOW)); colortable[TERM_PURPLE] = (COLOR_PAIR(PAIR_MAGENTA)); colortable[TERM_VIOLET] = (COLOR_PAIR(PAIR_MAGENTA)); colortable[TERM_TEAL] = (COLOR_PAIR(PAIR_CYAN)); colortable[TERM_MUD] = (COLOR_PAIR(PAIR_YELLOW)); colortable[TERM_L_YELLOW] = (COLOR_PAIR(PAIR_YELLOW | A_BRIGHT)); colortable[TERM_MAGENTA] = (COLOR_PAIR(PAIR_MAGENTA | A_BRIGHT)); colortable[TERM_L_TEAL] = (COLOR_PAIR(PAIR_CYAN | A_BRIGHT)); colortable[TERM_L_VIOLET] = (COLOR_PAIR(PAIR_MAGENTA | A_BRIGHT)); colortable[TERM_L_PINK] = (COLOR_PAIR(PAIR_MAGENTA | A_BRIGHT)); colortable[TERM_MUSTARD] = (COLOR_PAIR(PAIR_YELLOW)); colortable[TERM_BLUE_SLATE] = (COLOR_PAIR(PAIR_BLUE)); colortable[TERM_DEEP_L_BLUE] = (COLOR_PAIR(PAIR_BLUE)); } #endif #ifdef A_ALTCHARSET /* Build a quick access table for the "alternate character set". */ if (use_alt_charset) { acs_table[1] = ACS_DIAMOND; acs_table[16] = ACS_S1; acs_table[2] = ACS_CKBOARD; acs_table[18] = ACS_HLINE; acs_table[7] = ACS_DEGREE; acs_table[20] = ACS_S9; acs_table[8] = ACS_PLMINUS; acs_table[21] = ACS_LTEE; acs_table[11] = ACS_LRCORNER; acs_table[22] = ACS_RTEE; acs_table[12] = ACS_URCORNER; acs_table[23] = ACS_BTEE; acs_table[13] = ACS_ULCORNER; acs_table[24] = ACS_TTEE; acs_table[14] = ACS_LLCORNER; acs_table[25] = ACS_VLINE; acs_table[15] = ACS_PLUS; acs_table[31] = ACS_BULLET; } #endif /*** Low level preparation ***/ /* Paranoia -- Assume no waiting */ nodelay(stdscr, FALSE); /* Prepare */ cbreak(); noecho(); nonl(); /* Tell curses to rewrite escape sequences to KEY_UP and friends */ keypad(stdscr, TRUE); /* Extract the game keymap */ keymap_game_prepare(); /*** Now prepare the term(s) ***/ for (i = 0; i < MAX_TERM_DATA; i++) { if (use_big_screen && i > 0) break; /* Get the terminal dimensions; if the user asked for a big screen * then we'll put the whole screen in term 0; otherwise we'll divide * it amongst the available terms */ get_gcu_term_size(i, &rows, &cols, &y, &x); /* Skip non-existant windows */ if (rows <= 0 || cols <= 0) continue; /* Create a term */ term_data_init_gcu(&data[next_win], rows, cols, y, x); /* Remember the term */ angband_term[next_win] = &data[next_win].t; /* One more window */ next_win++; } /* Activate the "Angband" window screen */ Term_activate(&data[0].t); /* Remember the active screen */ term_screen = &data[0].t; /* Success */ return (0); }