Move redundant instances of blocking_query into InputData

We duplicate the same member across all implementations.  Looks like
this never makes sense, so move it to the shared data bag.
This commit is contained in:
Johannes Altmanninger
2025-09-25 20:34:06 +02:00
parent b907bc775a
commit f8269be359
4 changed files with 10 additions and 25 deletions

View File

@@ -8,7 +8,7 @@
use crate::global_safety::RelaxedAtomicBool;
use crate::input_common::{
match_key_event_to_key, CharEvent, CharInputStyle, ImplicitEvent, InputData, InputEventQueuer,
KeyMatchQuality, ReadlineCmd, TerminalQuery, R_END_INPUT_FUNCTIONS,
KeyMatchQuality, ReadlineCmd, R_END_INPUT_FUNCTIONS,
};
use crate::key::{self, canonicalize_raw_escapes, ctrl, Key, Modifiers};
use crate::proc::job_reap;
@@ -19,7 +19,6 @@
use crate::threads::{assert_is_main_thread, iothread_service_main};
use crate::wchar::prelude::*;
use once_cell::sync::Lazy;
use std::cell::RefMut;
use std::mem;
use std::sync::{
atomic::{AtomicU32, Ordering},
@@ -451,10 +450,6 @@ fn paste_commit(&mut self) {
escape(&str2wcstring(&buffer))
)));
}
fn blocking_query(&self) -> RefMut<'_, Option<TerminalQuery>> {
Reader::blocking_query(self)
}
}
/// A struct which allows accumulating input events, or returns them to the queue.

View File

@@ -749,6 +749,9 @@ pub struct InputData {
// How long to wait for responses for TTY queries.
pub blocking_query_timeout: Option<Duration>,
// If set, events will be buffered until the query finishes.
pub blocking_query: RefCell<Option<TerminalQuery>>,
}
impl InputData {
@@ -762,6 +765,7 @@ pub fn new(in_fd: RawFd, blocking_query_timeout: Option<Duration>) -> Self {
function_status: false,
event_storage: Vec::new(),
blocking_query_timeout,
blocking_query: RefCell::new(None),
}
}
@@ -1620,7 +1624,9 @@ fn drop_leading_readline_events(&mut self) {
}
}
fn blocking_query(&self) -> RefMut<'_, Option<TerminalQuery>>;
fn blocking_query(&self) -> RefMut<'_, Option<TerminalQuery>> {
self.get_input_data().blocking_query.borrow_mut()
}
fn is_blocked_querying(&self) -> bool {
self.blocking_query().is_some()
}
@@ -1772,14 +1778,12 @@ impl<'a> FloggableDisplay for DisplayBytes<'a> {}
/// A simple, concrete implementation of InputEventQueuer.
pub struct InputEventQueue {
data: InputData,
blocking_query: RefCell<Option<TerminalQuery>>,
}
impl InputEventQueue {
pub fn new(in_fd: RawFd, blocking_query_timeout: Option<Duration>) -> Self {
Self {
data: InputData::new(in_fd, blocking_query_timeout),
blocking_query: RefCell::new(None),
}
}
}
@@ -1798,9 +1802,6 @@ fn select_interrupted(&mut self) {
self.enqueue_interrupt_key();
}
}
fn blocking_query(&self) -> RefMut<'_, Option<TerminalQuery>> {
self.blocking_query.borrow_mut()
}
}
fn parse_hex(hex: &[u8]) -> Option<Vec<u8>> {

View File

@@ -28,7 +28,6 @@
#[cfg(not(target_has_atomic = "64"))]
use portable_atomic::AtomicU64;
use std::borrow::Cow;
use std::cell::RefMut;
use std::cell::UnsafeCell;
use std::cmp;
use std::io::BufReader;
@@ -1633,10 +1632,6 @@ pub fn combine_command_and_autosuggestion(
}
impl<'a> Reader<'a> {
pub(crate) fn blocking_query(&self) -> RefMut<'_, Option<TerminalQuery>> {
self.parser.blocking_query.borrow_mut()
}
pub fn request_cursor_position(&mut self, out: &mut Outputter, q: CursorPositionQuery) {
if !querying_allowed(self.get_in_fd()) {
return;

View File

@@ -1,13 +1,11 @@
use crate::env::EnvStack;
use crate::input::{EventQueuePeeker, InputMappingSet, KeyNameStyle, DEFAULT_BIND_MODE};
use crate::input_common::{CharEvent, InputData, InputEventQueuer, KeyEvent, TerminalQuery};
use crate::input_common::{CharEvent, InputData, InputEventQueuer, KeyEvent};
use crate::key::Key;
use crate::wchar::prelude::*;
use std::cell::{RefCell, RefMut};
struct TestInputEventQueuer {
input_data: InputData,
blocking_query: RefCell<Option<TerminalQuery>>,
}
impl InputEventQueuer for TestInputEventQueuer {
@@ -17,17 +15,13 @@ fn get_input_data(&self) -> &InputData {
fn get_input_data_mut(&mut self) -> &mut InputData {
&mut self.input_data
}
fn blocking_query(&self) -> RefMut<'_, Option<TerminalQuery>> {
self.blocking_query.borrow_mut()
}
}
#[test]
fn test_input() {
let vars = EnvStack::new();
let mut input = TestInputEventQueuer {
input_data: InputData::new(i32::MAX), // value doesn't matter since we don't read from it
blocking_query: RefCell::new(None),
input_data: InputData::new(i32::MAX, None), // value doesn't matter since we don't read from it
};
// 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