From 3928b39988155c5e1a20685335d47fb9b681eb00 Mon Sep 17 00:00:00 2001 From: "Diogo Franco (Kovensky)" Date: Fri, 26 Jul 2013 11:29:34 -0300 Subject: 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. --- osdep/getch2.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) 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"); -- cgit v1.2.3