From 671df141789fe645c1571a023fb373a8a51ae143 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 2 Jun 2019 16:41:13 -0700 Subject: [PATCH] Thread a parser into inputter_t --- src/fish_tests.cpp | 2 +- src/input.cpp | 11 ++++++----- src/input.h | 5 ++++- src/reader.cpp | 2 +- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/fish_tests.cpp b/src/fish_tests.cpp index 5153a0fa6..e96db44f3 100644 --- a/src/fish_tests.cpp +++ b/src/fish_tests.cpp @@ -3003,7 +3003,7 @@ static bool history_contains(const std::unique_ptr &history, const wc static void test_input() { say(L"Testing input"); - inputter_t input{}; + inputter_t input{parser_t::principal_parser()}; // Ensure sequences are order independent. Here we add two bindings where the first is a prefix // of the second, and then emit the second key list. The second binding should be invoked, not // the first! diff --git a/src/input.cpp b/src/input.cpp index 878ae2c4e..530cbe450 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -287,6 +287,8 @@ void init_input() { } } +inputter_t::inputter_t(parser_t &parser) : parser_(parser.shared()) {} + void inputter_t::function_push_arg(wchar_t arg) { input_function_args_.push_back(arg); } wchar_t inputter_t::function_pop_arg() { @@ -363,12 +365,11 @@ void inputter_t::mapping_execute(const input_mapping_t &m, bool allow_commands) // // FIXME(snnw): if commands add stuff to input queue (e.g. commandline -f execute), we won't // see that until all other commands have also been run. - auto &parser = parser_t::principal_parser(); - auto last_statuses = parser.get_last_statuses(); + auto last_statuses = parser_->get_last_statuses(); for (const wcstring &cmd : m.commands) { - parser.eval(cmd, io_chain_t(), TOP); + parser_->eval(cmd, io_chain_t(), TOP); } - parser.set_last_statuses(std::move(last_statuses)); + parser_->set_last_statuses(std::move(last_statuses)); event_queue_.push_front(char_event_type_t::check_exit); } else { // Invalid binding, mixed commands and functions. We would need to execute these one by @@ -414,7 +415,7 @@ void inputter_t::push_front(char_event_t ch) { event_queue_.push_front(ch); } /// preset list. \return null if nothing matches. const input_mapping_t *inputter_t::find_mapping() { const input_mapping_t *generic = NULL; - const auto &vars = parser_t::principal_parser().vars(); + const auto &vars = parser_->vars(); const wcstring bind_mode = input_get_bind_mode(vars); const auto lists = {&s_mapping_list, &s_preset_mapping_list}; diff --git a/src/input.h b/src/input.h index 7168e2771..b5fb40ca1 100644 --- a/src/input.h +++ b/src/input.h @@ -27,6 +27,9 @@ class inputter_t { std::vector input_function_args_{}; bool function_status_{false}; + // We need a parser to evaluate bindings. + const std::shared_ptr parser_; + void function_push_arg(wchar_t arg); void function_push_args(readline_cmd_t code); void mapping_execute(const input_mapping_t &m, bool allow_commands); @@ -36,7 +39,7 @@ class inputter_t { char_event_t read_characters_no_readline(); public: - inputter_t() = default; + inputter_t(parser_t &parser); /// Read a character from fd 0. Try to convert some escape sequences into character constants, /// but do not permanently block the escape character. diff --git a/src/reader.cpp b/src/reader.cpp index 4884b5bda..197702719 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -433,7 +433,7 @@ class reader_data_t : public std::enable_shared_from_this { parser_t &parser() { return *parser_ref; } reader_data_t(std::shared_ptr parser, history_t *hist) - : parser_ref(std::move(parser)), history(hist) {} + : parser_ref(std::move(parser)), inputter(*parser_ref), history(hist) {} void update_buff_pos(editable_line_t *el, size_t buff_pos); void repaint();