Don't use "readline" input functionality for the following builtins:
* peek_byte * peek_char * peek_code * get_byte * get_char * get_code * get_n_chars
This commit is contained in:
45
src/read.rs
45
src/read.rs
@@ -107,6 +107,30 @@ fn get_prompt() -> &'static str {
|
||||
}
|
||||
}
|
||||
|
||||
static mut RAW_READ: bool = false;
|
||||
|
||||
pub struct RawReadGuard;
|
||||
|
||||
impl RawReadGuard {
|
||||
pub fn new() -> RawReadGuard {
|
||||
unsafe {
|
||||
if RAW_READ {
|
||||
panic!("Nested RawReadGuards");
|
||||
}
|
||||
RAW_READ = true;
|
||||
}
|
||||
RawReadGuard
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for RawReadGuard {
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
RAW_READ = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ReadlineStream {
|
||||
#[cfg(feature = "repl")]
|
||||
@@ -172,7 +196,23 @@ impl ReadlineStream {
|
||||
|
||||
#[cfg(feature = "repl")]
|
||||
fn call_readline(&mut self) -> std::io::Result<usize> {
|
||||
match self.rl.readline(get_prompt()) {
|
||||
let raw = unsafe { RAW_READ };
|
||||
let text = if raw {
|
||||
let mut buffer = String::new();
|
||||
let stdin = std::io::stdin();
|
||||
match stdin.read_line(&mut buffer) {
|
||||
Ok(_) => Ok(buffer),
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
} else {
|
||||
match self.rl.readline(get_prompt()) {
|
||||
Ok(text) => Ok(text),
|
||||
Err(ReadlineError::Eof) => Err(Error::from(ErrorKind::UnexpectedEof)),
|
||||
Err(e) => Err(Error::new(ErrorKind::InvalidInput, e)),
|
||||
}
|
||||
};
|
||||
|
||||
match text {
|
||||
Ok(text) => {
|
||||
self.pending_input.reset_buffer();
|
||||
|
||||
@@ -195,8 +235,7 @@ impl ReadlineStream {
|
||||
|
||||
Ok(self.pending_input.get_ref().get_ref().len())
|
||||
}
|
||||
Err(ReadlineError::Eof) => Err(Error::from(ErrorKind::UnexpectedEof)),
|
||||
Err(e) => Err(Error::new(ErrorKind::InvalidInput, e)),
|
||||
Err(e) => Err(e)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user