From 26ea0b3785bf117ce84b0e53d7206feb2ee6b509 Mon Sep 17 00:00:00 2001 From: nick black Date: Sun, 16 Aug 2020 17:56:55 -0400 Subject: [PATCH 1/4] dirgb PoC: throw in some italics --- src/poc/dirgb.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/poc/dirgb.c b/src/poc/dirgb.c index 44dce5dd3..314b2342a 100644 --- a/src/poc/dirgb.c +++ b/src/poc/dirgb.c @@ -106,6 +106,7 @@ int main(void){ ncdirect_stop(nc); return EXIT_FAILURE; } + ncdirect_styles_on(nc, NCSTYLE_ITALIC); printf("dank\n"); if(ncdirect_stop(nc)){ return EXIT_FAILURE; From 6d62470032c24c49424416daf44113556a4a52e8 Mon Sep 17 00:00:00 2001 From: nick black Date: Sun, 16 Aug 2020 18:23:10 -0400 Subject: [PATCH 2/4] zoo demo: feed ncplane_puttext() atomic words #897 --- src/demo/zoo.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/demo/zoo.c b/src/demo/zoo.c index c7550f1eb..0560203ff 100644 --- a/src/demo/zoo.c +++ b/src/demo/zoo.c @@ -320,15 +320,11 @@ 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 size_t MAXTOWRITE = 8; bool collect_input = false; while(textpos < textlen || y > targrow){ pthread_mutex_lock(lock); ncplane_move_yx(rplane, y, x); size_t towrite = strcspn(text + textpos, " \t\n") + 1; - if(towrite > MAXTOWRITE){ - towrite = MAXTOWRITE; - } if(towrite){ char* duped = strndup(text + textpos, towrite); size_t bytes; From bcff36ac770dfdf4464f7f01949bdb9e42a6645a Mon Sep 17 00:00:00 2001 From: nick black Date: Sun, 16 Aug 2020 19:06:36 -0400 Subject: [PATCH 3/4] hoist out init_lang(), call from ncdirect #888 --- src/lib/direct.cpp | 3 +-- src/lib/internal.h | 1 + src/lib/notcurses.c | 25 +++++++++++++------------ 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/lib/direct.cpp b/src/lib/direct.cpp index b26e29c71..f3a55b249 100644 --- a/src/lib/direct.cpp +++ b/src/lib/direct.cpp @@ -445,11 +445,10 @@ ncdirect* ncdirect_init(const char* termtype, FILE* outfp){ ret->fgdefault = ret->bgdefault = true; ret->fgrgb = ret->bgrgb = 0; ncdirect_styles_set(ret, 0); + init_lang(false); const char* encoding = nl_langinfo(CODESET); if(encoding && strcmp(encoding, "UTF-8") == 0){ ret->utf8 = true; - }else if(encoding && strcmp(encoding, "ANSI_X3.4-1968") == 0){ - ret->utf8 = false; } return ret; } diff --git a/src/lib/internal.h b/src/lib/internal.h index 85b698aab..a798fef26 100644 --- a/src/lib/internal.h +++ b/src/lib/internal.h @@ -314,6 +314,7 @@ typedef struct notcurses { void sigwinch_handler(int signo); +void init_lang(int verbose); int terminfostr(char** gseq, const char* name); int interrogate_terminfo(tinfo* ti); diff --git a/src/lib/notcurses.c b/src/lib/notcurses.c index aa4690518..4a8b9e712 100644 --- a/src/lib/notcurses.c +++ b/src/lib/notcurses.c @@ -774,15 +774,14 @@ init_banner(const notcurses* nc){ // practice is for the client code to have called setlocale() themselves, and // set the NCOPTION_INHIBIT_SETLOCALE flag. if that flag is set, we take the // locale as we get it. -static void -init_lang(const notcurses_options* opts){ - if(!(opts->flags & NCOPTION_INHIBIT_SETLOCALE)){ - const char* locale = setlocale(LC_ALL, ""); - if(locale && (!strcmp(locale, "C") || !strcmp(locale, "POSIX"))){ - const char* lang = getenv("LANG"); - if(lang){ - // if LANG was explicitly set to C/POSIX, roll with it - if(strcmp(locale, "C") && strcmp(locale, "POSIX")){ +void init_lang(int verbose){ + const char* locale = setlocale(LC_ALL, ""); + if(locale && (!strcmp(locale, "C") || !strcmp(locale, "POSIX"))){ + const char* lang = getenv("LANG"); + if(lang){ + // if LANG was explicitly set to C/POSIX, roll with it + if(strcmp(locale, "C") && strcmp(locale, "POSIX")){ + if(verbose){ if(!locale){ // otherwise, generate diagnostic fprintf(stderr, "Couldn't set locale based off LANG %s\n", lang); }else{ @@ -790,9 +789,9 @@ init_lang(const notcurses_options* opts){ lang ? lang : "???"); } } - }else{ - fprintf(stderr, "No LANG environment variable was set, ick :/\n"); } + }else if(verbose){ + fprintf(stderr, "No LANG environment variable was set, ick :/\n"); } } } @@ -842,7 +841,9 @@ notcurses* notcurses_init(const notcurses_options* opts, FILE* outfp){ return ret; } ret->loglevel = opts->loglevel; - init_lang(opts); + if(!(opts->flags & NCOPTION_INHIBIT_SETLOCALE)){ + init_lang(true); + } const char* encoding = nl_langinfo(CODESET); if(encoding && strcmp(encoding, "UTF-8") == 0){ ret->utf8 = true; From a64433afe2b5e8604a8f85f8cc9f2cfa14c87867 Mon Sep 17 00:00:00 2001 From: nick black Date: Sun, 16 Aug 2020 19:14:34 -0400 Subject: [PATCH 4/4] init_lang(): take struct notcurses, not verbose flag #888 --- src/lib/direct.cpp | 2 +- src/lib/internal.h | 2 +- src/lib/notcurses.c | 20 +++++++++----------- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/lib/direct.cpp b/src/lib/direct.cpp index f3a55b249..830c3a699 100644 --- a/src/lib/direct.cpp +++ b/src/lib/direct.cpp @@ -445,7 +445,7 @@ ncdirect* ncdirect_init(const char* termtype, FILE* outfp){ ret->fgdefault = ret->bgdefault = true; ret->fgrgb = ret->bgrgb = 0; ncdirect_styles_set(ret, 0); - init_lang(false); + init_lang(nullptr); const char* encoding = nl_langinfo(CODESET); if(encoding && strcmp(encoding, "UTF-8") == 0){ ret->utf8 = true; diff --git a/src/lib/internal.h b/src/lib/internal.h index a798fef26..4861905bc 100644 --- a/src/lib/internal.h +++ b/src/lib/internal.h @@ -314,7 +314,7 @@ typedef struct notcurses { void sigwinch_handler(int signo); -void init_lang(int verbose); +void init_lang(struct notcurses* nc); // nc may be NULL, only used for logging int terminfostr(char** gseq, const char* name); int interrogate_terminfo(tinfo* ti); diff --git a/src/lib/notcurses.c b/src/lib/notcurses.c index 4a8b9e712..f8b06b462 100644 --- a/src/lib/notcurses.c +++ b/src/lib/notcurses.c @@ -774,24 +774,22 @@ init_banner(const notcurses* nc){ // practice is for the client code to have called setlocale() themselves, and // set the NCOPTION_INHIBIT_SETLOCALE flag. if that flag is set, we take the // locale as we get it. -void init_lang(int verbose){ +void init_lang(struct notcurses* nc){ const char* locale = setlocale(LC_ALL, ""); if(locale && (!strcmp(locale, "C") || !strcmp(locale, "POSIX"))){ const char* lang = getenv("LANG"); if(lang){ // if LANG was explicitly set to C/POSIX, roll with it if(strcmp(locale, "C") && strcmp(locale, "POSIX")){ - if(verbose){ - if(!locale){ // otherwise, generate diagnostic - fprintf(stderr, "Couldn't set locale based off LANG %s\n", lang); - }else{ - fprintf(stderr, "Set %s locale from LANG; client should call setlocale(2)!\n", - lang ? lang : "???"); - } + if(!locale){ // otherwise, generate diagnostic + logerror(nc, "Couldn't set locale based off LANG %s\n", lang); + }else{ + loginfo(nc, "Set %s locale from LANG; client should call setlocale(2)!\n", + lang ? lang : "???"); } } - }else if(verbose){ - fprintf(stderr, "No LANG environment variable was set, ick :/\n"); + }else{ + logwarn(nc, "No LANG environment variable was set, ick :/\n"); } } } @@ -842,7 +840,7 @@ notcurses* notcurses_init(const notcurses_options* opts, FILE* outfp){ } ret->loglevel = opts->loglevel; if(!(opts->flags & NCOPTION_INHIBIT_SETLOCALE)){ - init_lang(true); + init_lang(ret); } const char* encoding = nl_langinfo(CODESET); if(encoding && strcmp(encoding, "UTF-8") == 0){