notcurses_render(): call term_setstyles() for sgr stuff #11

pull/74/head
nick black 5 years ago committed by Nick Black
parent bc662e92bb
commit f65d168d83

@ -56,7 +56,7 @@ typedef struct cell {
// (values 0--0x7f), or a pointer into a per-ncplane attached pool of
// varying-length UTF-8 grapheme clusters. This pool may thus be up to 16MB.
uint32_t gcluster; // 1 * 4b -> 4b
// The classic NCURSES WA_* attributes (16 bits), plus 16 bits of alpha.
// The CELL_STYLE_* attributes (16 bits), plus 16 bits of alpha.
uint32_t attrword; // + 4b -> 8b
// (channels & 0x8000000000000000ull): inherit styling from prior cell
// (channels & 0x4000000000000000ull): foreground is *not* "default color"
@ -246,19 +246,19 @@ API int ncplane_bg_rgb8(struct ncplane* n, int r, int g, int b);
// Set the specified style bits for the ncplane 'n', whether they're actively
// supported or not.
API void ncplane_set_style(struct ncplane* n, unsigned stylebits);
API void ncplane_styles_set(struct ncplane* n, unsigned stylebits);
// Add the specified styles to the ncplane's existing spec.
API void ncplane_enable_styles(struct ncplane* n, unsigned stylebits);
API void ncplane_styles_on(struct ncplane* n, unsigned stylebits);
// Remove the specified styles from the ncplane's existing spec.
API void ncplane_disable_styles(struct ncplane* n, unsigned stylebits);
API void ncplane_styles_off(struct ncplane* n, unsigned stylebits);
// Fine details about terminal
// Returns a 16-bit bitmask in the LSBs of supported NCURSES-style attributes
// (WA_UNDERLINE, WA_BOLD, etc.) The attribute is only indicated as supported
// if the terminal can support it together with color.
// Returns a 16-bit bitmask in the LSBs of supported curses-style attributes
// (CELL_STYLE_UNDERLINE, CELL_STYLE_BOLD, etc.) The attribute is only
// indicated as supported if the terminal can support it together with color.
API unsigned notcurses_supported_styles(const struct notcurses* nc);
// Returns the number of colors supported by the palette, or 1 if there is no
@ -286,13 +286,23 @@ API int cell_duplicate(struct ncplane* n, cell* targ, const cell* c);
// Release resources held by the cell 'c'.
API void cell_release(struct ncplane* n, cell* c);
#define CELL_STYLE_SHIFT 16u
#define CELL_STYLE_MASK 0xffff0000ul
#define CELL_ALPHA_MASK 0x0000fffful
#define CELL_STYLE_STANDOUT (0x001u << CELL_STYLE_SHIFT)
#define CELL_STYLE_UNDERLINE (0x002u << CELL_STYLE_SHIFT)
#define CELL_STYLE_REVERSE (0x004u << CELL_STYLE_SHIFT)
#define CELL_STYLE_BLINK (0x008u << CELL_STYLE_SHIFT)
#define CELL_STYLE_DIM (0x010u << CELL_STYLE_SHIFT)
#define CELL_STYLE_BOLD (0x020u << CELL_STYLE_SHIFT)
#define CELL_STYLE_INVIS (0x040u << CELL_STYLE_SHIFT)
#define CELL_STYLE_PROTECT (0x080u << CELL_STYLE_SHIFT)
#define CELL_STYLE_ITALIC (0x100u << CELL_STYLE_SHIFT)
// Set the specified style bits for the cell 'c', whether they're actively
// supported or not.
static inline void
cell_set_style(cell* c, unsigned stylebits){
cell_styles_set(cell* c, unsigned stylebits){
c->attrword = (c->attrword & ~CELL_STYLE_MASK) |
((stylebits & 0xffff) << 16u);
}
@ -306,13 +316,13 @@ cell_get_style(const cell* c){
// Add the specified styles (in the LSBs) to the cell's existing spec, whether
// they're actively supported or not.
static inline void
cell_enable_styles(cell* c, unsigned stylebits){
cell_styles_on(cell* c, unsigned stylebits){
c->attrword |= ((stylebits & 0xffff) << 16u);
}
// Remove the specified styles (in the LSBs) from the cell's existing spec.
static inline void
cell_disable_styles(cell* c, unsigned stylebits){
cell_styles_off(cell* c, unsigned stylebits){
c->attrword &= ~((stylebits & 0xffff) << 16u);
}

@ -145,9 +145,11 @@ int main(int argc, char** argv){
if(ncplane_cursor_move_yx(ncp, rows / 2, (cols - strlen(str) + 4) / 2)){
goto err;
}
ncplane_styles_on(ncp, CELL_STYLE_ITALIC);
if(ncplane_putstr(ncp, str) != (int)strlen(str)){
goto err;
}
ncplane_styles_off(ncp, CELL_STYLE_ITALIC);
const wchar_t wstr[] = L"▏▁ ▂ ▃ ▄ ▅ ▆ ▇ █ █ ▇ ▆ ▅ ▄ ▃ ▂ ▁▕";
char mbstr[128];
if(wcstombs(mbstr, wstr, sizeof(mbstr)) <= 0){

@ -20,7 +20,7 @@ message(struct ncplane* n, int maxy, int maxx, int num, int total){
ncplane_cursor_move_yx(n, 3, 1);
ncplane_fg_rgb8(n, 255, 255, 255);
ncplane_bg_rgb8(n, 0, 20, 0);
ncplane_set_style(n, WA_BOLD);
ncplane_styles_on(n, CELL_STYLE_BOLD);
if(ncplane_box(n, &ul, &ur, &ll, &lr, &hl, &vl, 5, 54)){
return -1;
}
@ -45,7 +45,7 @@ message(struct ncplane* n, int maxy, int maxx, int num, int total){
ncplane_cursor_move_yx(n, 2, 5);
ncplane_printf(n, " %dx%d (%d/%d) ", maxx, maxy, num, total);
ncplane_cursor_move_yx(n, 4, 2);
ncplane_set_style(n, WA_NORMAL);
ncplane_styles_off(n, CELL_STYLE_BOLD);
ncplane_fg_rgb8(n, 200, 20, 200);
ncplane_putstr(n, " 🔥wide chars, multiple colors, resize awareness…🔥 ");
return 0;
@ -272,7 +272,6 @@ int widecolor_demo(struct notcurses* nc){
s = strs;
for(s = strs ; *s ; ++s){
cell wch = CELL_TRIVIAL_INITIALIZER;
cell_set_style(&wch, WA_NORMAL);
cell_set_fg(&wch, cell_rgb_red(rgb), 255 - cell_rgb_green(rgb),
cell_rgb_blue(rgb));
cell_set_bg(&wch, 64, 64, 64);

@ -972,15 +972,18 @@ int notcurses_palette_size(const notcurses* nc){
return nc->colors;
}
void ncplane_enable_styles(ncplane* n, unsigned stylebits){
// turn on any specified stylebits
void ncplane_styles_on(ncplane* n, unsigned stylebits){
n->attrword |= ((stylebits & 0xffff) << 16u);
}
void ncplane_disable_styles(ncplane* n, unsigned stylebits){
// turn off any specified stylebits
void ncplane_styles_off(ncplane* n, unsigned stylebits){
n->attrword &= ~((stylebits & 0xffff) << 16u);
}
void ncplane_set_style(ncplane* n, unsigned stylebits){
// set the current stylebits to exactly those provided
void ncplane_styles_set(ncplane* n, unsigned stylebits){
n->attrword = (n->attrword & ~CELL_STYLE_MASK) |
((stylebits & 0xffff) << 16u);
}

@ -30,7 +30,7 @@ class CellTest : public :: testing::Test {
TEST_F(CellTest, SetStyles) {
cell c;
memset(&c, 0, sizeof(c));
cell_set_style(&c, WA_ITALIC);
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(1, ncplane_putc(n_, &c));

Loading…
Cancel
Save