direct mode: reset terminal, check vals #77

pull/296/head
nick black 5 years ago
parent 1fd0563093
commit 81b58234ee
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

@ -918,6 +918,15 @@ err:
int ncdirect_stop(ncdirect* nc){ int ncdirect_stop(ncdirect* nc){
int ret = 0; int ret = 0;
if(nc){ 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); free(nc);
} }
return ret; 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){ 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); 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){ 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); return term_fg_rgb8(nc->RGBflag, nc->setaf, nc->colors, nc->ttyfp, r, g, b);
} }

@ -5,6 +5,40 @@
#include <locale.h> #include <locale.h>
#include <notcurses.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 // direct-mode generation of 4096 RGB foregrounds
int main(void){ int main(void){
if(!setlocale(LC_ALL, "")){ if(!setlocale(LC_ALL, "")){
@ -14,20 +48,10 @@ int main(void){
if(!nc){ if(!nc){
return EXIT_FAILURE; return EXIT_FAILURE;
} }
for(int r = 0 ; r < 256 ; r += 16){ for(int t = 0xf ; t < 768 ; t += 16){
for(int g = 0 ; g < 256 ; g += 16){ if(print_rgb(nc, t)){
for(int b = 0 ; b < 256 ; b += 16){ ncdirect_stop(nc);
int ret = ncdirect_fg_rgb8(nc, r, g, b); return EXIT_FAILURE;
if(ret){
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"); printf("\n");

Loading…
Cancel
Save