Simplify logic for special input functions "and" & "or"

No functional change.
This commit is contained in:
Johannes Altmanninger 2023-01-29 11:02:26 +01:00
parent 5678602af4
commit 857612d243
3 changed files with 13 additions and 12 deletions

View File

@ -751,19 +751,11 @@ char_event_t inputter_t::read_char(const command_handler_t &command_handler) {
} }
case readline_cmd_t::func_and: case readline_cmd_t::func_and:
case readline_cmd_t::func_or: { case readline_cmd_t::func_or: {
// If previous function has correct status, we keep reading tokens // If previous function has bad status, we want to skip all functions that
if (evt.get_readline() == readline_cmd_t::func_and) { // follow us.
// Don't return immediately, we might need to handle it here - like if ((evt.get_readline() == readline_cmd_t::func_and) != function_status_) {
// self-insert. drop_leading_readline_events();
if (function_status_) continue;
} else {
if (!function_status_) continue;
} }
// Else we flush remaining tokens
do {
evt = this->readch();
} while (evt.is_readline());
this->push_front(evt);
continue; continue;
} }
default: { default: {

View File

@ -285,6 +285,12 @@ void input_event_queue_t::promote_interruptions_to_front() {
std::rotate(queue_.begin(), first, last); std::rotate(queue_.begin(), first, last);
} }
void input_event_queue_t::drop_leading_readline_events() {
queue_.erase(queue_.begin(),
std::find_if(queue_.begin(), queue_.end(),
[](const char_event_t& evt) { return !evt.is_readline(); }));
}
void input_event_queue_t::prepare_to_select() {} void input_event_queue_t::prepare_to_select() {}
void input_event_queue_t::select_interrupted() {} void input_event_queue_t::select_interrupted() {}
void input_event_queue_t::uvar_change_notified() {} void input_event_queue_t::uvar_change_notified() {}

View File

@ -224,6 +224,9 @@ class input_event_queue_t {
queue_.insert(queue_.begin(), begin, end); queue_.insert(queue_.begin(), begin, end);
} }
/// Forget all enqueued readline events in the front of the queue.
void drop_leading_readline_events();
/// Override point for when we are about to (potentially) block in select(). The default does /// Override point for when we are about to (potentially) block in select(). The default does
/// nothing. /// nothing.
virtual void prepare_to_select(); virtual void prepare_to_select();