mirror of
https://github.com/dankamongmen/notcurses
synced 2025-03-09 17:19:03 -04:00
detect and expose default foreground color #2432
This commit is contained in:
parent
3391db6dcb
commit
4c17970ba0
2
NEWS.md
2
NEWS.md
@ -8,7 +8,7 @@ rearrangements of Notcurses.
|
|||||||
and `ncplane_autogrow_p()` functions. When autogrow is enabled, the plane
|
and `ncplane_autogrow_p()` functions. When autogrow is enabled, the plane
|
||||||
is automatically enlarged to accommodate output at its right (no scrolling)
|
is automatically enlarged to accommodate output at its right (no scrolling)
|
||||||
or bottom (scrolling enabled) boundaries.
|
or bottom (scrolling enabled) boundaries.
|
||||||
* Added the new function `notcurses_default_background()`.
|
* Added `notcurses_default_background()` and `notcurses_default_foreground()`.
|
||||||
|
|
||||||
* 3.0.0 (2021-12-01) **"In the A"**
|
* 3.0.0 (2021-12-01) **"In the A"**
|
||||||
* Made the ABI/API changes that have been planned/collected during 2.x
|
* Made the ABI/API changes that have been planned/collected during 2.x
|
||||||
|
5
USAGE.md
5
USAGE.md
@ -293,6 +293,11 @@ notcurses_term_dim_yx(const struct notcurses* n, unsigned* restrict rows,
|
|||||||
// current screen geometry is returned in 'y' and 'x', if they are not NULL.
|
// current screen geometry is returned in 'y' and 'x', if they are not NULL.
|
||||||
int notcurses_refresh(struct notcurses* n, unsigned* restrict y, unsigned* restrict x);
|
int notcurses_refresh(struct notcurses* n, unsigned* restrict y, unsigned* restrict x);
|
||||||
|
|
||||||
|
// Get the default foreground color, if it is known. Returns -1 on error
|
||||||
|
// (unknown foreground). On success, returns 0, writing the RGB value to
|
||||||
|
// 'fg' (if non-NULL)
|
||||||
|
int notcurses_default_foreground(const struct notcurses* nc, uint32_t* fg);
|
||||||
|
|
||||||
// Get the default background color, if it is known. Returns -1 on error
|
// Get the default background color, if it is known. Returns -1 on error
|
||||||
// (unknown background). On success, returns 0, writing the RGB value to
|
// (unknown background). On success, returns 0, writing the RGB value to
|
||||||
// 'bg' (if non-NULL) and setting 'bgtrans' high iff the background color
|
// 'bg' (if non-NULL) and setting 'bgtrans' high iff the background color
|
||||||
|
@ -53,6 +53,8 @@ typedef struct notcurses_options {
|
|||||||
|
|
||||||
**int notcurses_lex_margins(const char* ***op***, notcurses_options* ***opts***);**
|
**int notcurses_lex_margins(const char* ***op***, notcurses_options* ***opts***);**
|
||||||
|
|
||||||
|
**int notcurses_default_foreground(const struct notcurses* ***nc***, uint32_t* ***fg***);**
|
||||||
|
|
||||||
**int notcurses_default_background(const struct notcurses* ***nc***, uint32_t* ***bg***, unsigned* ***bgtrans***);**
|
**int notcurses_default_background(const struct notcurses* ***nc***, uint32_t* ***bg***, unsigned* ***bgtrans***);**
|
||||||
|
|
||||||
# DESCRIPTION
|
# DESCRIPTION
|
||||||
@ -168,8 +170,10 @@ zero. The following flags are defined:
|
|||||||
eventually prevent Notcurses from processing messages from the terminal. It
|
eventually prevent Notcurses from processing messages from the terminal. It
|
||||||
will furthermore avoid wasting time processing useless input.
|
will furthermore avoid wasting time processing useless input.
|
||||||
|
|
||||||
**notcurses_default_background** returns the default background color, and
|
**notcurses_default_foreground** returns the default foreground color, if it
|
||||||
whether the terminal treats it as transparent, if this could be detected.
|
could be detected. **notcurses_default_background** returns the default
|
||||||
|
background color, and whether the terminal treats it as transparent, if this
|
||||||
|
could be detected.
|
||||||
|
|
||||||
## Fatal signals
|
## Fatal signals
|
||||||
|
|
||||||
@ -250,6 +254,9 @@ rendered mode to be used as a normal scrolling shell application.
|
|||||||
|
|
||||||
**notcurses_cursor_disable** returns -1 if the cursor is already invisible.
|
**notcurses_cursor_disable** returns -1 if the cursor is already invisible.
|
||||||
|
|
||||||
|
**notcurses_default_foreground** returns -1 if the default foreground color
|
||||||
|
could not be detected.
|
||||||
|
|
||||||
**notcurses_default_background** returns -1 if the default background color
|
**notcurses_default_background** returns -1 if the default background color
|
||||||
could not be detected.
|
could not be detected.
|
||||||
|
|
||||||
|
@ -3629,6 +3629,12 @@ ncbprefix(uintmax_t val, uintmax_t decimal, char* buf, int omitdec){
|
|||||||
return ncnmetric(val, NCBPREFIXSTRLEN + 1, decimal, buf, omitdec, 1024, 'i');
|
return ncnmetric(val, NCBPREFIXSTRLEN + 1, decimal, buf, omitdec, 1024, 'i');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the default foreground color, if it is known. Returns -1 on error
|
||||||
|
// (unknown foreground). On success, returns 0, writing the RGB value to
|
||||||
|
// 'fg' (if non-NULL)
|
||||||
|
API int notcurses_default_foreground(const struct notcurses* nc, uint32_t* fg)
|
||||||
|
__attribute__ ((nonnull (1)));
|
||||||
|
|
||||||
// Get the default background color, if it is known. Returns -1 on error
|
// Get the default background color, if it is known. Returns -1 on error
|
||||||
// (unknown background). On success, returns 0, writing the RGB value to
|
// (unknown background). On success, returns 0, writing the RGB value to
|
||||||
// 'bg' (if non-NULL) and setting 'bgtrans' high iff the background color
|
// 'bg' (if non-NULL) and setting 'bgtrans' high iff the background color
|
||||||
|
@ -369,18 +369,23 @@ display_logo(struct ncplane* n, const char* path){
|
|||||||
|
|
||||||
static void
|
static void
|
||||||
tinfo_debug_bitmaps(struct ncplane* n, const tinfo* ti, const char* indent){
|
tinfo_debug_bitmaps(struct ncplane* n, const tinfo* ti, const char* indent){
|
||||||
|
uint32_t fg = 0;
|
||||||
|
int r = notcurses_default_foreground(ncplane_notcurses(n), &fg);
|
||||||
|
if(r){
|
||||||
|
ncplane_printf(n, "%sno known default fg ", indent);
|
||||||
|
}else{
|
||||||
|
ncplane_printf(n, "%sdefault fg 0x%06x ", indent, fg);
|
||||||
|
}
|
||||||
unsigned bgtrans = 0;
|
unsigned bgtrans = 0;
|
||||||
uint32_t bg = 0;
|
uint32_t bg = 0;
|
||||||
int r = notcurses_default_background(ncplane_notcurses(n), &bg, &bgtrans);
|
r = notcurses_default_background(ncplane_notcurses(n), &bg, &bgtrans);
|
||||||
if(r){
|
if(r){
|
||||||
ncplane_printf(n, "couldn't detect default background");
|
ncplane_printf(n, "no known default fg");
|
||||||
}else{
|
}else{
|
||||||
if(bgtrans){
|
if(bgtrans){
|
||||||
ncplane_printf(n, "%sdefault background 0x%06lx considered transparent", indent,
|
ncplane_printf(n, "default bg 0x%06x (trans)", bg);
|
||||||
ti->bg_collides_default & 0xfffffful);
|
|
||||||
}else{
|
}else{
|
||||||
ncplane_printf(n, "%sdefault background 0x%06lx", indent,
|
ncplane_printf(n, "default bg 0x%06x", bg);
|
||||||
ti->bg_collides_default & 0xfffffful);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finish_line(n);
|
finish_line(n);
|
||||||
|
@ -1726,6 +1726,16 @@ int ncdirect_set_fg_rgb(ncdirect* nc, unsigned rgb){
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int notcurses_default_foreground(const struct notcurses* nc, uint32_t* fg){
|
||||||
|
const tinfo* ti = &nc->tcache;
|
||||||
|
if(ti->fg_default & 0x80000000){
|
||||||
|
logerror("default foreground could not be determined\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
*fg = ti->fg_default & NC_BG_RGB_MASK;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int notcurses_default_background(const struct notcurses* nc,
|
int notcurses_default_background(const struct notcurses* nc,
|
||||||
uint32_t* bg, unsigned* bgtrans){
|
uint32_t* bg, unsigned* bgtrans){
|
||||||
const tinfo* ti = &nc->tcache;
|
const tinfo* ti = &nc->tcache;
|
||||||
|
@ -857,6 +857,7 @@ int interrogate_terminfo(tinfo* ti, FILE* out, unsigned utf8,
|
|||||||
}
|
}
|
||||||
*cursor_x = *cursor_y = -1;
|
*cursor_x = *cursor_y = -1;
|
||||||
ti->bg_collides_default = 0xfe000000;
|
ti->bg_collides_default = 0xfe000000;
|
||||||
|
ti->fg_default = 0xff000000;
|
||||||
ti->kbdlevel = UINT_MAX; // see comment in tinfo definition
|
ti->kbdlevel = UINT_MAX; // see comment in tinfo definition
|
||||||
ti->qterm = TERMINAL_UNKNOWN;
|
ti->qterm = TERMINAL_UNKNOWN;
|
||||||
// we don't need a controlling tty for everything we do; allow a failure here
|
// we don't need a controlling tty for everything we do; allow a failure here
|
||||||
@ -1109,6 +1110,9 @@ int interrogate_terminfo(tinfo* ti, FILE* out, unsigned utf8,
|
|||||||
// kitty, we'll add the 0x01000000 in during heuristics.
|
// kitty, we'll add the 0x01000000 in during heuristics.
|
||||||
ti->bg_collides_default = iresp->bg;
|
ti->bg_collides_default = iresp->bg;
|
||||||
}
|
}
|
||||||
|
if(iresp->got_fg){
|
||||||
|
ti->fg_default = iresp->fg;
|
||||||
|
}
|
||||||
// kitty trumps sixel, when both are available
|
// kitty trumps sixel, when both are available
|
||||||
if((kitty_graphics = iresp->kitty_graphics) == 0){
|
if((kitty_graphics = iresp->kitty_graphics) == 0){
|
||||||
ti->color_registers = iresp->color_registers;
|
ti->color_registers = iresp->color_registers;
|
||||||
|
@ -123,6 +123,9 @@ typedef struct tinfo {
|
|||||||
// 0xfexxxxxxx (unknown), 0x00RRGGBB (no collide), or 0x01RRGGBB (collides).
|
// 0xfexxxxxxx (unknown), 0x00RRGGBB (no collide), or 0x01RRGGBB (collides).
|
||||||
uint32_t bg_collides_default;
|
uint32_t bg_collides_default;
|
||||||
|
|
||||||
|
// 0xffxxxxxxx (unknown), or 0x00RRGGBB (foreground)
|
||||||
|
uint32_t fg_default;
|
||||||
|
|
||||||
// bitmap support. if we support bitmaps, pixel_implementation will be a
|
// bitmap support. if we support bitmaps, pixel_implementation will be a
|
||||||
// value other than NCPIXEL_NONE.
|
// value other than NCPIXEL_NONE.
|
||||||
ncpixelimpl_e pixel_implementation;
|
ncpixelimpl_e pixel_implementation;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user