[termdesc] query default foreground color #2432

pull/2447/head
nick black 3 years ago
parent 6e42d5c52e
commit 3391db6dcb
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

@ -1219,6 +1219,27 @@ decrpm_asu_cb(inputctx* ictx){
return 2;
}
static int
get_default_color(const char* str, uint32_t* color){
int r, g, b;
if(sscanf(str, "%02x/%02x/%02x", &r, &g, &b) == 3){
// great! =]
}else if(sscanf(str, "%04x/%04x/%04x", &r, &g, &b) == 3){
r /= 256;
g /= 256;
b /= 256;
}else{
logerror("couldn't extract rgb from %s\n", str);
return -1;
}
if(r < 0 || g < 0 || b < 0){
logerror("invalid colors %d %d %d\n", r, g, b);
return -1;
}
*color = (r << 16u) | (g << 8u) | b;
return 0;
}
static int
bgdef_cb(inputctx* ictx){
if(ictx->initdata){
@ -1226,20 +1247,27 @@ bgdef_cb(inputctx* ictx){
if(str == NULL){
logerror("empty bg string\n");
}else{
int r, g, b;
if(sscanf(str, "%02x/%02x/%02x", &r, &g, &b) == 3){
// great! =]
}else if(sscanf(str, "%04x/%04x/%04x", &r, &g, &b) == 3){
r /= 256;
g /= 256;
b /= 256;
}else{
logerror("couldn't extract rgb from %s\n", str);
r = g = b = 0;
if(get_default_color(str, &ictx->initdata->bg) == 0){
ictx->initdata->got_bg = true;
loginfo("default background 0x%06x\n", ictx->initdata->bg);
}
free(str);
}
}
return 2;
}
static int
fgdef_cb(inputctx* ictx){
if(ictx->initdata){
char* str = amata_next_string(&ictx->amata, "\x1b]10;rgb:");
if(str == NULL){
logerror("empty fg string\n");
}else{
if(get_default_color(str, &ictx->initdata->fg) == 0){
ictx->initdata->got_fg = true;
loginfo("default foreground 0x%06x\n", ictx->initdata->fg);
}
ictx->initdata->bg = (r << 16u) | (g << 8u) | b;
ictx->initdata->got_bg = true;
loginfo("default background 0x%02x%02x%02x\n", r, g, b);
free(str);
}
}
@ -1467,6 +1495,7 @@ build_cflow_automaton(inputctx* ictx){
// OSC (\e_...ST)
{ "_G\\S", kittygraph_cb, },
// a mystery to everyone!
{ "]10;rgb:\\S", fgdef_cb, },
{ "]11;rgb:\\S", bgdef_cb, },
{ NULL, NULL, },
}, *csi;

@ -61,7 +61,9 @@ struct initial_responses {
queried_terminals_e qterm; // determined terminal
unsigned kitty_graphics; // kitty graphics supported
uint32_t bg; // default background
uint32_t fg; // default foreground
bool got_bg; // have we read default background?
bool got_fg; // have we read default foreground?
bool rgb; // was RGB DirectColor advertised?
int pixx; // screen geometry in pixels
int pixy; // screen geometry in pixels

@ -361,6 +361,7 @@ init_terminfo_esc(tinfo* ti, const char* name, escape_e idx,
// unlike most other queries, so send this first since it will take longer to be
// answered. note the "\x1b]"; this is an Operating System Command, not CSI.
#define DEFBGQ "\x1b]11;?\e\\"
#define DEFFGQ "\x1b]10;?\e\\"
// FIXME ought be using the u7 terminfo string here, if it exists. the great
// thing is, if we get a response to this, we know we can use it for u7!
@ -386,7 +387,8 @@ init_terminfo_esc(tinfo* ti, const char* name, escape_e idx,
// request the cell geometry of the textual area
#define GEOMCELL "\x1b[18t"
#define DIRECTIVES DEFBGQ \
#define DIRECTIVES DEFFGQ \
DEFBGQ \
KKBDQUERY \
SUMQUERY \
"\x1b[?1;3;256S" /* try to set 256 cregs */ \

Loading…
Cancel
Save