/* Assign pairs by request */ short owl_fmtext_get_colorpair(int fg, int bg) { owl_colorpair_mgr *cpmgr; short pair, default_bg; /* Sanity (Bounds) Check */ if (fg > COLORS || fg < OWL_COLOR_DEFAULT) fg = OWL_COLOR_DEFAULT; if (bg > COLORS || bg < OWL_COLOR_DEFAULT) bg = OWL_COLOR_DEFAULT; #ifdef HAVE_USE_DEFAULT_COLORS if (fg == OWL_COLOR_DEFAULT) fg = -1; default_bg = OWL_COLOR_DEFAULT; #else if (fg == OWL_COLOR_DEFAULT) fg = 0; if (bg == OWL_COLOR_DEFAULT) bg = 0; default_bg = COLOR_BLACK; #endif /* looking for a pair we already set up for this draw. */ cpmgr = owl_global_get_colorpair_mgr(&g); pair = cpmgr->pairs[fg+1][bg+1]; if (!(pair != -1 && pair < cpmgr->next)) { /* If we didn't find a pair, search for a free one to assign. */ pair = (cpmgr->next < COLOR_PAIRS) ? cpmgr->next : -1; if (pair != -1) { /* We found a free pair, initialize it. */ init_pair(pair, fg, bg); cpmgr->pairs[fg+1][bg+1] = pair; cpmgr->next++; } else if (bg != OWL_COLOR_DEFAULT) { /* We still don't have a pair, drop the background color. Too bad. */ owl_function_debugmsg("colorpairs: color shortage - dropping background color."); pair = owl_fmtext_get_colorpair(fg, OWL_COLOR_DEFAULT); } else { /* We still don't have a pair, defaults all around. */ owl_function_debugmsg("colorpairs: color shortage - dropping foreground and background color."); pair = 0; } } return pair; }
/* Reset used list */ void owl_fmtext_reset_colorpairs(void) { if (owl_global_get_hascolors(&g)) { short i, j; owl_colorpair_mgr *cpmgr = owl_global_get_colorpair_mgr(&g); cpmgr->next = 8; /* The test is <= because we allocated COLORS+1 entries. */ for(i = 0; i <= COLORS; i++) { for(j = 0; j <= COLORS; j++) { cpmgr->pairs[i][j] = -1; } } for(i = 0; i < 8; i++) { short fg, bg; if (i >= COLORS) continue; pair_content(i, &fg, &bg); cpmgr->pairs[fg+1][bg+1] = i; } } }
static int owl_refresh_pre_select_action(owl_ps_action *a, void *data) { owl_colorpair_mgr *cpmgr; /* if a resize has been scheduled, deal with it */ owl_global_check_resize(&g); /* update the terminal if we need to */ owl_window_redraw_scheduled(); /* On colorpair shortage, reset and redraw /everything/. NOTE: if * the current screen uses too many colorpairs, this draws * everything twice. But this is unlikely; COLOR_PAIRS is 64 with * 8+1 colors, and 256^2 with 256+1 colors. (+1 for default.) */ cpmgr = owl_global_get_colorpair_mgr(&g); if (cpmgr->overflow) { owl_function_debugmsg("colorpairs: color shortage; reset pairs and redraw. COLOR_PAIRS = %d", COLOR_PAIRS); owl_fmtext_reset_colorpairs(cpmgr); owl_function_full_redisplay(); owl_window_redraw_scheduled(); } return 0; }