uniblock: restore colors/fade

This commit is contained in:
nick black 2020-01-04 06:39:57 -05:00
parent 5dd90f3735
commit a748dea61b

View File

@ -10,6 +10,13 @@
#define BLOCKSIZE 512 // show this many per page
#define CHUNKSIZE 32 // show this many per line
static int
fade_block(struct ncplane* nn, const struct timespec* subdelay){
int ret = ncplane_fadein(nn, subdelay, NULL);
ncplane_destroy(nn);
return ret;
}
static int
draw_block(struct ncplane* nn, uint32_t blockstart){
cell ul = CELL_TRIVIAL_INITIALIZER, ur = CELL_TRIVIAL_INITIALIZER;
@ -41,12 +48,11 @@ draw_block(struct ncplane* nn, uint32_t blockstart){
return -1;
}
int z;
cell c = CELL_TRIVIAL_INITIALIZER;
// 16 to a line
for(z = 0 ; z < CHUNKSIZE ; ++z){
wchar_t w[2] = { blockstart + chunk * CHUNKSIZE + z, L'\u200e' };
wchar_t w[3] = { blockstart + chunk * CHUNKSIZE + z, L'\u200e', L'\0' };
char utf8arr[MB_CUR_MAX * 2 + 1];
if(wcswidth(w, 2) >= 1 && iswprint(w[0])){
if(wcswidth(w, 3) >= 1 && iswprint(w[0])){
mbstate_t ps;
memset(&ps, 0, sizeof(ps));
const wchar_t *wptr = w;
@ -61,8 +67,8 @@ draw_block(struct ncplane* nn, uint32_t blockstart){
}else{ // don't dump non-printing codepoints
strcpy(utf8arr, " ");
}
cell_set_fg_rgb(&c, 0xad + z * 2, 0xd8, 0xe6 - z * 2);
cell_set_bg_rgb(&c, 8 * chunk, 8 * chunk + z, 8 * chunk);
ncplane_set_fg_rgb(nn, 0xad + z * 2, 0xd8, 0xe6 - z * 2);
ncplane_set_bg_rgb(nn, 8 * chunk, 8 * chunk + z, 8 * chunk);
if(ncplane_putstr(nn, utf8arr) < 0){
return -1;
}
@ -72,7 +78,6 @@ draw_block(struct ncplane* nn, uint32_t blockstart){
}
}
}
cell_release(nn, &c);
}
return 0;
}
@ -187,9 +192,9 @@ int unicodeblocks_demo(struct notcurses* nc){
if(ncplane_printf_aligned(n, 6 + BLOCKSIZE / CHUNKSIZE, NCALIGN_CENTER, "%s", description) <= 0){
return -1;
}
notcurses_render(nc);
nanosleep(&subdelay, NULL);
ncplane_destroy(nn);
if(fade_block(nn, &subdelay)){ // destroys nn
return -1;
}
// for a 32-bit wchar_t, we would want up through 24 bits of block ID. but
// really, the vast majority of space is unused.
blockstart += BLOCKSIZE;