mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-13 13:39:02 +00:00
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.
This commit is contained in:
parent
e0a627f99d
commit
eb834f47ef
3 changed files with 21 additions and 64 deletions
|
@ -6,7 +6,6 @@
|
|||
|
||||
#include "config.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <wchar.h>
|
||||
|
@ -457,43 +456,27 @@ void update_fish_color_support(void)
|
|||
output_set_color_support(support);
|
||||
}
|
||||
|
||||
int input_init()
|
||||
{
|
||||
if (is_init)
|
||||
return 1;
|
||||
|
||||
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 */
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include "fallback.h"
|
||||
#include "wutil.h" // IWYU pragma: keep - needed for wgettext
|
||||
#include "common.h"
|
||||
#include "env.h"
|
||||
#include "output.h"
|
||||
|
||||
static int writeb_internal(char c);
|
||||
|
@ -37,14 +38,8 @@ static int writeb_internal(char c);
|
|||
/**
|
||||
The function used for output
|
||||
*/
|
||||
|
||||
static int (*out)(char c) = &writeb_internal;
|
||||
|
||||
/**
|
||||
Name of terminal
|
||||
*/
|
||||
static wcstring current_term;
|
||||
|
||||
/* Whether term256 and term24bit are supported */
|
||||
static color_support_t color_support = 0;
|
||||
|
||||
|
@ -554,29 +549,13 @@ rgb_color_t parse_color(const wcstring &val, bool is_background)
|
|||
return result;
|
||||
}
|
||||
|
||||
void output_set_term(const wcstring &term)
|
||||
{
|
||||
current_term.assign(term);
|
||||
}
|
||||
|
||||
const wchar_t *output_get_term()
|
||||
{
|
||||
return current_term.empty() ? L"<unknown>" : current_term.c_str();
|
||||
}
|
||||
|
||||
void writembs_check(char *mbs, const char *mbs_name, const char *file, long line)
|
||||
{
|
||||
if (mbs != NULL)
|
||||
{
|
||||
void writembs_check(char *mbs, const char *mbs_name, const char *file, long line) {
|
||||
if (mbs != NULL) {
|
||||
tputs(mbs, 1, &writeb);
|
||||
}
|
||||
else
|
||||
{
|
||||
debug( 0, _(L"Tried to use terminfo string %s on line %ld of %s, which is undefined in terminal of type \"%ls\". Please report this error to %s"),
|
||||
mbs_name,
|
||||
line,
|
||||
file,
|
||||
output_get_term(),
|
||||
PACKAGE_BUGREPORT);
|
||||
} else {
|
||||
env_var_t term = env_get_string(L"TERM");
|
||||
debug(0, _(L"Tried to use terminfo string %s on line %ld of %s, which is undefined in "
|
||||
L"terminal of type \"%ls\". Please report this error to %s"),
|
||||
mbs_name, line, file, term.c_str(), PACKAGE_BUGREPORT);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -105,11 +105,6 @@ void output_set_writer(int (*writer)(char));
|
|||
*/
|
||||
int (*output_get_writer())(char) ;
|
||||
|
||||
/** Set the terminal name */
|
||||
void output_set_term(const wcstring &term);
|
||||
|
||||
/** Return the terminal name */
|
||||
const wchar_t *output_get_term();
|
||||
|
||||
/** Sets what colors are supported */
|
||||
enum
|
||||
|
|
Loading…
Reference in a new issue