mirror of
https://github.com/dankamongmen/notcurses
synced 2025-03-09 17:19:03 -04:00
[termdesc] query default foreground color #2432
This commit is contained in:
parent
6e42d5c52e
commit
3391db6dcb
55
src/lib/in.c
55
src/lib/in.c
@ -1219,6 +1219,27 @@ decrpm_asu_cb(inputctx* ictx){
|
|||||||
return 2;
|
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
|
static int
|
||||||
bgdef_cb(inputctx* ictx){
|
bgdef_cb(inputctx* ictx){
|
||||||
if(ictx->initdata){
|
if(ictx->initdata){
|
||||||
@ -1226,20 +1247,27 @@ bgdef_cb(inputctx* ictx){
|
|||||||
if(str == NULL){
|
if(str == NULL){
|
||||||
logerror("empty bg string\n");
|
logerror("empty bg string\n");
|
||||||
}else{
|
}else{
|
||||||
int r, g, b;
|
if(get_default_color(str, &ictx->initdata->bg) == 0){
|
||||||
if(sscanf(str, "%02x/%02x/%02x", &r, &g, &b) == 3){
|
ictx->initdata->got_bg = true;
|
||||||
// great! =]
|
loginfo("default background 0x%06x\n", ictx->initdata->bg);
|
||||||
}else if(sscanf(str, "%04x/%04x/%04x", &r, &g, &b) == 3){
|
}
|
||||||
r /= 256;
|
free(str);
|
||||||
g /= 256;
|
}
|
||||||
b /= 256;
|
}
|
||||||
}else{
|
return 2;
|
||||||
logerror("couldn't extract rgb from %s\n", str);
|
}
|
||||||
r = g = b = 0;
|
|
||||||
|
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);
|
free(str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1467,6 +1495,7 @@ build_cflow_automaton(inputctx* ictx){
|
|||||||
// OSC (\e_...ST)
|
// OSC (\e_...ST)
|
||||||
{ "_G\\S", kittygraph_cb, },
|
{ "_G\\S", kittygraph_cb, },
|
||||||
// a mystery to everyone!
|
// a mystery to everyone!
|
||||||
|
{ "]10;rgb:\\S", fgdef_cb, },
|
||||||
{ "]11;rgb:\\S", bgdef_cb, },
|
{ "]11;rgb:\\S", bgdef_cb, },
|
||||||
{ NULL, NULL, },
|
{ NULL, NULL, },
|
||||||
}, *csi;
|
}, *csi;
|
||||||
|
@ -61,7 +61,9 @@ struct initial_responses {
|
|||||||
queried_terminals_e qterm; // determined terminal
|
queried_terminals_e qterm; // determined terminal
|
||||||
unsigned kitty_graphics; // kitty graphics supported
|
unsigned kitty_graphics; // kitty graphics supported
|
||||||
uint32_t bg; // default background
|
uint32_t bg; // default background
|
||||||
|
uint32_t fg; // default foreground
|
||||||
bool got_bg; // have we read default background?
|
bool got_bg; // have we read default background?
|
||||||
|
bool got_fg; // have we read default foreground?
|
||||||
bool rgb; // was RGB DirectColor advertised?
|
bool rgb; // was RGB DirectColor advertised?
|
||||||
int pixx; // screen geometry in pixels
|
int pixx; // screen geometry in pixels
|
||||||
int pixy; // 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
|
// 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.
|
// answered. note the "\x1b]"; this is an Operating System Command, not CSI.
|
||||||
#define DEFBGQ "\x1b]11;?\e\\"
|
#define DEFBGQ "\x1b]11;?\e\\"
|
||||||
|
#define DEFFGQ "\x1b]10;?\e\\"
|
||||||
|
|
||||||
// FIXME ought be using the u7 terminfo string here, if it exists. the great
|
// 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!
|
// 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
|
// request the cell geometry of the textual area
|
||||||
#define GEOMCELL "\x1b[18t"
|
#define GEOMCELL "\x1b[18t"
|
||||||
|
|
||||||
#define DIRECTIVES DEFBGQ \
|
#define DIRECTIVES DEFFGQ \
|
||||||
|
DEFBGQ \
|
||||||
KKBDQUERY \
|
KKBDQUERY \
|
||||||
SUMQUERY \
|
SUMQUERY \
|
||||||
"\x1b[?1;3;256S" /* try to set 256 cregs */ \
|
"\x1b[?1;3;256S" /* try to set 256 cregs */ \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user