diff options
author | Kurtis Rader <krader@skepticism.us> | 2016-06-01 20:03:50 -0700 |
---|---|---|
committer | Kurtis Rader <krader@skepticism.us> | 2016-06-03 17:16:41 -0700 |
commit | 53e865b65434fa9ec12afc11a076aec244cd3c43 (patch) | |
tree | 3cbfe0ed403a5ca30b1570fe28411c6d91ae6910 /src/env.cpp | |
parent | 57f289850c24a44a2590cb30762853f2a61f4efd (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/env.cpp')
-rw-r--r-- | src/env.cpp | 43 |
1 files changed, 39 insertions, 4 deletions
diff --git a/src/env.cpp b/src/env.cpp index e09064ad..71d85800 100644 --- a/src/env.cpp +++ b/src/env.cpp @@ -124,10 +124,15 @@ static null_terminated_array_t<char> export_array; static bool has_changed_exported = true; static void mark_changed_exported() { has_changed_exported = true; } -/// List of all locale variable names. -static const wchar_t *const locale_variable[] = {L"LANG", L"LC_ALL", L"LC_COLLATE", - L"LC_CTYPE", L"LC_MESSAGES", L"LC_MONETARY", - L"LC_NUMERIC", L"LC_TIME", NULL}; +/// List of all locale environment variable names. +static const wchar_t *const locale_variable[] = { + L"LANG", L"LANGUAGE", L"LC_ALL", L"LC_ADDRESS", L"LC_COLLATE", + L"LC_CTYPE", L"LC_IDENTIFICATION", L"LC_MEASUREMENT", L"LC_MESSAGES", L"LC_MONETARY", + L"LC_NAME", L"LC_NUMERIC", L"LC_PAPER", L"LC_TELEPHONE", L"LC_TIME", + NULL}; + +/// List of all curses environment variable names. +static const wchar_t *const curses_variable[] = {L"TERM", L"TERMINFO", L"TERMINFO_DIRS", NULL}; const var_entry_t *env_node_t::find_entry(const wcstring &key) { const var_entry_t *result = NULL; @@ -200,10 +205,40 @@ static void handle_locale() { } } +/// Check if the specified variable is a locale variable. +static bool var_is_curses(const wcstring &key) { + for (size_t i = 0; curses_variable[i]; i++) { + if (key == curses_variable[i]) { + return true; + } + } + return false; +} + +/// Push all curses/terminfo env vars into the global environment where they can be found by those +/// libraries. +static void handle_curses() { + for (size_t i = 0; curses_variable[i]; i++) { + const wchar_t *key = curses_variable[i]; + const env_var_t var = env_get_string(key); + if (!var.empty()) { + const std::string &name = wcs2string(key); + const std::string &value = wcs2string(var); + setenv(name.c_str(), value.c_str(), 1); + } + } + // TODO: Modify input_init() to allow calling it when the terminfo env vars are dynamically + // changed. At the present time it can be called just once. Also, we should really only do this + // if the TERM var is set. + // input_init(); +} + /// React to modifying the given variable. static void react_to_variable_change(const wcstring &key) { if (var_is_locale(key)) { handle_locale(); + } else if (var_is_curses(key)) { + handle_curses(); } else if (key == L"fish_term256" || key == L"fish_term24bit") { update_fish_color_support(); reader_react_to_color_change(); |