mirror of https://github.com/mpv-player/mpv
getch2: Handle setupterm errors
setupterm abort()s if it can't initialize the terminal and the last parameter is NULL; handle setupterm errors and retry with "ansi" if the TERM env var was unset.
This commit is contained in:
parent
ca039d42bb
commit
3928b39988
|
@ -237,7 +237,24 @@ int load_termcap(char *termtype){
|
||||||
|
|
||||||
#ifdef HAVE_TERMINFO
|
#ifdef HAVE_TERMINFO
|
||||||
use_env(TRUE);
|
use_env(TRUE);
|
||||||
setupterm(termtype, 1, NULL);
|
int ret;
|
||||||
|
if (setupterm(termtype, 1, &ret) != OK) {
|
||||||
|
/* try again, with with "ansi" terminal if it was unset before */
|
||||||
|
if (!termtype)
|
||||||
|
termtype = getenv("TERM");
|
||||||
|
if (!termtype || *termtype == '\0')
|
||||||
|
termtype = "ansi";
|
||||||
|
|
||||||
|
if (setupterm(termtype, 1, &ret) != OK) {
|
||||||
|
if (ret < 0) {
|
||||||
|
printf("Could not access the 'terminfo' data base.\n");
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
printf("Couldn't use terminal `%s' for input.\n", termtype);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
static char term_buffer[2048];
|
static char term_buffer[2048];
|
||||||
if (!termtype) termtype = getenv("TERM");
|
if (!termtype) termtype = getenv("TERM");
|
||||||
|
|
Loading…
Reference in New Issue