send palette updates (initc) #230

pull/287/head
nick black 5 years ago committed by Nick Black
parent dfcdd10cb5
commit 20f4b3493c

@ -164,6 +164,7 @@ typedef struct notcurses {
char* smkx; // enter keypad transmit mode (keypad_xmit)
char* rmkx; // leave keypad transmit mode (keypad_local)
char* getm; // get mouse events
char* initc; // set a palette entry's RGB value
bool RGBflag; // terminfo-reported "RGB" flag for 24bpc directcolor
bool CCCflag; // terminfo-reported "CCC" flag for palette set capability
@ -183,6 +184,7 @@ typedef struct notcurses {
unsigned inputbuf_valid_starts;
unsigned inputbuf_write_at;
palette256 palette; // 256-indexed palette can be used instead of RGB
bool palette_damage[256]; // FIXME derive this value somehow
struct esctrie* inputescapes; // trie of input escapes -> ncspecial_keys
} notcurses;

@ -496,7 +496,12 @@ interrogate_terminfo(notcurses* nc, const notcurses_options* opts){
const char* cterm = getenv("COLORTERM");
nc->RGBflag = cterm && (strcmp(cterm, "truecolor") == 0 || strcmp(cterm, "24bit") == 0);
}
nc->CCCflag = tigetflag("ccc") == 1;
term_verify_seq(&nc->initc, "initc");
if(nc->initc == NULL){
nc->CCCflag = tigetflag("ccc") == 1;
}else{
nc->CCCflag = false;
}
if((nc->colors = tigetnum("colors")) <= 0){
if(!opts->suppress_banner){
fprintf(stderr, "This terminal doesn't appear to support colors\n");
@ -700,6 +705,8 @@ notcurses* notcurses_init(const notcurses_options* opts, FILE* outfp){
ret->inputescapes = NULL;
ret->ttyinfp = stdin; // FIXME
memset(&ret->rstate, 0, sizeof(ret->rstate));
memset(&ret->palette_damage, 0, sizeof(ret->palette_damage));
memset(&ret->palette, 0, sizeof(ret->palette));
ret->lastframe = NULL;
ret->lfdimy = 0;
ret->lfdimx = 0;

@ -594,6 +594,21 @@ term_fg_rgb8(notcurses* nc, FILE* out, unsigned r, unsigned g, unsigned b){
return 0;
}
static inline int
update_palette(notcurses* nc, FILE* out){
if(nc->CCCflag){
for(size_t damageidx = 0 ; damageidx < sizeof(nc->palette.chans) / sizeof(*nc->palette.chans) ; ++damageidx){
unsigned r, g, b;
if(nc->palette_damage[damageidx]){
channel_rgb(nc->palette.chans[damageidx], &r, &g, &b);
term_emit("initc", tiparm(nc->initc, damageidx, r, g, b), out, false);
nc->palette_damage[damageidx] = false;
}
}
}
return 0;
}
// Producing the frame requires three steps:
// * render -- build up a flat framebuffer from a set of ncplanes
// * rasterize -- build up a UTF-8 stream of escapes and EGCs
@ -611,6 +626,7 @@ notcurses_rasterize(notcurses* nc, const struct crender* rvec){
// don't write a clearscreen. we only update things that have been changed.
// we explicitly move the cursor at the beginning of each output line, so no
// need to home it expliticly.
update_palette(nc, out);
for(y = 0 ; y < nc->stdscr->leny ; ++y){
// how many characters have we elided? it's not worthwhile to invoke a
// cursor movement with cup if we only elided one or two. set to INT_MAX

Loading…
Cancel
Save