sgr-direct PoC

This commit is contained in:
nick black 2020-08-14 15:55:27 -04:00
parent b315c31141
commit b980d7deee
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC
3 changed files with 40 additions and 11 deletions

View File

@ -320,7 +320,7 @@ reader_thread(void* vmarsh){
// we usually won't be done rendering the text before reaching our target row // we usually won't be done rendering the text before reaching our target row
size_t textpos = 0; size_t textpos = 0;
int ret; int ret;
const int MAXTOWRITE = 8; const size_t MAXTOWRITE = 8;
bool collect_input = false; bool collect_input = false;
while(textpos < textlen || y > targrow){ while(textpos < textlen || y > targrow){
pthread_mutex_lock(lock); pthread_mutex_lock(lock);

30
src/poc/sgr-direct.c Normal file
View File

@ -0,0 +1,30 @@
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#include <assert.h>
#include <notcurses/direct.h>
int main(int argc, char** argv){
(void)argc;
if(!setlocale(LC_ALL, "")){
return EXIT_FAILURE;
}
struct ncdirect* nc = ncdirect_init(NULL, stdout);
if(!nc){
return EXIT_FAILURE;
}
int e = 0;
for(unsigned i = 0 ; i < (NCSTYLE_ITALIC << 1u) ; ++i){
if(ncdirect_styles_set(nc, i)){
ncdirect_stop(nc);
return EXIT_FAILURE;
}
printf("%08x ", i);
if(++e % 6 == 0){
printf("\n");
}
}
printf("\n");
ncdirect_stop(nc);
return EXIT_SUCCESS;
}

View File

@ -44,8 +44,8 @@ int main(int argc, char** argv){
fprintf(stderr, "Couldn't get terminfo entry for sgr\n"); fprintf(stderr, "Couldn't get terminfo entry for sgr\n");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
int sgrs[9] = { 0 }; int sgrs[8] = { 0 };
int pivot = 8; int pivot = sizeof(sgrs) / sizeof(*sgrs);
if(DISABLE_ALTCHARSET){ if(DISABLE_ALTCHARSET){
--pivot; --pivot;
} }
@ -53,22 +53,21 @@ int main(int argc, char** argv){
// generate all values // generate all values
int cols = 0; int cols = 0;
while(pivot >= 0){ while(pivot >= 0){
int i; for(size_t i = 0 ; i < sizeof(sgrs) / sizeof(*sgrs) ; ++i){
for(i = 0 ; i < 9 ; ++i){
cols += printf("%c", sgrs[i] ? '1' : '0'); cols += printf("%c", sgrs[i] ? '1' : '0');
} }
cols += printf(" (%02d)", pivot); cols += printf(" (%02d)", pivot);
i = putp(tiparm(sgr, sgrs[0], sgrs[1], sgrs[2], sgrs[3], sgrs[4], int r = putp(tiparm(sgr, sgrs[0], sgrs[1], sgrs[2], sgrs[3], sgrs[4],
sgrs[5], sgrs[6], sgrs[7], sgrs[8])); sgrs[5], sgrs[6], sgrs[7], sgrs[8]));
if(i != OK){ if(r != OK){
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if((i = printf(" %s ", argv[0])) < 0){ if((r = printf(" %s ", argv[0])) < 0){
return EXIT_FAILURE; return EXIT_FAILURE;
} }
cols += i; cols += r;
i = putp(tiparm(sgr, 0, 0, 0, 0, 0, 0, 0, 0, 0)); r = putp(tiparm(sgr, 0, 0, 0, 0, 0, 0, 0, 0, 0));
if(i != OK){ if(r != OK){
return EXIT_FAILURE; return EXIT_FAILURE;
} }
pivot = pivot_on(pivot, sgrs, sgrcount); pivot = pivot_on(pivot, sgrs, sgrcount);