diff options
author | 2013-02-15 14:00:25 -0800 | |
---|---|---|
committer | 2013-02-15 14:00:25 -0800 | |
commit | a355cf24f12f8a43d8344af424e68e87d352e155 (patch) | |
tree | 9aa161c8b0e06baa698cfb8de657a11313a7cc03 | |
parent | bc7ad955a3b48744249f4f28932bad44fcfa602c (diff) |
Teach set_color to call setupterm so it doesn't crash when run non-interactively
-rw-r--r-- | builtin_set_color.cpp | 23 | ||||
-rw-r--r-- | input.cpp | 6 |
2 files changed, 26 insertions, 3 deletions
diff --git a/builtin_set_color.cpp b/builtin_set_color.cpp index 5d4c2124..ef9ab23d 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 <ncurses.h> +#else +#include <curses.h> +#endif + #if HAVE_TERM_H #include <term.h> #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(); @@ -238,7 +238,7 @@ static std::vector<terminfo_mapping_t> 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(); |