diff --git a/builtin_set_color.cpp b/builtin_set_color.cpp index 5d4c21243..ef9ab23d3 100644 --- a/builtin_set_color.cpp +++ b/builtin_set_color.cpp @@ -9,6 +9,12 @@ Functions used for implementing the set_color builtin. #include "color.h" #include "output.h" +#if HAVE_NCURSES_H +#include +#else +#include +#endif + #if HAVE_TERM_H #include #elif HAVE_NCURSES_TERM_H @@ -157,6 +163,23 @@ static int builtin_set_color(parser_t &parser, wchar_t **argv) append_format(stderr_buffer, _("%s: Unknown color '%s'\n"), argv[0], bgcolor); return STATUS_BUILTIN_ERROR; } + + /* Make sure that the term exists */ + if (cur_term == NULL && setupterm(0, STDOUT_FILENO, 0) == ERR) + { + append_format(stderr_buffer, _("%s: Could not set up terminal\n"), argv[0]); + return STATUS_BUILTIN_ERROR; + } + + /* + Test if we have at least basic support for setting fonts, colors + and related bits - otherwise just give up... + */ + if (! exit_attribute_mode) + { + return STATUS_BUILTIN_ERROR; + } + /* Save old output function so we can restore it */ int (* const saved_writer_func)(char) = output_get_writer(); diff --git a/input.cpp b/input.cpp index 1c60b93c2..4432633ea 100644 --- a/input.cpp +++ b/input.cpp @@ -238,7 +238,7 @@ static std::vector mappings; /** Set to one when the input subsytem has been initialized. */ -static int is_init = 0; +static bool is_init = false; /** Initialize terminfo. @@ -344,7 +344,7 @@ int input_init() if (is_init) return 1; - is_init = 1; + is_init = true; input_common_init(&interrupt_handler); @@ -381,7 +381,7 @@ void input_destroy() return; - is_init=0; + is_init = false; input_common_destroy();