mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-03-26 05:45:22 +08:00
Teach set_color to call setupterm so it doesn't crash when run non-interactively
This commit is contained in:
parent
bc7ad955a3
commit
a355cf24f1
@ -9,6 +9,12 @@ Functions used for implementing the set_color builtin.
|
|||||||
#include "color.h"
|
#include "color.h"
|
||||||
#include "output.h"
|
#include "output.h"
|
||||||
|
|
||||||
|
#if HAVE_NCURSES_H
|
||||||
|
#include <ncurses.h>
|
||||||
|
#else
|
||||||
|
#include <curses.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#if HAVE_TERM_H
|
#if HAVE_TERM_H
|
||||||
#include <term.h>
|
#include <term.h>
|
||||||
#elif HAVE_NCURSES_TERM_H
|
#elif HAVE_NCURSES_TERM_H
|
||||||
@ -158,6 +164,23 @@ static int builtin_set_color(parser_t &parser, wchar_t **argv)
|
|||||||
return STATUS_BUILTIN_ERROR;
|
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 */
|
/* Save old output function so we can restore it */
|
||||||
int (* const saved_writer_func)(char) = output_get_writer();
|
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.
|
Set to one when the input subsytem has been initialized.
|
||||||
*/
|
*/
|
||||||
static int is_init = 0;
|
static bool is_init = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Initialize terminfo.
|
Initialize terminfo.
|
||||||
@ -344,7 +344,7 @@ int input_init()
|
|||||||
if (is_init)
|
if (is_init)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
is_init = 1;
|
is_init = true;
|
||||||
|
|
||||||
input_common_init(&interrupt_handler);
|
input_common_init(&interrupt_handler);
|
||||||
|
|
||||||
@ -381,7 +381,7 @@ void input_destroy()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
||||||
is_init=0;
|
is_init = false;
|
||||||
|
|
||||||
input_common_destroy();
|
input_common_destroy();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user