diff options
author | ridiculousfish <corydoras@ridiculousfish.com> | 2013-02-15 14:00:25 -0800 |
---|---|---|
committer | ridiculousfish <corydoras@ridiculousfish.com> | 2013-02-15 14:00:25 -0800 |
commit | a355cf24f12f8a43d8344af424e68e87d352e155 (patch) | |
tree | 9aa161c8b0e06baa698cfb8de657a11313a7cc03 /builtin_set_color.cpp | |
parent | bc7ad955a3b48744249f4f28932bad44fcfa602c (diff) |
Teach set_color to call setupterm so it doesn't crash when run non-interactively
Diffstat (limited to 'builtin_set_color.cpp')
-rw-r--r-- | builtin_set_color.cpp | 23 |
1 files changed, 23 insertions, 0 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(); |