mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-27 12:15:08 +00:00
rename get_is_interactive and remove stupid test
I'm doing this as part of fixing issue #2980. The code for managing tty modes and job control is a horrible mess. This is a very tiny step towards improving the situation.
This commit is contained in:
parent
149e601743
commit
ff1d651415
9 changed files with 22 additions and 24 deletions
|
@ -181,7 +181,7 @@ void builtin_print_help(parser_t &parser, io_streams_t &streams, const wchar_t *
|
||||||
|
|
||||||
screen_height = common_get_height();
|
screen_height = common_get_height();
|
||||||
lines = count_char(str, L'\n');
|
lines = count_char(str, L'\n');
|
||||||
if (!get_is_interactive() || (lines > 2 * screen_height / 3)) {
|
if (!shell_is_interactive() || (lines > 2 * screen_height / 3)) {
|
||||||
wchar_t *pos;
|
wchar_t *pos;
|
||||||
int cut = 0;
|
int cut = 0;
|
||||||
int i;
|
int i;
|
||||||
|
@ -2368,7 +2368,7 @@ static int builtin_cd(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||||
argv[0], dir_in.c_str());
|
argv[0], dir_in.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!get_is_interactive()) {
|
if (!shell_is_interactive()) {
|
||||||
streams.err.append(parser.current_line());
|
streams.err.append(parser.current_line());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2385,7 +2385,7 @@ static int builtin_cd(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||||
streams.err.append_format(_(L"%ls: '%ls' is not a directory\n"), argv[0], dir.c_str());
|
streams.err.append_format(_(L"%ls: '%ls' is not a directory\n"), argv[0], dir.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!get_is_interactive()) {
|
if (!shell_is_interactive()) {
|
||||||
streams.err.append(parser.current_line());
|
streams.err.append(parser.current_line());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1183,7 +1183,7 @@ parse_execution_result_t parse_execution_context_t::run_1_job(const parse_node_t
|
||||||
|
|
||||||
// Get terminal modes.
|
// Get terminal modes.
|
||||||
struct termios tmodes = {};
|
struct termios tmodes = {};
|
||||||
if (get_is_interactive()) {
|
if (shell_is_interactive()) {
|
||||||
if (tcgetattr(STDIN_FILENO, &tmodes)) {
|
if (tcgetattr(STDIN_FILENO, &tmodes)) {
|
||||||
// Need real error handling here.
|
// Need real error handling here.
|
||||||
wperror(L"tcgetattr");
|
wperror(L"tcgetattr");
|
||||||
|
@ -1254,14 +1254,14 @@ parse_execution_result_t parse_execution_context_t::run_1_job(const parse_node_t
|
||||||
j->tmodes = tmodes;
|
j->tmodes = tmodes;
|
||||||
job_set_flag(j, JOB_CONTROL,
|
job_set_flag(j, JOB_CONTROL,
|
||||||
(job_control_mode == JOB_CONTROL_ALL) ||
|
(job_control_mode == JOB_CONTROL_ALL) ||
|
||||||
((job_control_mode == JOB_CONTROL_INTERACTIVE) && (get_is_interactive())));
|
((job_control_mode == JOB_CONTROL_INTERACTIVE) && (shell_is_interactive())));
|
||||||
|
|
||||||
job_set_flag(j, JOB_FOREGROUND, !tree.job_should_be_backgrounded(job_node));
|
job_set_flag(j, JOB_FOREGROUND, !tree.job_should_be_backgrounded(job_node));
|
||||||
|
|
||||||
job_set_flag(j, JOB_TERMINAL, job_get_flag(j, JOB_CONTROL) && !is_subshell && !is_event);
|
job_set_flag(j, JOB_TERMINAL, job_get_flag(j, JOB_CONTROL) && !is_subshell && !is_event);
|
||||||
|
|
||||||
job_set_flag(j, JOB_SKIP_NOTIFICATION,
|
job_set_flag(j, JOB_SKIP_NOTIFICATION,
|
||||||
is_subshell || is_block || is_event || !get_is_interactive());
|
is_subshell || is_block || is_event || !shell_is_interactive());
|
||||||
|
|
||||||
// Tell the current block what its job is. This has to happen before we populate it (#1394).
|
// Tell the current block what its job is. This has to happen before we populate it (#1394).
|
||||||
parser->current_block()->job = j;
|
parser->current_block()->job = j;
|
||||||
|
|
|
@ -139,7 +139,7 @@ wcstring parse_error_t::describe_with_prefix(const wcstring &src, const wcstring
|
||||||
}
|
}
|
||||||
|
|
||||||
wcstring parse_error_t::describe(const wcstring &src) const {
|
wcstring parse_error_t::describe(const wcstring &src) const {
|
||||||
return this->describe_with_prefix(src, wcstring(), get_is_interactive(), false);
|
return this->describe_with_prefix(src, wcstring(), shell_is_interactive(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void parse_error_offset_source_start(parse_error_list_t *errors, size_t amt) {
|
void parse_error_offset_source_start(parse_error_list_t *errors, size_t amt) {
|
||||||
|
|
|
@ -522,7 +522,7 @@ wcstring parser_t::current_line() {
|
||||||
wcstring prefix;
|
wcstring prefix;
|
||||||
|
|
||||||
// If we are not going to print a stack trace, at least print the line number and filename.
|
// If we are not going to print a stack trace, at least print the line number and filename.
|
||||||
if (!get_is_interactive() || is_function()) {
|
if (!shell_is_interactive() || is_function()) {
|
||||||
if (file) {
|
if (file) {
|
||||||
append_format(prefix, _(L"%ls (line %d): "), user_presentable_path(file).c_str(),
|
append_format(prefix, _(L"%ls (line %d): "), user_presentable_path(file).c_str(),
|
||||||
lineno);
|
lineno);
|
||||||
|
@ -533,7 +533,7 @@ wcstring parser_t::current_line() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_interactive = get_is_interactive();
|
bool is_interactive = shell_is_interactive();
|
||||||
bool skip_caret = is_interactive && !is_function();
|
bool skip_caret = is_interactive && !is_function();
|
||||||
|
|
||||||
// Use an error with empty text.
|
// Use an error with empty text.
|
||||||
|
@ -756,7 +756,7 @@ void parser_t::get_backtrace(const wcstring &src, const parse_error_list_t &erro
|
||||||
if (!errors.empty()) {
|
if (!errors.empty()) {
|
||||||
const parse_error_t &err = errors.at(0);
|
const parse_error_t &err = errors.at(0);
|
||||||
|
|
||||||
const bool is_interactive = get_is_interactive();
|
const bool is_interactive = shell_is_interactive();
|
||||||
|
|
||||||
// Determine if we want to try to print a caret to point at the source error. The
|
// Determine if we want to try to print a caret to point at the source error. The
|
||||||
// err.source_start <= src.size() check is due to the nasty way that slices work, which is
|
// err.source_start <= src.size() check is due to the nasty way that slices work, which is
|
||||||
|
|
|
@ -101,10 +101,11 @@ static int is_interactive = -1;
|
||||||
|
|
||||||
static bool proc_had_barrier = false;
|
static bool proc_had_barrier = false;
|
||||||
|
|
||||||
int get_is_interactive(void) {
|
bool shell_is_interactive(void) {
|
||||||
ASSERT_IS_MAIN_THREAD();
|
ASSERT_IS_MAIN_THREAD();
|
||||||
// is_interactive is initialized to -1; ensure someone has popped/pushed it before then.
|
// is_interactive is statically initialized to -1. Ensure it has been dynamically set
|
||||||
assert(is_interactive >= 0);
|
// before we're called.
|
||||||
|
assert(is_interactive != -1);
|
||||||
return is_interactive > 0;
|
return is_interactive > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -232,7 +232,7 @@ extern int is_subshell;
|
||||||
extern int is_block;
|
extern int is_block;
|
||||||
|
|
||||||
/// Whether we are reading from the keyboard right now.
|
/// Whether we are reading from the keyboard right now.
|
||||||
int get_is_interactive(void);
|
bool shell_is_interactive(void);
|
||||||
|
|
||||||
/// Whether this shell is attached to the keyboard at all.
|
/// Whether this shell is attached to the keyboard at all.
|
||||||
extern int is_interactive_session;
|
extern int is_interactive_session;
|
||||||
|
|
|
@ -1686,7 +1686,7 @@ static void reader_interactive_destroy() {
|
||||||
|
|
||||||
void reader_sanity_check() {
|
void reader_sanity_check() {
|
||||||
// Note: 'data' is non-null if we are interactive, except in the testing environment.
|
// Note: 'data' is non-null if we are interactive, except in the testing environment.
|
||||||
if (get_is_interactive() && data != NULL) {
|
if (shell_is_interactive() && data != NULL) {
|
||||||
if (data->command_line.position > data->command_line.size()) sanity_lose();
|
if (data->command_line.position > data->command_line.size()) sanity_lose();
|
||||||
if (data->colors.size() != data->command_line.size()) sanity_lose();
|
if (data->colors.size() != data->command_line.size()) sanity_lose();
|
||||||
if (data->indents.size() != data->command_line.size()) sanity_lose();
|
if (data->indents.size() != data->command_line.size()) sanity_lose();
|
||||||
|
@ -2217,7 +2217,7 @@ static void reader_super_highlight_me_plenty(int match_highlight_pos_adjust, boo
|
||||||
}
|
}
|
||||||
|
|
||||||
bool shell_is_exiting() {
|
bool shell_is_exiting() {
|
||||||
if (get_is_interactive())
|
if (shell_is_interactive())
|
||||||
return job_list_is_empty() && data != NULL && data->end_loop;
|
return job_list_is_empty() && data != NULL && data->end_loop;
|
||||||
else
|
else
|
||||||
return end_loop;
|
return end_loop;
|
||||||
|
@ -3412,7 +3412,7 @@ int reader_read(int fd, const io_chain_t &io) {
|
||||||
int inter = ((fd == STDIN_FILENO) && isatty(STDIN_FILENO));
|
int inter = ((fd == STDIN_FILENO) && isatty(STDIN_FILENO));
|
||||||
proc_push_interactive(inter);
|
proc_push_interactive(inter);
|
||||||
|
|
||||||
res = get_is_interactive() ? read_i() : read_ni(fd, io);
|
res = shell_is_interactive() ? read_i() : read_ni(fd, io);
|
||||||
|
|
||||||
// If the exit command was called in a script, only exit the script, not the program.
|
// If the exit command was called in a script, only exit the script, not the program.
|
||||||
if (data) data->end_loop = 0;
|
if (data) data->end_loop = 0;
|
||||||
|
|
|
@ -18,8 +18,7 @@ void sanity_lose() {
|
||||||
}
|
}
|
||||||
|
|
||||||
int sanity_check() {
|
int sanity_check() {
|
||||||
if (!insane)
|
if (!insane && shell_is_interactive()) history_sanity_check();
|
||||||
if (get_is_interactive()) history_sanity_check();
|
|
||||||
if (!insane) reader_sanity_check();
|
if (!insane) reader_sanity_check();
|
||||||
if (!insane) kill_sanity_check();
|
if (!insane) kill_sanity_check();
|
||||||
if (!insane) proc_sanity_check();
|
if (!insane) proc_sanity_check();
|
||||||
|
|
|
@ -249,8 +249,6 @@ void signal_reset_handlers() {
|
||||||
void signal_set_handlers() {
|
void signal_set_handlers() {
|
||||||
struct sigaction act;
|
struct sigaction act;
|
||||||
|
|
||||||
if (get_is_interactive() == -1) return;
|
|
||||||
|
|
||||||
sigemptyset(&act.sa_mask);
|
sigemptyset(&act.sa_mask);
|
||||||
act.sa_flags = SA_SIGINFO;
|
act.sa_flags = SA_SIGINFO;
|
||||||
act.sa_sigaction = &default_handler;
|
act.sa_sigaction = &default_handler;
|
||||||
|
@ -267,9 +265,9 @@ void signal_set_handlers() {
|
||||||
// Ignore sigpipe, which we may get from the universal variable notifier.
|
// Ignore sigpipe, which we may get from the universal variable notifier.
|
||||||
sigaction(SIGPIPE, &act, 0);
|
sigaction(SIGPIPE, &act, 0);
|
||||||
|
|
||||||
if (get_is_interactive()) {
|
if (shell_is_interactive()) {
|
||||||
// Interactive mode. Ignore interactive signals. We are a shell, we know whats best for the
|
// Interactive mode. Ignore interactive signals. We are a shell, we know what is best for
|
||||||
// user.
|
// the user.
|
||||||
act.sa_handler = SIG_IGN;
|
act.sa_handler = SIG_IGN;
|
||||||
|
|
||||||
sigaction(SIGINT, &act, 0);
|
sigaction(SIGINT, &act, 0);
|
||||||
|
|
Loading…
Reference in a new issue