How do I fix opening terminal error with c++ ncurses

2k Views Asked by At

I'm using CLion 2018.2.6 on MacOS. I'm trying to use ncurses but getting the error "Error opening terminal: unknown." I'm not sure how to fix this. Any help appreciated. Code below.

#include <iostream> 
#include <ncurses.h>
using namespace std;
int main(){
     initscr();
     clear();
     printw("Seems legit!");
     refresh();
     getch();
     endwin();
}
2

There are 2 best solutions below

0
On

Check the path of terminfo folder in the application running system and the same path in your application like this,

Ex:- setenv("TERMINFO","/usr/share/terminfo", 1);

It working.

0
On

The initscr manual page mentions this:

Unset TERM Variable

If the TERM variable is missing or empty, initscr uses the value "unknown", which normally corresponds to a terminal entry with the generic (gn) capability. Generic entries are detected by setupterm (see curs_terminfo(3x)) and cannot be used for full-screen operation. Other implementations may handle a missing/empty TERM variable differently.

Also, depending on how your system is configured, ncurses may not even find the terminal database, e.g., if it is installed in a different location than the compiled-in default location. Like TERM, that can be fixed using the TERMINFO or TERMINFO_DIRS environments. As an additional complication, MacOS by default uses case-insensitive filesystems, and ncurses uses a different directory organization for that. The term(5) manual page mentions that:

A small number of terminal descriptions use uppercase characters in their names. If the underlying filesystem ignores the difference between uppercase and lowercase, ncurses represents the "first character" of the terminal name used as the intermediate level of a directory tree in (two-character) hexadecimal form.