[reset_term_palette] use oc only as a last resort #2450

pull/2460/head
nick black 3 years ago committed by nick black
parent 227271017a
commit 0d65db84dc

@ -379,7 +379,7 @@ tinfo_debug_bitmaps(struct ncplane* n, const tinfo* ti, const char* indent){
uint32_t bg = 0;
r = notcurses_default_background(ncplane_notcurses(n), &bg);
if(r){
ncplane_printf(n, "no known default fg");
ncplane_printf(n, "no known default bg");
}else{
ncplane_printf(n, "default bg 0x%06x", bg);
}

@ -421,7 +421,7 @@ insert_path(automaton* a, const char* seq){
return NULL;
}
}else if(c == 'S'){
// strings always end with ST ("\e\\")
// strings always end with ST ("\e\\") or at least ("\e")
if((eptr = esctrie_make_string(a, eptr)) == NULL){
return NULL;
}

@ -426,7 +426,7 @@ void sigwinch_handler(int signo);
void init_lang(void);
int reset_term_attributes(const tinfo* ti, fbuf* f);
int reset_term_palette(const tinfo* ti, fbuf* f);
// if there were missing elements we wanted from terminfo, bitch about them here
void warn_terminfo(const notcurses* nc, const tinfo* ti);

@ -59,8 +59,43 @@ int reset_term_attributes(const tinfo* ti, fbuf* f){
if((esc = get_escape(ti, ESCAPE_SGR0)) && fbuf_emit(f, esc)){
ret = -1;
}
if((esc = get_escape(ti, ESCAPE_OC)) && fbuf_emit(f, esc)){
ret = -1;
return ret;
}
// attempt to restore the palette. if XT{PUSH,POP}COLORS is supported, use
// XTPOPCOLORS. if we can program individual colors, and we read the palette,
// reload it from our initial capture. otherwise, use "oc" if available; this
// will blow away any preexisting palette in favor of the default.
int reset_term_palette(const tinfo* ti, fbuf* f){
int ret = 0;
const char* esc;
if((esc = get_escape(ti, ESCAPE_RESTORECOLORS))){
loginfo("restoring palette via xtpopcolors\n");
if(fbuf_emit(f, esc)){
ret = -1;
}
}else if(ti->caps.can_change_colors && ti->maxpaletteread > -1){
fprintf(stderr, "CCC: %u %d\n", ti->caps.can_change_colors, ti->maxpaletteread);
loginfo("restoring saved palette (%d)\n", ti->maxpaletteread + 1);
esc = get_escape(ti, ESCAPE_INITC);
for(int z = 0 ; z < ti->maxpaletteread ; ++z){
unsigned r, g, b;
ncchannel_rgb8(ti->originalpalette.chans[z], &r, &g, &b);
// Need convert RGB values [0..256) to [0..1000], ugh
r = r * 1000 / 255;
g = g * 1000 / 255;
b = b * 1000 / 255;
if(fbuf_emit(f, tiparm(esc, z, r, g, b)) < 0){
return -1;
}
}
}else if((esc = get_escape(ti, ESCAPE_OC))){
loginfo("resetting palette\n");
if(fbuf_emit(f, esc)){
ret = -1;
}
}else{
logwarn("no method known to restore palette\n");
}
return ret;
}
@ -81,9 +116,7 @@ notcurses_stop_minimal(void* vnc){
// be sure to write the restoration sequences *prior* to running rmcup, as
// they apply to the screen (alternate or otherwise) we're actually using.
const char* esc;
if((esc = get_escape(&nc->tcache, ESCAPE_RESTORECOLORS)) && fbuf_emit(f, esc)){
ret = -1;
}
ret |= reset_term_palette(&nc->tcache, f);
ret |= reset_term_attributes(&nc->tcache, f);
if((esc = get_escape(&nc->tcache, ESCAPE_RMKX)) && fbuf_emit(f, esc)){
ret = -1;

Loading…
Cancel
Save