From b980d7deee29326aad3e2dba0a2028abc80fb066 Mon Sep 17 00:00:00 2001 From: nick black Date: Fri, 14 Aug 2020 15:55:27 -0400 Subject: [PATCH] sgr-direct PoC --- src/demo/zoo.c | 2 +- src/poc/sgr-direct.c | 30 ++++++++++++++++++++++++++++++ src/poc/sgr.c | 19 +++++++++---------- 3 files changed, 40 insertions(+), 11 deletions(-) create mode 100644 src/poc/sgr-direct.c diff --git a/src/demo/zoo.c b/src/demo/zoo.c index 5742feeeb..e629a19d2 100644 --- a/src/demo/zoo.c +++ b/src/demo/zoo.c @@ -320,7 +320,7 @@ reader_thread(void* vmarsh){ // we usually won't be done rendering the text before reaching our target row size_t textpos = 0; int ret; - const int MAXTOWRITE = 8; + const size_t MAXTOWRITE = 8; bool collect_input = false; while(textpos < textlen || y > targrow){ pthread_mutex_lock(lock); diff --git a/src/poc/sgr-direct.c b/src/poc/sgr-direct.c new file mode 100644 index 000000000..3067757c8 --- /dev/null +++ b/src/poc/sgr-direct.c @@ -0,0 +1,30 @@ +#include +#include +#include +#include +#include + +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; +} diff --git a/src/poc/sgr.c b/src/poc/sgr.c index e6cf1cfc6..34d1ae60d 100644 --- a/src/poc/sgr.c +++ b/src/poc/sgr.c @@ -44,8 +44,8 @@ int main(int argc, char** argv){ fprintf(stderr, "Couldn't get terminfo entry for sgr\n"); return EXIT_FAILURE; } - int sgrs[9] = { 0 }; - int pivot = 8; + int sgrs[8] = { 0 }; + int pivot = sizeof(sgrs) / sizeof(*sgrs); if(DISABLE_ALTCHARSET){ --pivot; } @@ -53,22 +53,21 @@ int main(int argc, char** argv){ // generate all values int cols = 0; while(pivot >= 0){ - int i; - for(i = 0 ; i < 9 ; ++i){ + for(size_t i = 0 ; i < sizeof(sgrs) / sizeof(*sgrs) ; ++i){ cols += printf("%c", sgrs[i] ? '1' : '0'); } 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])); - if(i != OK){ + if(r != OK){ return EXIT_FAILURE; } - if((i = printf(" %s ", argv[0])) < 0){ + if((r = printf(" %s ", argv[0])) < 0){ return EXIT_FAILURE; } - cols += i; - i = putp(tiparm(sgr, 0, 0, 0, 0, 0, 0, 0, 0, 0)); - if(i != OK){ + cols += r; + r = putp(tiparm(sgr, 0, 0, 0, 0, 0, 0, 0, 0, 0)); + if(r != OK){ return EXIT_FAILURE; } pivot = pivot_on(pivot, sgrs, sgrcount);