Thread a parser into inputter_t

This commit is contained in:
ridiculousfish 2019-06-02 16:41:13 -07:00
parent a48dbf23b8
commit 671df14178
4 changed files with 12 additions and 8 deletions

View file

@ -3003,7 +3003,7 @@ static bool history_contains(const std::unique_ptr<history_t> &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!

View file

@ -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};

View file

@ -27,6 +27,9 @@ class inputter_t {
std::vector<wchar_t> input_function_args_{};
bool function_status_{false};
// We need a parser to evaluate bindings.
const std::shared_ptr<parser_t> 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.

View file

@ -433,7 +433,7 @@ class reader_data_t : public std::enable_shared_from_this<reader_data_t> {
parser_t &parser() { return *parser_ref; }
reader_data_t(std::shared_ptr<parser_t> 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();