diff options
author | Diogo Franco (Kovensky) <diogomfranco@gmail.com> | 2013-07-26 11:29:34 -0300 |
---|---|---|
committer | Diogo Franco (Kovensky) <diogomfranco@gmail.com> | 2013-07-26 11:29:34 -0300 |
commit | 3928b39988155c5e1a20685335d47fb9b681eb00 (patch) | |
tree | 4a11eff89bfa1ddc62cbffc6adaf8ed7325073f7 /osdep | |
parent | ca039d42bb947f3252cd3dc08e5d6751f39eba96 (diff) | |
download | mpv-3928b39988155c5e1a20685335d47fb9b681eb00.tar.bz2 mpv-3928b39988155c5e1a20685335d47fb9b681eb00.tar.xz |
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.
Diffstat (limited to 'osdep')
-rw-r--r-- | osdep/getch2.c | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/osdep/getch2.c b/osdep/getch2.c index e8e9fe293f..f9528f33ea 100644 --- a/osdep/getch2.c +++ b/osdep/getch2.c @@ -237,7 +237,24 @@ int load_termcap(char *termtype){ #ifdef HAVE_TERMINFO 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 static char term_buffer[2048]; if (!termtype) termtype = getenv("TERM"); |