mirror of
https://github.com/dankamongmen/notcurses.git
synced 2024-11-18 03:25:55 +00:00
ncdirect_{fg, bg}_default() -> ncdirect_set_{fg, bg}_default() #1261
This commit is contained in:
parent
713498efc5
commit
76d8e2dfce
2
NEWS.md
2
NEWS.md
@ -5,6 +5,8 @@ rearrangements of Notcurses.
|
|||||||
* `ncdirect_styles_{set, on, off}()` have been deprecated in favor of
|
* `ncdirect_styles_{set, on, off}()` have been deprecated in favor of
|
||||||
`ncdirect_{set, on, off}_styles()`, to match `ncplane_` equivalents.
|
`ncdirect_{set, on, off}_styles()`, to match `ncplane_` equivalents.
|
||||||
* `ncdirect_raster_frame()` no longer requires `blitter` nor `scale`.
|
* `ncdirect_raster_frame()` no longer requires `blitter` nor `scale`.
|
||||||
|
* `ncdirect_{fg, bg}_default()` have been deprecated in favor of
|
||||||
|
`ncdirect_set_{fg, bg}_default()`, to match `ncplane`.
|
||||||
|
|
||||||
* 2.1.2 (2020-12-25)
|
* 2.1.2 (2020-12-25)
|
||||||
* Add `notcurses_linesigs_enable()` and `notcurses_linesigs_disable()`.
|
* Add `notcurses_linesigs_enable()` and `notcurses_linesigs_disable()`.
|
||||||
|
@ -35,7 +35,7 @@ namespace ncpp
|
|||||||
|
|
||||||
bool set_fg_default () const NOEXCEPT_MAYBE
|
bool set_fg_default () const NOEXCEPT_MAYBE
|
||||||
{
|
{
|
||||||
return error_guard (ncdirect_fg_default (direct), -1);
|
return error_guard (ncdirect_set_fg_default (direct), -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool set_fg_rgb (unsigned rgb) const NOEXCEPT_MAYBE
|
bool set_fg_rgb (unsigned rgb) const NOEXCEPT_MAYBE
|
||||||
@ -55,7 +55,7 @@ namespace ncpp
|
|||||||
|
|
||||||
bool set_bg_default () const NOEXCEPT_MAYBE
|
bool set_bg_default () const NOEXCEPT_MAYBE
|
||||||
{
|
{
|
||||||
return error_guard (ncdirect_bg_default (direct), -1);
|
return error_guard (ncdirect_set_bg_default (direct), -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool set_bg_rgb (unsigned rgb) const NOEXCEPT_MAYBE
|
bool set_bg_rgb (unsigned rgb) const NOEXCEPT_MAYBE
|
||||||
|
@ -78,8 +78,14 @@ ncdirect_fg_rgb8(struct ncdirect* nc, unsigned r, unsigned g, unsigned b){
|
|||||||
return ncdirect_fg_rgb(nc, (r << 16u) + (g << 8u) + b);
|
return ncdirect_fg_rgb(nc, (r << 16u) + (g << 8u) + b);
|
||||||
}
|
}
|
||||||
|
|
||||||
API int ncdirect_fg_default(struct ncdirect* nc);
|
API int ncdirect_set_fg_default(struct ncdirect* nc);
|
||||||
API int ncdirect_bg_default(struct ncdirect* nc);
|
API int ncdirect_set_bg_default(struct ncdirect* nc);
|
||||||
|
|
||||||
|
API int ncdirect_fg_default(struct ncdirect* nc)
|
||||||
|
__attribute__ ((deprecated));
|
||||||
|
|
||||||
|
API int ncdirect_bg_default(struct ncdirect* nc)
|
||||||
|
__attribute__ ((deprecated));
|
||||||
|
|
||||||
// Get the current number of columns/rows.
|
// Get the current number of columns/rows.
|
||||||
API int ncdirect_dim_x(const struct ncdirect* nc);
|
API int ncdirect_dim_x(const struct ncdirect* nc);
|
||||||
|
@ -276,7 +276,7 @@ drawpalette(struct ncdirect* nc){
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(ncdirect_bg_default(nc)){
|
if(ncdirect_set_bg_default(nc)){
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if(putchar('\n') == EOF){
|
if(putchar('\n') == EOF){
|
||||||
|
@ -9,16 +9,31 @@
|
|||||||
#include "notcurses/direct.h"
|
#include "notcurses/direct.h"
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
|
||||||
|
static inline uint64_t
|
||||||
|
ncdirect_channels(const ncdirect* nc){
|
||||||
|
return nc->channels;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline bool
|
||||||
|
ncdirect_fg_default_p(const struct ncdirect* nc){
|
||||||
|
return channels_fg_default_p(ncdirect_channels(nc));
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline bool
|
||||||
|
ncdirect_bg_default_p(const struct ncdirect* nc){
|
||||||
|
return channels_bg_default_p(ncdirect_channels(nc));
|
||||||
|
}
|
||||||
|
|
||||||
int ncdirect_putstr(ncdirect* nc, uint64_t channels, const char* utf8){
|
int ncdirect_putstr(ncdirect* nc, uint64_t channels, const char* utf8){
|
||||||
if(channels_fg_default_p(channels)){
|
if(channels_fg_default_p(channels)){
|
||||||
if(ncdirect_fg_default(nc)){
|
if(ncdirect_fg_default_p(nc)){
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}else if(ncdirect_fg_rgb(nc, channels_fg_rgb(channels))){
|
}else if(ncdirect_fg_rgb(nc, channels_fg_rgb(channels))){
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if(channels_bg_default_p(channels)){
|
if(channels_bg_default_p(channels)){
|
||||||
if(ncdirect_bg_default(nc)){
|
if(ncdirect_set_bg_default(nc)){
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}else if(ncdirect_bg_rgb(nc, channels_bg_rgb(channels))){
|
}else if(ncdirect_bg_rgb(nc, channels_bg_rgb(channels))){
|
||||||
@ -372,8 +387,10 @@ ncdirect_dump_plane(ncdirect* n, const ncplane* np, int xoff){
|
|||||||
ncplane_dim_yx(np, &dimy, &dimx);
|
ncplane_dim_yx(np, &dimy, &dimx);
|
||||||
//fprintf(stderr, "rasterizing %dx%d+%d\n", dimy, dimx, xoff);
|
//fprintf(stderr, "rasterizing %dx%d+%d\n", dimy, dimx, xoff);
|
||||||
// save the existing style and colors
|
// save the existing style and colors
|
||||||
bool fgdefault = n->fgdefault, bgdefault = n->bgdefault;
|
const bool fgdefault = ncdirect_fg_default_p(n);
|
||||||
uint32_t fgrgb = n->fgrgb, bgrgb = n->bgrgb;
|
const bool bgdefault = ncdirect_bg_default_p(n);
|
||||||
|
const uint32_t fgrgb = channels_fg_rgb(n->channels);
|
||||||
|
const uint32_t bgrgb = channels_bg_rgb(n->channels);
|
||||||
for(int y = 0 ; y < dimy ; ++y){
|
for(int y = 0 ; y < dimy ; ++y){
|
||||||
if(xoff){
|
if(xoff){
|
||||||
if(ncdirect_cursor_move_yx(n, -1, xoff)){
|
if(ncdirect_cursor_move_yx(n, -1, xoff)){
|
||||||
@ -388,12 +405,12 @@ ncdirect_dump_plane(ncdirect* n, const ncplane* np, int xoff){
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if(channels_fg_alpha(channels) == CELL_ALPHA_TRANSPARENT){
|
if(channels_fg_alpha(channels) == CELL_ALPHA_TRANSPARENT){
|
||||||
ncdirect_fg_default(n);
|
ncdirect_set_fg_default(n);
|
||||||
}else{
|
}else{
|
||||||
ncdirect_fg_rgb(n, channels_fg_rgb(channels));
|
ncdirect_fg_rgb(n, channels_fg_rgb(channels));
|
||||||
}
|
}
|
||||||
if(channels_bg_alpha(channels) == CELL_ALPHA_TRANSPARENT){
|
if(channels_bg_alpha(channels) == CELL_ALPHA_TRANSPARENT){
|
||||||
ncdirect_bg_default(n);
|
ncdirect_set_bg_default(n);
|
||||||
}else{
|
}else{
|
||||||
ncdirect_bg_rgb(n, channels_bg_rgb(channels));
|
ncdirect_bg_rgb(n, channels_bg_rgb(channels));
|
||||||
}
|
}
|
||||||
@ -408,8 +425,8 @@ ncdirect_dump_plane(ncdirect* n, const ncplane* np, int xoff){
|
|||||||
// each line of output; this is necessary if our output is lifted out and
|
// each line of output; this is necessary if our output is lifted out and
|
||||||
// used in something e.g. paste(1).
|
// used in something e.g. paste(1).
|
||||||
// FIXME replace with a SGR clear
|
// FIXME replace with a SGR clear
|
||||||
ncdirect_fg_default(n);
|
ncdirect_set_fg_default(n);
|
||||||
ncdirect_bg_default(n);
|
ncdirect_set_bg_default(n);
|
||||||
if(putc('\n', n->ttyfp) == EOF){
|
if(putc('\n', n->ttyfp) == EOF){
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -421,12 +438,12 @@ ncdirect_dump_plane(ncdirect* n, const ncplane* np, int xoff){
|
|||||||
}
|
}
|
||||||
// restore the previous colors
|
// restore the previous colors
|
||||||
if(fgdefault){
|
if(fgdefault){
|
||||||
ncdirect_fg_default(n);
|
ncdirect_set_fg_default(n);
|
||||||
}else{
|
}else{
|
||||||
ncdirect_fg_rgb(n, fgrgb);
|
ncdirect_fg_rgb(n, fgrgb);
|
||||||
}
|
}
|
||||||
if(bgdefault){
|
if(bgdefault){
|
||||||
ncdirect_bg_default(n);
|
ncdirect_set_bg_default(n);
|
||||||
}else{
|
}else{
|
||||||
ncdirect_bg_rgb(n, bgrgb);
|
ncdirect_bg_rgb(n, bgrgb);
|
||||||
}
|
}
|
||||||
@ -610,8 +627,7 @@ ncdirect* ncdirect_init(const char* termtype, FILE* outfp, uint64_t flags){
|
|||||||
if(interrogate_terminfo(&ret->tcache, shortname_term)){
|
if(interrogate_terminfo(&ret->tcache, shortname_term)){
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
ret->fgdefault = ret->bgdefault = true;
|
ret->channels = 0;
|
||||||
ret->fgrgb = ret->bgrgb = 0;
|
|
||||||
ncdirect_set_styles(ret, 0);
|
ncdirect_set_styles(ret, 0);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
@ -669,11 +685,12 @@ ncdirect_style_emit(ncdirect* n, unsigned stylebits, FILE* out){
|
|||||||
}
|
}
|
||||||
// sgr resets colors, so set them back up if not defaults
|
// sgr resets colors, so set them back up if not defaults
|
||||||
if(r == 0){
|
if(r == 0){
|
||||||
if(!n->fgdefault){
|
// FIXME need to handle palette-indexed colors
|
||||||
r |= ncdirect_fg_rgb(n, n->fgrgb);
|
if(!ncdirect_fg_default_p(n)){
|
||||||
|
r |= ncdirect_fg_rgb(n, channels_fg_rgb(n->channels));
|
||||||
}
|
}
|
||||||
if(!n->bgdefault){
|
if(!ncdirect_bg_default_p(n)){
|
||||||
r |= ncdirect_bg_rgb(n, n->bgrgb);
|
r |= ncdirect_bg_rgb(n, channels_bg_rgb(n->channels));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
@ -750,26 +767,42 @@ unsigned ncdirect_palette_size(const ncdirect* nc){
|
|||||||
return nc->tcache.colors;
|
return nc->tcache.colors;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ncdirect_fg_default(ncdirect* nc){
|
int ncdirect_set_fg_default(ncdirect* nc){
|
||||||
if(term_emit("op", nc->tcache.op, nc->ttyfp, false) == 0){
|
if(ncdirect_fg_default_p(nc)){
|
||||||
nc->fgdefault = true;
|
return 0;
|
||||||
if(nc->bgdefault){
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return ncdirect_bg_rgb(nc, nc->bgrgb);
|
|
||||||
}
|
}
|
||||||
return -1;
|
if(nc->tcache.fgop){
|
||||||
|
if(term_emit("fgop", nc->tcache.fgop, nc->ttyfp, false)){
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}else if(term_emit("op", nc->tcache.op, nc->ttyfp, false) == 0){
|
||||||
|
if(!ncdirect_bg_default_p(nc)){
|
||||||
|
if(ncdirect_bg_rgb(nc, channels_bg_rgb(nc->channels))){
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
channels_set_fg_default(&nc->channels);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ncdirect_bg_default(ncdirect* nc){
|
int ncdirect_set_bg_default(ncdirect* nc){
|
||||||
if(term_emit("op", nc->tcache.op, nc->ttyfp, false) == 0){
|
if(ncdirect_bg_default_p(nc)){
|
||||||
nc->bgdefault = true;
|
return 0;
|
||||||
if(nc->fgdefault){
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return ncdirect_fg_rgb(nc, nc->fgrgb);
|
|
||||||
}
|
}
|
||||||
return -1;
|
if(nc->tcache.bgop){
|
||||||
|
if(term_emit("bgop", nc->tcache.bgop, nc->ttyfp, false)){
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}else if(term_emit("op", nc->tcache.op, nc->ttyfp, false) == 0){
|
||||||
|
if(!ncdirect_fg_default_p(nc)){
|
||||||
|
if(ncdirect_fg_rgb(nc, channels_fg_rgb(nc->channels))){
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
channels_set_bg_default(&nc->channels);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ncdirect_hline_interp(ncdirect* n, const char* egc, int len,
|
int ncdirect_hline_interp(ncdirect* n, const char* egc, int len,
|
||||||
|
@ -304,10 +304,9 @@ typedef struct ncdirect {
|
|||||||
FILE* ttyfp; // FILE* for output tty
|
FILE* ttyfp; // FILE* for output tty
|
||||||
int ctermfd; // fd for controlling terminal
|
int ctermfd; // fd for controlling terminal
|
||||||
tinfo tcache; // terminfo cache
|
tinfo tcache; // terminfo cache
|
||||||
unsigned fgrgb, bgrgb; // last RGB values of foreground/background
|
uint64_t channels; // current channels
|
||||||
uint16_t stylemask; // current styles
|
uint16_t stylemask; // current styles
|
||||||
ncinputlayer input; // input layer; we're in cbreak mode
|
ncinputlayer input; // input layer; we're in cbreak mode
|
||||||
bool fgdefault, bgdefault; // are FG/BG currently using default colors?
|
|
||||||
bool utf8; // are we using utf-8 encoding, as hoped?
|
bool utf8; // are we using utf-8 encoding, as hoped?
|
||||||
struct termios tpreserved; // terminal state upon entry
|
struct termios tpreserved; // terminal state upon entry
|
||||||
// some terminals (e.g. kmscon) return cursor coordinates inverted from the
|
// some terminals (e.g. kmscon) return cursor coordinates inverted from the
|
||||||
|
@ -1241,8 +1241,7 @@ int ncdirect_bg_rgb(ncdirect* nc, unsigned rgb){
|
|||||||
nc->tcache.bg_collides_default)){
|
nc->tcache.bg_collides_default)){
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
nc->bgdefault = false;
|
channels_set_bg_rgb(&nc->channels, rgb);
|
||||||
nc->bgrgb = rgb;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1254,8 +1253,7 @@ int ncdirect_fg_rgb(ncdirect* nc, unsigned rgb){
|
|||||||
(rgb & 0xff0000u) >> 16u, (rgb & 0xff00u) >> 8u, rgb & 0xffu)){
|
(rgb & 0xff0000u) >> 16u, (rgb & 0xff00u) >> 8u, rgb & 0xffu)){
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
nc->fgdefault = false;
|
channels_set_fg_rgb(&nc->channels, rgb);
|
||||||
nc->fgrgb = rgb;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,8 +107,8 @@ int main(void){
|
|||||||
|
|
||||||
int leny = ncdirect_dim_y(nc);
|
int leny = ncdirect_dim_y(nc);
|
||||||
int lenx = ncdirect_dim_x(nc);
|
int lenx = ncdirect_dim_x(nc);
|
||||||
ncdirect_fg_default(nc);
|
ncdirect_set_fg_default(nc);
|
||||||
ncdirect_bg_default(nc);
|
ncdirect_set_bg_default(nc);
|
||||||
if(ncdirect_cursor_move_yx(nc, leny / 2, (lenx - 4) / 2)){
|
if(ncdirect_cursor_move_yx(nc, leny / 2, (lenx - 4) / 2)){
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
@ -15,8 +15,8 @@ int main(void){
|
|||||||
if(ncdirect_hline_interp(n, "-", i, c1, c2) < i){
|
if(ncdirect_hline_interp(n, "-", i, c1, c2) < i){
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
ncdirect_fg_default(n);
|
ncdirect_set_fg_default(n);
|
||||||
ncdirect_bg_default(n);
|
ncdirect_set_bg_default(n);
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
}
|
}
|
||||||
for(int i = 0 ; i < 15 ; ++i){
|
for(int i = 0 ; i < 15 ; ++i){
|
||||||
@ -26,8 +26,8 @@ int main(void){
|
|||||||
if(ncdirect_vline_interp(n, "|", i, c1, c2) < i){
|
if(ncdirect_vline_interp(n, "|", i, c1, c2) < i){
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
ncdirect_fg_default(n);
|
ncdirect_set_fg_default(n);
|
||||||
ncdirect_bg_default(n);
|
ncdirect_set_bg_default(n);
|
||||||
if(i < 14){
|
if(i < 14){
|
||||||
if(ncdirect_cursor_up(n, i)){
|
if(ncdirect_cursor_up(n, i)){
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
Loading…
Reference in New Issue
Block a user