short find_color_pair(short fg,short bg) { short fg_color,bg_color; int i; if(has_colors()==FALSE) return -1; for(i=1;i<COLOR_PAIRS;i++) { pair_content(i,&fg_color,&bg_color); if(fg_color==fg && bg_color==bg) break; } if(i==COLOR_PAIRS) return -1; return i; }
void InitUI() { initscr(); if(has_colors()) { start_color(); init_pair(1, COLOR_BLACK, COLOR_WHITE); init_pair(2, COLOR_BLACK, COLOR_CYAN); init_pair(3, COLOR_BLACK, COLOR_GREEN); init_pair(4, COLOR_BLACK, COLOR_YELLOW); init_pair(5, COLOR_BLACK, COLOR_RED); init_pair(6, COLOR_BLACK, COLOR_MAGENTA); init_pair(7, COLOR_BLACK, COLOR_BLUE); init_pair(8, COLOR_WHITE, COLOR_BLACK); } cbreak(); noecho(); keypad(stdscr, TRUE); }
/* * Setup and run the interactive portion of the program. */ void screen_start(void) { if (initscr() == 0) /* should return a "WINDOW *" */ exit(EXIT_FAILURE); #if HAVE_KEYPAD keypad(stdscr, TRUE); #endif #if HAVE_DEFINE_KEY define_key("\033Ok", '+'); define_key("\033Ol", ','); define_key("\033Om", '-'); define_key("\033On", '.'); define_key("\033Op", '0'); define_key("\033Oq", '1'); define_key("\033Or", '2'); define_key("\033Os", '3'); define_key("\033Ot", '4'); define_key("\033Ou", '5'); define_key("\033Ov", '6'); define_key("\033Ow", '7'); define_key("\033Ox", '8'); define_key("\033Oy", '9'); define_key("\033OM", '\n'); #endif #if defined(COLOR_BLUE) && defined(COLOR_WHITE) && HAVE_COLOR_PAIR if (has_colors()) { start_color(); init_pair(1, COLOR_WHITE, COLOR_BLUE); /* normal */ SetColors(1); #if HAVE_BKGD bkgd(CURRENT_COLOR); #endif } #endif #if HAVE_TYPEAHEAD typeahead(-1); /* disable typeahead */ #endif #if SYS_MSDOS && defined(F_GRAY) && defined(B_BLUE) wattrset(stdscr, F_GRAY | B_BLUE); /* patch for old PD-Curses */ #endif raw(); nonl(); noecho(); set_screensize(); }
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; }
int main() { int i; initscr(); if (!has_colors()) { endwin(); fprintf(stderr, "Error - no color support on this terminal\n"); exit(1); } if (start_color() != OK) { endwin(); fprintf(stderr, "Error - could not initialize colors\n"); exit(2); } /* We can now print out the allowed number of colors and color pairs. We create seven color pairs and display them one at a time. */ clear(); mvprintw(5, 5, "There are %d COLORS, and %d COLOR_PAIRS available", COLORS, COLOR_PAIRS); refresh(); init_pair(1, COLOR_RED, COLOR_BLACK); init_pair(2, COLOR_RED, COLOR_GREEN); init_pair(3, COLOR_GREEN, COLOR_RED); init_pair(4, COLOR_YELLOW, COLOR_BLUE); init_pair(5, COLOR_BLACK, COLOR_WHITE); init_pair(6, COLOR_MAGENTA, COLOR_BLUE); init_pair(7, COLOR_CYAN, COLOR_WHITE); for (i = 1; i <= 7; i++) { attroff(A_BOLD); attrset(COLOR_PAIR(i)); mvprintw(5 + i, 5, "Color pair %d", i); attrset(COLOR_PAIR(i) | A_BOLD); mvprintw(5 + i, 25, "Bold color pair %d", i); refresh(); sleep(1); } endwin(); exit(EXIT_SUCCESS); }
void theme_init (bool has_xterm) { reset_colors_table (); if (has_colors()) { if (options_get_str("ForceTheme")) load_color_theme (options_get_str("ForceTheme"), 1); else if (has_xterm && options_get_str("XTermTheme")) load_color_theme (options_get_str("XTermTheme"), 1); else if (options_get_str("Theme")) load_color_theme (options_get_str("Theme"), 1); set_default_colors (); } else set_bw_colors (); }
/* * Draw shadows along the right and bottom edge to give a more 3D look * to the boxes */ void draw_shadow(WINDOW * win, int y, int x, int height, int width) { int i; if (has_colors()) { /* Whether terminal supports color? */ wattrset(win, dlg.shadow.atr); wmove(win, y + height, x + 2); for (i = 0; i < width; i++) waddch(win, winch(win) & A_CHARTEXT); for (i = y + 1; i < y + height + 1; i++) { wmove(win, i, x + width); waddch(win, winch(win) & A_CHARTEXT); waddch(win, winch(win) & A_CHARTEXT); } wnoutrefresh(win); } }
/* * Setup for color display */ void color_setup (void) { int i; if (has_colors ()) { /* Terminal supports color? */ start_color (); /* Initialize color pairs */ for (i = 0; i < ATTRIBUTE_COUNT; i++) init_pair (i + 1, color_table[i][0], color_table[i][1]); /* Setup color attributes */ for (i = 0; i < ATTRIBUTE_COUNT; i++) attributes[i] = C_ATTR (color_table[i][2], i + 1); } }
static void init(void) { int x, y; #ifdef yaomoon moon_log = fopen("moon_log","w+"); #endif /* Initialize the curses library */ if (isatty(STDIN_FILENO)) { cursed = !!initscr(); } else { /* Leave stdin and stdout alone when acting as a pager. */ FILE *io = fopen("/dev/tty", "r+"); cursed = !!newterm(NULL, io, io); } if (!cursed) die("Failed to initialize curses"); nonl(); /* tell curses not to do NL->CR/NL on output */ cbreak(); /* take input chars one at a time, no wait for \n */ noecho(); /* don't echo input */ leaveok(stdscr, TRUE); if (has_colors()) { init_colors(); } getmaxyx(stdscr, y, x); #ifdef yaomoon fprintf(moon_log,"getmaxyx y=%d\n",y); fprintf(moon_log,"getmaxyx x=%d\n",x); #endif status_win = newwin(1, 0, y - 10, 0); if (!status_win) die("failed to create status window"); keypad(status_win, TRUE); wbkgdset(status_win, get_line_attr(LINE_STATUS)); }
void display_init() { initscr(); if(has_colors() == FALSE) { endwin(); printf("Your terminal does not support color\n"); exit(1); } start_color(); init_pair(1, COLOR_WHITE, COLOR_BLACK); init_pair(2, COLOR_WHITE, COLOR_WHITE); init_pair(3, COLOR_BLACK, COLOR_RED); init_pair(4, COLOR_RED, COLOR_BLACK); wrefresh(stdscr);//first call clears the screen mvaddstr(1, LSTICK_X_P + 1, _("Left stick")); mvaddstr(1, RSTICK_X_P + 1, _("Right stick")); mvaddstr(1, BUTTON_X_P + 1, _("Buttons")); lstick = newwin(STICK_Y_L, STICK_X_L, LSTICK_Y_P, LSTICK_X_P); box(lstick, 0 , 0); wnoutrefresh(lstick); rstick = newwin(STICK_Y_L, STICK_X_L, RSTICK_Y_P, RSTICK_X_P); box(rstick, 0 , 0); wnoutrefresh(rstick); wbuttons = newwin(BUTTON_Y_L, BUTTON_X_L, BUTTON_Y_P, BUTTON_X_P); box(wbuttons, 0 , 0); wnoutrefresh(wbuttons); mvaddstr(CAL_Y_P, CAL_X_P + 1, _("Mouse calibration (Ctrl+F1 to edit)")); wcal = newwin(7, COLS-3, CAL_Y_P + 1, CAL_X_P); box(wcal, 0 , 0); wnoutrefresh(wcal); mvaddstr(LINES-1, 1, _("Refresh rate:")); mvaddstr(LINES-1, COLS-strlen(SHIFT_ESC), SHIFT_ESC); doupdate(); }
int main(int argc, char *argv[]) { initscr(); /* 启动curses模式 */ if(has_colors() == FALSE) { endwin(); printf("You terminal does not support color\n"); exit(1); } start_color(); /* 启动 color机制 */ init_pair(1, COLOR_RED, COLOR_BLACK); attron(COLOR_PAIR(1)); print_in_middle(stdscr, LINES / 2, 0, 0, "Viola !!! In color ..."); attroff(COLOR_PAIR(1)); getch(); endwin(); }
void screen(int h, int w){ initscr(); if (has_colors()) { start_color(); init_pair(1, COLOR_GREEN, COLOR_BLACK); init_pair(BGD, COLOR_WHITE, COLOR_BLACK); //2 init_pair(3, COLOR_YELLOW, COLOR_BLACK); init_pair(4, COLOR_RED, COLOR_BLACK); init_pair(5,COLOR_CYAN,COLOR_BLACK); init_pair(6,COLOR_MAGENTA,COLOR_BLACK); init_pair(7,COLOR_BLUE,COLOR_BLACK); } noecho(); curs_set(0); keypad(stdscr, TRUE); raw(); resize_term(h,w); }
int CTUI::GetColorPair(int fg, int bg) { if (!has_colors()) return COLOR_PAIR(0); TColorMap::iterator it = m_ColorPairs.find(fg); if (it != m_ColorPairs.end()) { std::map<int, int>::iterator it2 = it->second.find(bg); if (it2 != it->second.end()) return COLOR_PAIR(it2->second); } m_iCurColorPair++; InitPair(m_iCurColorPair, fg, bg); m_ColorPairs[fg][bg] = m_iCurColorPair; return COLOR_PAIR(m_iCurColorPair); }
void draw_sprite(WINDOW* win, struct sprite* spr, int x, int y){ int i=0, j=0; int color=0; char a; for(i=0; i<spr->height; ++i){ for(j=0; j<spr->width; ++j){ color = spr->color[spr->width*i+j]; a = spr->sprite[spr->width*i+j]; if(has_colors()){ wattron(win,COLOR_PAIR(color)); mvwprintw(win,y,x,"%c",a); wattroff(win,COLOR_PAIR(color)); }else{ mvwprintw(win,y,x,"%c",a); } } } }
void init_colori(vars *varia) { if (has_colors() == FALSE) { varia->colori=0; } else { varia->colori=1; start_color(); init_pair(color_portal(0), COLOR_RED, COLOR_BLACK); init_pair(color_portal(1), COLOR_BLUE, COLOR_BLACK); init_pair(color_wall, COLOR_YELLOW, COLOR_BLACK); init_pair(color_snake, COLOR_GREEN, COLOR_BLACK); init_pair(color_food, COLOR_MAGENTA, COLOR_BLACK); } }
void Engine::init_ncurses() { initscr(); cbreak(); curs_set(0); keypad(stdscr,TRUE); if (has_colors()) { start_color(); 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_WHITE,COLOR_BLACK); init_pair(8,COLOR_BLACK,COLOR_BLACK); } }
static void init_term() { /* Setup terminal */ initscr(); cbreak(); keypad(stdscr, 1); noecho(); timeout(100); if (has_colors()) { start_color(); init_pair(1, COLOR_GREEN, COLOR_BLACK); init_pair(2, COLOR_CYAN, COLOR_BLACK); init_pair(3, COLOR_RED, COLOR_BLACK); init_pair(4, COLOR_BLUE, COLOR_BLACK); } refresh(); }
static void init_ncurses() { initscr(); if (has_colors() == FALSE) { endwin(); printf("Your terminal does not support color\n"); exit(1); } curs_set(0); cbreak(); noecho(); start_color(); init_pair(1, COLOR_YELLOW, COLOR_BLACK); init_pair(2, COLOR_BLUE, COLOR_BLACK); init_pair(3, COLOR_CYAN, COLOR_BLACK); init_pair(4, COLOR_WHITE, COLOR_BLACK); }
Window::Window(void) : _color(0) { initscr(); m_win = stdscr; noecho(); curs_set(FALSE); raw(); keypad(stdscr, TRUE); getmaxyx(m_win, m_sizey, m_sizex); nodelay(stdscr, TRUE); if (has_colors() == FALSE) { endwin(); std::cout << "Color are not eneable in this term." << std::endl; exit(1); } return; }
int main (int argc, char **argv) { initscr(); if (has_colors() == FALSE) { endwin(); printf("You terminal does not support color\n"); exit(1); } start_color(); init_pair(1, COLOR_WHITE, COLOR_BLACK); attron(COLOR_PAIR(1)); print_in_middle(stdscr, LINES / 2, 0, 0, "Hello world!"); attroff(COLOR_PAIR(1)); getch(); endwin(); return 0; }
static void DisplayTiles(void) { int Line, peg, SlotNo; char TileBuf[BUFSIZ]; erase(); MvAddStr(1, 24, "T O W E R S O F H A N O I"); MvAddStr(3, 34, "SJR 1990"); MvPrintw(19, 5, "Moves : %d", NMoves); (void) attrset(A_REVERSE); MvAddStr(BASELINE, 8, " "); for (Line = TOPLINE; Line < BASELINE; Line++) { MvAddCh(Line, LEFTPEG, ' '); MvAddCh(Line, MIDPEG, ' '); MvAddCh(Line, RIGHTPEG, ' '); } MvAddCh(BASELINE, LEFTPEG, '1'); MvAddCh(BASELINE, MIDPEG, '2'); MvAddCh(BASELINE, RIGHTPEG, '3'); (void) attrset(A_NORMAL); /* Draw tiles */ for (peg = 0; peg < NPEGS; peg++) { for (SlotNo = 0; SlotNo < Pegs[peg].Count; SlotNo++) { size_t len = Pegs[peg].Length[SlotNo]; if (len < sizeof(TileBuf) - 1 && len < (size_t) PegPos[peg]) { memset(TileBuf, ' ', len); TileBuf[len] = '\0'; if (has_colors()) (void) attrset((attr_t) COLOR_PAIR(LENTOIND(len))); else (void) attrset(A_REVERSE); MvAddStr(BASELINE - (SlotNo + 1), (PegPos[peg] - (int) len / 2), TileBuf); } } } (void) attrset(A_NORMAL); refresh(); }
static int init_screen(screen_t *screen) { //printf("I'm %s() at %d in %s\n",__func__,__LINE__,__FILE__); screen_t *scr=screen; if(NULL==scr){ return RET_FAILED; } //init ncurses initscr(); noecho(); cbreak(); curs_set(FALSE); clear(); if(has_colors()){ start_color(); init_pair(COLOR_FOREGROUND,COLOR_BLUE,COLOR_BLACK); init_pair(COLOR_ICON_NORMAL,COLOR_BLUE,COLOR_BLACK); init_pair(COLOR_ICON_SELECT,COLOR_GREEN,COLOR_BLACK); init_pair(COLOR_TITLE,COLOR_MAGENTA,COLOR_BLACK); init_pair(COLOR_TEXT_CONTENT,COLOR_YELLOW,COLOR_BLACK); init_pair(COLOR_MSG_WARNING,COLOR_YELLOW,COLOR_BLACK); init_pair(COLOR_MSG_ERROR,COLOR_RED,COLOR_BLACK); init_pair(COLOR_MSG_RIGHT,COLOR_GREEN,COLOR_BLACK); } scr->win=stdscr; scr->background.top=ALPHABET_GAME_BACKGROUND_TOP; scr->background.left=ALPHABET_GAME_BACKGROUND_LEFT; scr->background.height=(int16_t)getmaxy(scr->win); scr->background.width=(int16_t)getmaxx(scr->win); scr->foreground.height=(int16_t)ALPHABET_GAME_FOREGROUND_HEIGHT; scr->foreground.width=(int16_t)ALPHABET_GAME_FOREGROUND_WIDTH; scr->foreground.top=(scr->background.height-scr->foreground.height)/2; scr->foreground.left=(scr->background.width-scr->foreground.width)/2; wrefresh(scr->win); keypad(scr->win,TRUE); nodelay(stdscr,TRUE); return RET_SUCCESS; }
bool DrawInit(){ initscr(); if(has_colors() == false) { endwin(); std::cout << "Your terminal does not support color\n" << std::endl; return false; } start_color(); //define colors init_pair (1, COLOR_BLACK, COLOR_WHITE); //board init_pair (2, COLOR_RED, COLOR_WHITE); //stone 1 init_pair (3, COLOR_BLUE, COLOR_WHITE); //stone 2 init_pair (4, COLOR_BLACK, COLOR_WHITE); //cursor //GUI init_pair (5, COLOR_WHITE, COLOR_BLACK); //border, GUI static text init_pair (6, COLOR_RED, COLOR_BLACK); //red score init_pair (7, COLOR_BLUE, COLOR_BLACK); //blue score init_pair (8, COLOR_WHITE, COLOR_BLACK); //button init_pair (9, COLOR_BLACK, COLOR_RED); //button selected init_pair(10, COLOR_WHITE, COLOR_BLUE); //MsgBox init_pair(11, COLOR_WHITE, COLOR_BLACK); //MsgBox text input init_pair(12, COLOR_RED, COLOR_BLACK); //BG init_pair(13, COLOR_MAGENTA, COLOR_BLACK); init_pair(14, COLOR_BLUE, COLOR_BLACK); init_pair(15, COLOR_CYAN, COLOR_BLACK); init_pair(16, COLOR_GREEN, COLOR_BLACK); init_pair(17, COLOR_YELLOW, COLOR_BLACK); timeout (17); curs_set (0); noecho(); keypad(stdscr, TRUE); return true; }
void initialize_curses() { // start curses initscr(); if ( ! has_colors() || (start_color() != OK) || COLORS != 256 ) error("colors"); // Define three horizontally-stacked windows: // // 1 - board window // 2 - CLI output window // 3 - CLI input window // int half_height = LINES / 2; // newwin( height, width, begin_height, begin_width ); w1 = newwin( half_height, COLS, 0, 0 ); w2 = newwin( half_height - 1, COLS, half_height, 0 ); w3 = newwin( 1, COLS, LINES - 1, 0 ); if (w1 == NULL || w2 == NULL || w3 == NULL) { waddstr(stdscr, "newwin"); endwin(); } echo(); scrollok(w2, TRUE); // initialize color tuples // see http://www.calmar.ws/vim/256-xterm-24bit-rgb-color-chart.html // FG, BG init_pair( LIGHT_SQUARE, 0, 229 ); init_pair( DARK_SQUARE, 0, 209 ); init_pair( BLUISH, 111, 233 ); init_pair( TERMINAL, 252, 232 ); init_pair( GREENISH, 107, 233 ); init_pair( CLI_INPUT, 253, 232 ); init_pair( GRAY_ON_BLACK, 245, 233 ); init_pair( RED, 1, 52 ); wbkgd( w1, COLOR_PAIR( TERMINAL ) ); wbkgd( w2, COLOR_PAIR( TERMINAL ) ); wbkgd( w3, COLOR_PAIR( CLI_INPUT ) ); wattron(w1, COLOR_PAIR( BLUISH) ); mvwaddstr(w1, 0, centered(TITLE), TITLE); wstandend(w1); wrefresh(stdscr); wrefresh(w1); wrefresh(w2); wrefresh(w3); touchwin(stdscr); touchwin(w1); touchwin(w2); touchwin(w3); }
/* * Define each field with an extra one, for reflecting "actual" text. */ static FIELD * make_field(int frow, int fcol, int rows, int cols) { FIELD *f = new_field(rows, cols, frow, fcol, o_value, 1); if (f) { FieldAttrs *ptr; set_field_back(f, A_UNDERLINE); /* * If -j and -d options are combined, -j loses. It is documented in * "Character User Interface Programming", page 12-15 that setting * O_STATIC off makes the form library ignore justification. */ set_field_just(f, j_value); if (d_option) { if (has_colors()) { set_field_fore(f, (chtype) COLOR_PAIR(2)); set_field_back(f, A_UNDERLINE | COLOR_PAIR(3)); } else { set_field_fore(f, A_BOLD); } /* * The field_opts_off() call dumps core with Solaris curses, * but that is a known bug in Solaris' form library -TD */ field_opts_off(f, O_STATIC); set_max_field(f, m_value); } /* * The userptr is used in edit_field.c's inactive_field(). */ ptr = (FieldAttrs *) field_userptr(f); if (ptr == 0) { ptr = typeCalloc(FieldAttrs, 1); ptr->background = field_back(f); } set_field_userptr(f, (void *) ptr); if (t_value) set_field_buffer(f, 0, t_value); } return (f); }
int main(int argc, char **argv) { if(!initscr()) { printf("Error initializing screen.\n"); exit(1); } if(!has_colors()) { printf("This terminal does not support colours.\n"); exit(1); } start_color(); // this prevents ncurses from forcing a white-on-black colour scheme, // regardless of what scheme is used by the terminal. use_default_colors(); attron(A_BOLD); mvaddstr(0, 0, "Colour FD FB FW BG BD BFD BFB BFW BBG BBN"); attroff(A_BOLD); int i; for(i=0; i<sizeof(colours)/sizeof(struct colour); i++) { init_pair(i*6+1, colours[i].code, -1); init_pair(i*6+2, colours[i].code, COLOR_BLACK); init_pair(i*6+3, colours[i].code, COLOR_WHITE); init_pair(i*6+4, colours[i].code, colours[i].code); init_pair(i*6+5, -1, colours[i].code); mvaddstr(i+2, 1, colours[i].desc); move(i+2, 8); print_colourpart(0, i); print_colourpart(A_BOLD, i); } mvaddstr(i+3, 2, "FD = Front colour on default background"); mvaddstr(i+4, 2, "FB = Front colour on black background"); mvaddstr(i+5, 2, "FW = Front colour on white background"); mvaddstr(i+6, 2, "BG = Front and background colour"); mvaddstr(i+7, 2, "BD = Background colour with default front colour"); mvaddstr(i+8, 2, "B?? = As above, with A_BOLD enabled"); mvaddstr(i+10, 0, "Hit any key to exit."); refresh(); getch(); endwin(); return 0; }
void curses_init() { null = g_fopen("/dev/null", "w"); unsetenv("COLUMNS"); unsetenv("LINES"); initscr(); noecho(); nonl(); cbreak(); keypad(stdscr, TRUE); meta(stdscr, TRUE); intrflush(stdscr, FALSE); leaveok(stdscr, TRUE); if (has_colors()) { start_color(); use_default_colors(); init_pair(COLORPAIR, conf.fg, conf.bg); } else conf.color = FALSE; curs_set(false); ws = newwin(1, COLS, EL, 0); view.current = 0; view.top_x = 0; view.top_y = 0; prompt.buf = g_string_new(""); prompt.on = false; prompt.regex = NULL; grid = g_array_sized_new(FALSE, TRUE, sizeof(grid_line_t*), SL); for (glong i = 0; i < SL; i++) { grid_line_t* grid_line = g_malloc(sizeof(grid_line_t)); g_array_append_val(grid, grid_line); } regrid(); }
int main(void) { int i; initscr(); if(!has_colors()) { endwin(); fprintf(stderr, "ERROR: this terminal do not support colors\n"); exit(1); } if(start_color() != OK) { endwin(); fprintf(stderr, "ERROR: could not initialize colors\n"); exit(2); } clear(); mvprintw(5, 5, "There are %d COLORS and %d COLOR_PAIRS available", COLORS, COLOR_PAIRS); refresh(); init_pair(1, COLOR_RED, COLOR_BLACK); init_pair(2, COLOR_RED, COLOR_GREEN); init_pair(3, COLOR_GREEN, COLOR_RED); init_pair(4, COLOR_YELLOW, COLOR_BLUE); init_pair(5, COLOR_BLACK, COLOR_WHITE); init_pair(6, COLOR_MAGENTA, COLOR_BLUE); init_pair(7, COLOR_CYAN, COLOR_WHITE); for(i = 1; i <= 7; i++) { attroff(A_BOLD); attrset(COLOR_PAIR(i)); mvprintw(5 + i, 5, "Color pair %d", i); attrset(COLOR_PAIR(i) | A_BOLD); mvprintw(5 + i, 25, "Bold color pair %d", i); refresh(); sleep(1); } endwin(); exit(EXIT_SUCCESS); }
static void DisplayTiles(void) { int Line, peg, SlotNo; char TileBuf[BUFSIZ]; erase(); init_pair(20,COLOR_MAGENTA,COLOR_BLACK); attrset(COLOR_PAIR(20)|A_BOLD); mvaddstr(1, 25,"汉 诺 塔 游 戏"); attrset(A_NORMAL); mvprintw(18, 30, "当前步数 : "); init_pair(21,COLOR_RED,COLOR_BLACK); attrset(COLOR_PAIR(21)|A_BOLD); mvprintw(18,41,"%d",NMoves); attrset(A_NORMAL); attrset(A_REVERSE); mvaddstr(BASELINE, 8, " "); for (Line = TOPLINE; Line < BASELINE; Line++) { mvaddch(Line, LEFTPEG, ' '); mvaddch(Line, MIDPEG, ' '); mvaddch(Line, RIGHTPEG, ' '); } mvaddch(BASELINE, LEFTPEG, '1'); mvaddch(BASELINE, MIDPEG, '2'); mvaddch(BASELINE, RIGHTPEG, '3'); attrset(A_NORMAL); for (peg = 0; peg < NPEGS; peg++) { for (SlotNo = 0; SlotNo < Pegs[peg].Count; SlotNo++) { memset(TileBuf, ' ', Pegs[peg].Length[SlotNo]); TileBuf[Pegs[peg].Length[SlotNo]] = '\0'; if (has_colors()) attrset(COLOR_PAIR(LENTOIND(Pegs[peg].Length[SlotNo]))); else attrset(A_REVERSE); mvaddstr(BASELINE - (SlotNo + 1), (int) (PegPos[peg] - Pegs[peg].Length[SlotNo] / 2), TileBuf); } } attrset(A_NORMAL); refresh(); }
int init(struct map_data **map, int argc, char *argv[]) { // process tags char *map_path; if ( argc > 1 ) map_path = argv[1]; else map_path = "test.map"; *map = load_map( map_path ); if (!*map) { fprintf(stderr, "Could not open map: %s\n", map_path); return 1; } //construct map if (!(*map)->data) { fprintf(stderr, "Data got corrupted!\n"); return 1; } // init screen initscr(); if((has_color = has_colors()) == FALSE) { endwin(); printf("Your terminal does not support color\n"); return 1; } else { assert( start_color() ); assert( init_printer() ); assert( init_pathfinder( is_traversable_test ) ); assert( init_keyboard( (*map)->height, (*map)->width-1 ) ); } // get keys cbreak(); raw(); return 0; }