fall back to ANSI terminal type if setupterm fails

Closes: https://github.com/fish-shell/fish-shell/issues/1060

'ansi' should always be present (tested on Solaris, Linux, FreeBSD,
Darwin).

Also overrides TERM so that other programs behave consistently e.g.
fish_pager.

The error message makes no specific mention of terminfo or termcap as
these vary across operating systems.

(r+ @ridiculousfish with thanks)
This commit is contained in:
David Adam
2013-11-26 11:39:54 +08:00
parent 8d1667e9e8
commit 2c39d5b6c0

View File

@@ -60,6 +60,8 @@
#include "intern.h"
#include <vector>
#define DEFAULT_TERM L"ansi"
/**
Struct representing a keybinding. Returned by input_get_mappings.
*/
@@ -355,9 +357,20 @@ int input_init()
{
debug(0, _(L"Check that your terminal type, '%ls', is supported on this system"),
term.c_str());
}
debug(0, _(L"Attempting to use '%ls' instead"), DEFAULT_TERM);
env_set(L"TERM", DEFAULT_TERM, ENV_GLOBAL | ENV_EXPORT);
const std::string default_term = wcs2string(DEFAULT_TERM);
if (setupterm(default_term.c_str(), STDOUT_FILENO, &errret) == ERR)
{
debug(0, _(L"Could not set up terminal"));
exit_without_destructors(1);
}
}
else
{
exit_without_destructors(1);
}
}
assert(! term.missing());
output_set_term(term);