From dfcdd10cb577c0888ebfcb150d4b47b74519ec6a Mon Sep 17 00:00:00 2001 From: nick black Date: Wed, 15 Jan 2020 06:25:13 -0500 Subject: [PATCH] more palette support/testing #230 --- src/lib/internal.h | 1 + src/lib/notcurses.c | 10 +++++++++- tests/palette.cpp | 24 ++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/lib/internal.h b/src/lib/internal.h index ed777f7e1..c688b8f24 100644 --- a/src/lib/internal.h +++ b/src/lib/internal.h @@ -182,6 +182,7 @@ typedef struct notcurses { unsigned inputbuf_occupied; unsigned inputbuf_valid_starts; unsigned inputbuf_write_at; + palette256 palette; // 256-indexed palette can be used instead of RGB struct esctrie* inputescapes; // trie of input escapes -> ncspecial_keys } notcurses; diff --git a/src/lib/notcurses.c b/src/lib/notcurses.c index 8b01d0e6c..588c31d23 100644 --- a/src/lib/notcurses.c +++ b/src/lib/notcurses.c @@ -1646,8 +1646,16 @@ palette256* palette256_new(void){ int palette256_use(notcurses* nc, const palette256* p){ int ret = -1; + if(!nc->CCCflag){ + return -1; + } pthread_mutex_lock(&nc->lock); - // FIXME load it + for(size_t z = 0 ; z < sizeof(p->chans) / sizeof(*p->chans) ; ++z){ + if(nc->palette.chans[z] != p->chans[z]){ + nc->palette.chans[z] = p->chans[z]; + // FIXME write it to terminal using initc, need another damage map + } + } pthread_mutex_unlock(&nc->lock); return ret; } diff --git a/tests/palette.cpp b/tests/palette.cpp index 83d2b8034..33613a047 100644 --- a/tests/palette.cpp +++ b/tests/palette.cpp @@ -23,6 +23,30 @@ TEST_CASE("Palette256") { palette256_free(p); } + SUBCASE("SetIndexZero") { + palette256* p = palette256_new(); + REQUIRE(nullptr != p); + palette256_set_rgb(p, 0, 0x80, 0x90, 0xa0); + unsigned r, g, b; + palette256_get(p, 0, &r, &g, &b); + CHECK(r == 0x80); + CHECK(g == 0x90); + CHECK(b == 0xa0); + palette256_free(p); + } + + SUBCASE("SetIndex255") { + palette256* p = palette256_new(); + REQUIRE(nullptr != p); + palette256_set_rgb(p, 255, 0xa0, 0x70, 0x50); + unsigned r, g, b; + palette256_get(p, 255, &r, &g, &b); + CHECK(r == 0xa0); + CHECK(g == 0x70); + CHECK(b == 0x50); + palette256_free(p); + } + // common teardown CHECK(0 == notcurses_stop(nc_)); CHECK(0 == fclose(outfp_));