aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/input.cpp
diff options
context:
space:
mode:
authorGravatar Kurtis Rader <krader@skepticism.us>2016-06-01 20:03:50 -0700
committerGravatar Kurtis Rader <krader@skepticism.us>2016-06-03 17:16:41 -0700
commit53e865b65434fa9ec12afc11a076aec244cd3c43 (patch)
tree3cbfe0ed403a5ca30b1570fe28411c6d91ae6910 /src/input.cpp
parent57f289850c24a44a2590cb30762853f2a61f4efd (diff)
put curses/terminfo vars into the environment
We need to actually export the curses/terminfo env vars in order for `setupterm()` to be able to use them. While fixing this I reworked the fallback logic implemented by @zanchey in response to issue #1060 in order to simplify the logic and clarify the error messages. This does not allow someone to change the curses/terminfo env vars after the first prompt is displayed (you can but it won't affect the current fish process). It only makes it possible to set `TERM`, `TERMINFO`, and `TERMINFO_DIRS` in *config.fish* or similar config file and have them be honored by fish.
Diffstat (limited to 'src/input.cpp')
-rw-r--r--src/input.cpp33
1 files changed, 11 insertions, 22 deletions
diff --git a/src/input.cpp b/src/input.cpp
index 5b599e85..b9132b2c 100644
--- a/src/input.cpp
+++ b/src/input.cpp
@@ -1,7 +1,6 @@
// Functions for reading a character of input from stdin.
#include "config.h"
-#include <assert.h>
#include <errno.h>
#include <unistd.h>
#include <wchar.h>
@@ -339,35 +338,25 @@ void update_fish_color_support(void) {
int input_init() {
if (is_init) return 1;
-
is_init = true;
-
input_common_init(&interrupt_handler);
- const env_var_t term = env_get_string(L"TERM");
- int errret;
- if (setupterm(const_cast<char *>(wcs2string(term).c_str()), STDOUT_FILENO, &errret) == ERR) {
- debug(0, _(L"Could not set up terminal"));
- if (errret == 0) {
- 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(const_cast<char *>(default_term.c_str()), STDOUT_FILENO, &errret) ==
- ERR) {
- debug(0, _(L"Could not set up terminal"));
- exit_without_destructors(1);
- }
- } else {
+ int err_ret;
+ if (setupterm(NULL, STDOUT_FILENO, &err_ret) == ERR) {
+ env_var_t term = env_get_string(L"TERM");
+ debug(0, _(L"Your TERM value of '%ls' is not valid"), term.c_str());
+ debug(0, _(L"Check that your terminal type is supported on this system"));
+ env_set(L"TERM", DEFAULT_TERM, ENV_GLOBAL | ENV_EXPORT);
+ if (setupterm(NULL, STDOUT_FILENO, &err_ret) == ERR) {
+ debug(0, _(L"Unable to setup terminal using your TERM or the '%ls' fallback"),
+ DEFAULT_TERM);
exit_without_destructors(1);
+ } else {
+ debug(0, _(L"Using fallback terminal type '%ls' instead"), DEFAULT_TERM);
}
}
- assert(!term.missing());
- output_set_term(term);
input_terminfo_init();
-
update_fish_color_support();
// If we have no keybindings, add a few simple defaults.