[Gambas-user] A Way to determine if Terminal supports color
Tobias Boege
tobs at taboege.de
Sat Jul 31 13:41:20 CEST 2021
On Fri, 30 Jul 2021, Brian G wrote:
> Maybe Tobias can help?
>
> Is there a way to use the color.available in gb.ncurses without having the screen automatically initialized.
>
gb.ncurses always calls initscr() as soon as the component is loaded to
establish a clean environment for the other classes "once and for all".
So there is no way to do that with gb.ncurses. It was conceived as a
user interface component (although not a lot came of it), not to inspect
low-level terminal capabilities. (I'm not saying that this wouldn't be
useful to have, maybe in gb.term?)
> 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?
>
Honestly, the quickest way is probably via Extern:
Extern setupterm(term As String, fd As Integer, err As Pointer) As Integer In "libncursesw"
Extern has_colors() As Integer In "libncursesw"
But note that when I try, inspired by your snippet,
#include <stdio.h>
#include <stdlib.h>
#include <ncurses.h>
#include <term.h>
int main(void) {
int err = 0;
printf("%d ", setupterm(NULL, 1, &err));
printf("%d ", err);
printf("%d\n", has_colors());
exit(0);
}
I get the output "0 1 0", meaning my terminal is detected as hardcopy,
not capable of curses or color.
But when I properly initialize ncurses using initscr(),
#include <stdio.h>
#include <stdlib.h>
#include <ncurses.h>
int main(void) {
initscr();
int c = has_colors();
endwin();
printf("%d\n", c);
exit(0);
}
I get the expected output "1". Are you sure your method is supposed to work?
Best,
Tobias
--
"There's an old saying: Don't change anything... ever!" -- Mr. Monk
More information about the User
mailing list