diff --git a/src/fish_key_reader.cpp b/src/fish_key_reader.cpp index 94c162d84..b63664f76 100644 --- a/src/fish_key_reader.cpp +++ b/src/fish_key_reader.cpp @@ -227,7 +227,7 @@ static void process_input(bool continuous_mode, bool verbose) { std::vector bind_chars; std::fwprintf(stderr, L"Press a key:\n"); - for (;;) { + while (!check_exit_loop_maybe_warning(nullptr)) { maybe_t evt{}; if (reader_test_and_clear_interrupted()) { evt = char_event_t{shell_modes.c_cc[VINTR]}; diff --git a/src/reader.cpp b/src/reader.cpp index 93011ed50..691850c97 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -2909,12 +2909,12 @@ static bool try_warn_on_background_jobs(reader_data_t *data) { /// Check if we should exit the reader loop. /// \return true if we should exit. -static bool check_exit_loop_maybe_warning(reader_data_t *data) { +bool check_exit_loop_maybe_warning(reader_data_t *data) { // sighup always forces exit. if (s_sighup_received) return true; // Check if an exit is requested. - if (data->exit_loop_requested) { + if (data && data->exit_loop_requested) { if (try_warn_on_background_jobs(data)) { data->exit_loop_requested = false; return false; diff --git a/src/reader.h b/src/reader.h index 37e1ccaec..7df5f1d27 100644 --- a/src/reader.h +++ b/src/reader.h @@ -240,6 +240,9 @@ struct reader_config_t { int in{0}; }; +class reader_data_t; +bool check_exit_loop_maybe_warning(reader_data_t *data); + /// Push a new reader environment controlled by \p conf, using the given history name. /// If \p history_name is empty, then save history in-memory only; do not write it to disk. void reader_push(parser_t &parser, const wcstring &history_name, reader_config_t &&conf);