sync cell/ncplane fg/bg API naming

This commit is contained in:
nick black 2019-12-06 22:45:08 -05:00
parent 80821ba0e5
commit 8afcd04446
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC
13 changed files with 56 additions and 38 deletions

View File

@ -515,8 +515,8 @@ void ncplane_erase(struct ncplane* n);
// will be interpreted in some lossy fashion. None of r, g, or b may exceed 255.
// "HP-like" terminals require setting foreground and background at the same
// time using "color pairs"; notcurses will manage color pairs transparently.
int ncplane_fg_rgb8(struct ncplane* n, int r, int g, int b);
int ncplane_bg_rgb8(struct ncplane* n, int r, int g, int b);
int ncplane_set_fg(struct ncplane* n, int r, int g, int b);
int ncplane_set_bg(struct ncplane* n, int r, int g, int b);
// use the default color for the foreground/background
void ncplane_fg_default(struct ncplane* n);
@ -1043,7 +1043,25 @@ mapping your colors to RGB values and color pairs to foreground and background
indices into said table.
I have adapted two large (~5k lines of C UI code each) from NCURSES to
notcurses, and found it a fairly painless process.
notcurses, and found it a fairly painless process. It was helpful to introduce
a shim layer, e.g. `compat_mvwprintw` for NCURSES's `mvwprintw`:
```c
static int
compat_mvwprintw(struct ncplane* nc, int y, int x, const char* fmt, ...){
if(ncplane_cursor_move_yx(nc, y, x)){
return ERR;
}
va_list va;
va_start(va, fmt);
if(ncplane_vprintf(nc, fmt, va) < 0){
va_end(va);
return ERR;
}
va_end(va);
return OK;
}
```
## Environment notes

View File

@ -439,8 +439,8 @@ API void ncplane_erase(struct ncplane* n);
// will be interpreted in some lossy fashion. None of r, g, or b may exceed 255.
// "HP-like" terminals require setting foreground and background at the same
// time using "color pairs"; notcurses will manage color pairs transparently.
API int ncplane_fg_rgb8(struct ncplane* n, int r, int g, int b);
API int ncplane_bg_rgb8(struct ncplane* n, int r, int g, int b);
API int ncplane_set_fg(struct ncplane* n, int r, int g, int b);
API int ncplane_set_bg(struct ncplane* n, int r, int g, int b);
// use the default color for the foreground/background
API void ncplane_fg_default(struct ncplane* n);

View File

@ -13,8 +13,8 @@ int box_demo(struct notcurses* nc){
cell ul = CELL_TRIVIAL_INITIALIZER, ll = CELL_TRIVIAL_INITIALIZER;
cell lr = CELL_TRIVIAL_INITIALIZER, ur = CELL_TRIVIAL_INITIALIZER;
cell hl = CELL_TRIVIAL_INITIALIZER, vl = CELL_TRIVIAL_INITIALIZER;
ncplane_fg_rgb8(n, 255, 255, 255);
ncplane_bg_rgb8(n, 180, 40, 180);
ncplane_set_fg(n, 255, 255, 255);
ncplane_set_bg(n, 180, 40, 180);
if(cells_double_box(n, 0, 0, &ul, &ur, &ll, &lr, &hl, &vl)){
return -1;
}

View File

@ -68,10 +68,10 @@ outro_message(struct notcurses* nc, int rows, int cols){
ncplane_set_background(on, &bgcell);
ncplane_dim_yx(on, &rows, &cols);
int ybase = 0;
if(ncplane_fg_rgb8(on, 0, 0, 0)){
if(ncplane_set_fg(on, 0, 0, 0)){
return -1;
}
if(ncplane_bg_rgb8(on, 0, 180, 180)){
if(ncplane_set_bg(on, 0, 180, 180)){
return -1;
}
if(ncplane_cursor_move_yx(on, ++ybase, (cols - strlen(str0)) / 2)){
@ -168,10 +168,10 @@ intro(struct notcurses* nc){
}
const char s1[] = " Die Welt ist alles, was der Fall ist. ";
const char str[] = " Wovon man nicht sprechen kann, darüber muss man schweigen. ";
if(ncplane_fg_rgb8(ncp, 192, 192, 192)){
if(ncplane_set_fg(ncp, 192, 192, 192)){
return -1;
}
if(ncplane_bg_rgb8(ncp, 0, 40, 0)){
if(ncplane_set_bg(ncp, 0, 40, 0)){
return -1;
}
if(ncplane_cursor_move_yx(ncp, rows / 2 - 2, (cols - strlen(s1) + 4) / 2)){

View File

@ -32,7 +32,7 @@ int maxcolor_demo(struct notcurses* nc){
int maxx, maxy;
notcurses_term_dim_yx(nc, &maxy, &maxx);
struct ncplane* n = notcurses_stdplane(nc);
ncplane_fg_rgb8(n, 255, 255, 255);
ncplane_set_fg(n, 255, 255, 255);
uint64_t channels = 0;
notcurses_fg_prep(&channels, 0, 128, 128);
notcurses_bg_prep(&channels, 90, 0, 90);

View File

@ -128,7 +128,7 @@ tabletdraw(struct ncplane* p, int begx, int begy, int maxx, int maxy,
}else{
ll = tabletdown(p, begx, begy, maxx, maxy, tctx, rgb);
}
ncplane_fg_rgb8(p, 242, 242, 242);
ncplane_set_fg(p, 242, 242, 242);
if(ll){
int summaryy = begy;
if(cliptop){
@ -269,7 +269,7 @@ panelreel_demo_core(struct notcurses* nc, int efd, tabletctx** tctxs){
}
// Press a for a new panel above the current, c for a new one below the
// current, and b for a new block at arbitrary placement. q quits.
ncplane_fg_rgb8(w, 58, 150, 221);
ncplane_set_fg(w, 58, 150, 221);
ncplane_bg_default(w);
ncplane_cursor_move_yx(w, 1, 1);
ncplane_printf(w, "a, b, c create tablets, DEL deletes, q quits.");
@ -283,12 +283,12 @@ panelreel_demo_core(struct notcurses* nc, int efd, tabletctx** tctxs){
unsigned id = 0;
do{
ncplane_styles_set(w, 0);
ncplane_fg_rgb8(w, 197, 15, 31);
ncplane_set_fg(w, 197, 15, 31);
int count = panelreel_tabletcount(pr);
ncplane_cursor_move_yx(w, 2, 2);
ncplane_printf(w, "%d tablet%s", count, count == 1 ? "" : "s");
// FIXME wclrtoeol(w);
ncplane_fg_rgb8(w, 0, 55, 218);
ncplane_set_fg(w, 0, 55, 218);
ncspecial_key special = NCKEY_INVALID;
cell c = CELL_TRIVIAL_INITIALIZER;
if(handle_input(nc, pr, efd, &c, &special) < 0){

View File

@ -113,8 +113,8 @@ fill_chunk(struct ncplane* n, int idx){
if(ncplane_cursor_move_yx(n, (maxy - 1) / 2, (maxx - 2) / 2)){
return -1;
}
ncplane_fg_rgb8(n, 0, 0, 0);
ncplane_bg_rgb8(n, r, g, b);
ncplane_set_fg(n, 0, 0, 0);
ncplane_set_bg(n, r, g, b);
if(ncplane_putstr(n, buf) <= 0){
return -1;
}

View File

@ -99,7 +99,7 @@ int unicodeblocks_demo(struct notcurses* nc){
uint32_t blockstart = blocks[sindex].start;
const char* description = blocks[sindex].name;
int chunk;
ncplane_fg_rgb8(n, 0xad, 0xd8, 0xe6);
ncplane_set_fg(n, 0xad, 0xd8, 0xe6);
if(ncplane_cursor_move_yx(n, 1, (maxx - 26) / 2)){
return -1;
}
@ -171,7 +171,7 @@ int unicodeblocks_demo(struct notcurses* nc){
}
cell_release(n, &c);
}
ncplane_fg_rgb8(n, 0x40, 0xc0, 0x40);
ncplane_set_fg(n, 0x40, 0xc0, 0x40);
if(ncplane_cursor_move_yx(n, 6 + BLOCKSIZE / CHUNKSIZE, 0)){
return -1;
}

View File

@ -272,8 +272,8 @@ static int
message(struct ncplane* n, int maxy, int maxx, int num, int total,
int bytes_out, int egs_out, int cols_out){
uint64_t channels = 0;
ncplane_fg_rgb8(n, 64, 128, 240);
ncplane_bg_rgb8(n, 32, 64, 32);
ncplane_set_fg(n, 64, 128, 240);
ncplane_set_bg(n, 32, 64, 32);
notcurses_fg_prep(&channels, 255, 255, 255);
notcurses_bg_default_prep(&channels);
ncplane_cursor_move_yx(n, 3, 1);
@ -322,9 +322,9 @@ message(struct ncplane* n, int maxy, int maxx, int num, int total,
ncplane_printf(n, " %03dx%03d (%d/%d) ", maxx, maxy, num + 1, total);
ncplane_cursor_move_yx(n, 4, 2);
ncplane_styles_off(n, CELL_STYLE_ITALIC);
ncplane_fg_rgb8(n, 224, 128, 224);
ncplane_set_fg(n, 224, 128, 224);
ncplane_putstr(n, " 🔥 wide chars, multiple colors, resize awareness…🔥 ");
ncplane_fg_rgb8(n, 255, 255, 255);
ncplane_set_fg(n, 255, 255, 255);
return 0;
}

View File

@ -63,7 +63,7 @@ int main(void){
int r;
notcurses_term_dim_yx(nc, &dimy, &dimx);
cell c = CELL_TRIVIAL_INITIALIZER;
if(ncplane_fg_rgb8(n, 255, 255, 255)){
if(ncplane_set_fg(n, 255, 255, 255)){
notcurses_stop(nc);
return EXIT_FAILURE;
}

View File

@ -747,11 +747,11 @@ void ncplane_bg_default(struct ncplane* n){
n->channels &= ~(CELL_BGDEFAULT_MASK);
}
int ncplane_bg_rgb8(ncplane* n, int r, int g, int b){
int ncplane_set_bg(ncplane* n, int r, int g, int b){
return notcurses_bg_prep(&n->channels, r, g, b);
}
int ncplane_fg_rgb8(ncplane* n, int r, int g, int b){
int ncplane_set_fg(ncplane* n, int r, int g, int b){
return notcurses_fg_prep(&n->channels, r, g, b);
}

View File

@ -37,7 +37,7 @@ TEST_F(CellTest, SetStyles) {
notcurses_term_dim_yx(nc_, &dimy, &dimx);
cell_styles_set(&c, CELL_STYLE_ITALIC);
ASSERT_EQ(1, cell_load(n_, &c, "s"));
EXPECT_EQ(0, ncplane_fg_rgb8(n_, 255, 255, 255));
EXPECT_EQ(0, ncplane_set_fg(n_, 255, 255, 255));
EXPECT_EQ(1, ncplane_putc(n_, &c));
int x, y;
ncplane_cursor_yx(n_, &y, &x);

View File

@ -89,20 +89,20 @@ TEST_F(NcplaneTest, MoveBeyondPlaneFails) {
}
TEST_F(NcplaneTest, SetPlaneRGB) {
EXPECT_EQ(0, ncplane_fg_rgb8(n_, 0, 0, 0));
EXPECT_EQ(0, ncplane_fg_rgb8(n_, 255, 255, 255));
EXPECT_EQ(0, ncplane_set_fg(n_, 0, 0, 0));
EXPECT_EQ(0, ncplane_set_fg(n_, 255, 255, 255));
EXPECT_EQ(0, notcurses_render(nc_));
}
TEST_F(NcplaneTest, RejectBadRGB) {
EXPECT_NE(0, ncplane_fg_rgb8(n_, -1, 0, 0));
EXPECT_NE(0, ncplane_fg_rgb8(n_, 0, -1, 0));
EXPECT_NE(0, ncplane_fg_rgb8(n_, 0, 0, -1));
EXPECT_NE(0, ncplane_fg_rgb8(n_, -1, -1, -1));
EXPECT_NE(0, ncplane_fg_rgb8(n_, 256, 255, 255));
EXPECT_NE(0, ncplane_fg_rgb8(n_, 255, 256, 255));
EXPECT_NE(0, ncplane_fg_rgb8(n_, 255, 255, 256));
EXPECT_NE(0, ncplane_fg_rgb8(n_, 256, 256, 256));
EXPECT_NE(0, ncplane_set_fg(n_, -1, 0, 0));
EXPECT_NE(0, ncplane_set_fg(n_, 0, -1, 0));
EXPECT_NE(0, ncplane_set_fg(n_, 0, 0, -1));
EXPECT_NE(0, ncplane_set_fg(n_, -1, -1, -1));
EXPECT_NE(0, ncplane_set_fg(n_, 256, 255, 255));
EXPECT_NE(0, ncplane_set_fg(n_, 255, 256, 255));
EXPECT_NE(0, ncplane_set_fg(n_, 255, 255, 256));
EXPECT_NE(0, ncplane_set_fg(n_, 256, 256, 256));
}
// Verify we can emit a wide character, and it advances the cursor