dankamongmen / notcurses

blingful character graphics/TUI library. definitely not curses.
https://nick-black.com/dankwiki/index.php/Notcurses
Other
3.4k stars 113 forks source link

ncmetric uses bullshit detect_utf8() #2780

Closed dankamongmen closed 1 month ago

dankamongmen commented 1 month ago

In lib/metric.c, we've got this:

// sure hope we've called setlocale() by the time we hit this!                                                                      
static void                                                                                                                         
detect_utf8(void){                                                                                                                  
  const char* encoding = nl_langinfo(CODESET);                                                                                      
  if(encoding){                                                                                                                     
    if(strcmp(encoding, "UTF-8") == 0){                                                                                             
      SUBPREFIXES = UTF8_SUBPREFIX;                                                                                                 
    }                                                                                                                               
  }                                                                                                                                 
}

called using pthread_once() from ncnmetric(). this is obviously a holdover from ncmetric()'s outcurses origins. move over to standard notcurses detection. found while looking at #2779.

dankamongmen commented 1 month ago

i think fixing this will imply an API change, since we'll need the notcurses object. =\

dankamongmen commented 1 month ago

maybe we introduce a new function, and deprecate this one?

dankamongmen commented 1 month ago

I'm halfway inclined to stash a library-wide singleton and allow functions like this to grab it, since all we need determine is UTF-8 presence, and there's no writing (i.e. we would take a const struct notcurses*)....and then just document this unorthodox choice in the man page's BUGS. Then there's no need for an API change. If we do this, keep the current naming.