[Gambas-user] A Way to determine if Terminal supports color

Brian G brian at westwoodsvcs.com
Fri Jul 30 20:46:58 CEST 2021


Maybe Tobias can help? 

Is there a way to use the color.available in gb.ncurses without having the screen automatically initialized. 

Like using setupterm() and then call has_color() 
To get the color available info from the terminal cap, so it never initializes the actual screen? 

Or is there another way to get this info? 

Maybe Tobias can help? 

I found this sample for c code: 
#include <stdlib.h>
#include <curses.h>

int main(void) {
  char *term = getenv("TERM");

  int erret = 0;
  if (setupterm(NULL, 1, &erret) == ERR) {
    char *errmsg = "unknown error";
    switch (erret) {
    case 1: errmsg = "terminal is hardcopy, cannot be used for curses applications"; break;
    case 0: errmsg = "terminal could not be found, or not enough information for curses applications"; break;
    case -1: errmsg = "terminfo entry could not be found"; break;
    }
    printf("Color support for terminal \"%s\" unknown (error %d: %s).\n", term, erret, errmsg);
    exit(1);
  }

  bool colors = has_colors();

  printf("Terminal \"%s\" %s colors.\n", term, colors ? "has" : "does not have");

  return 0;
} 



"Failure is the key to success; 
each mistake teaches us something" .. Morihei Ueshiba 
Brian G 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20210730/4537260a/attachment.htm>


More information about the User mailing list