mirror of
https://github.com/dankamongmen/notcurses.git
synced 2024-11-18 03:25:55 +00:00
direct mode: reset terminal, check vals #77
This commit is contained in:
parent
1fd0563093
commit
81b58234ee
@ -918,6 +918,15 @@ err:
|
||||
int ncdirect_stop(ncdirect* nc){
|
||||
int ret = 0;
|
||||
if(nc){
|
||||
if(nc->op && term_emit("op", nc->op, nc->ttyfp, true)){
|
||||
ret = -1;
|
||||
}
|
||||
if(nc->sgr0 && term_emit("sgr0", nc->sgr0, nc->ttyfp, true)){
|
||||
ret = -1;
|
||||
}
|
||||
if(nc->oc && term_emit("oc", nc->oc, nc->ttyfp, true)){
|
||||
ret = -1;
|
||||
}
|
||||
free(nc);
|
||||
}
|
||||
return ret;
|
||||
|
@ -609,10 +609,16 @@ term_fg_rgb8(bool RGBflag, const char* setaf, int colors, FILE* out,
|
||||
}
|
||||
|
||||
int ncdirect_bg_rgb8(ncdirect* nc, unsigned r, unsigned g, unsigned b){
|
||||
if(r > 255 || g > 255 || b > 255){
|
||||
return -1;
|
||||
}
|
||||
return term_bg_rgb8(nc->RGBflag, nc->setab, nc->colors, nc->ttyfp, r, g, b);
|
||||
}
|
||||
|
||||
int ncdirect_fg_rgb8(ncdirect* nc, unsigned r, unsigned g, unsigned b){
|
||||
if(r > 255 || g > 255 || b > 255){
|
||||
return -1;
|
||||
}
|
||||
return term_fg_rgb8(nc->RGBflag, nc->setaf, nc->colors, nc->ttyfp, r, g, b);
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,40 @@
|
||||
#include <locale.h>
|
||||
#include <notcurses.h>
|
||||
|
||||
static int
|
||||
print_b(struct ncdirect* nc, int r, int g, int total){
|
||||
int b = total - (r + g);
|
||||
if(b > 255){
|
||||
return 0;
|
||||
}
|
||||
int ret = ncdirect_fg_rgb8(nc, r, g, b);
|
||||
if(ret){
|
||||
return -1;
|
||||
}
|
||||
printf("X");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
print_gb(struct ncdirect* nc, int r, int total){
|
||||
for(int g = 0xf ; g <= total - r && g < 256 ; g += 16){
|
||||
if(print_b(nc, r, g, total)){
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
print_rgb(struct ncdirect* nc, int total){
|
||||
for(int r = 0xf ; r <= total && r < 256 ; r += 16){
|
||||
if(print_gb(nc, r, total)){
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// direct-mode generation of 4096 RGB foregrounds
|
||||
int main(void){
|
||||
if(!setlocale(LC_ALL, "")){
|
||||
@ -14,21 +48,11 @@ int main(void){
|
||||
if(!nc){
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
for(int r = 0 ; r < 256 ; r += 16){
|
||||
for(int g = 0 ; g < 256 ; g += 16){
|
||||
for(int b = 0 ; b < 256 ; b += 16){
|
||||
int ret = ncdirect_fg_rgb8(nc, r, g, b);
|
||||
if(ret){
|
||||
for(int t = 0xf ; t < 768 ; t += 16){
|
||||
if(print_rgb(nc, t)){
|
||||
ncdirect_stop(nc);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
printf("X");
|
||||
if(fflush(stdout) == EOF){
|
||||
fprintf(stderr, "Error flushing stdout (%s)\n", strerror(errno));
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
if(ncdirect_stop(nc)){
|
||||
|
Loading…
Reference in New Issue
Block a user