Update src/read.rs
Co-authored-by: Bennet Bleßmann <3877590+Skgland@users.noreply.github.com>
This commit is contained in:
19
src/read.rs
19
src/read.rs
@@ -107,27 +107,25 @@ fn get_prompt() -> &'static str {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static mut RAW_READ: bool = false;
|
thread_local! {
|
||||||
|
static RAW_READ: std::cell::Cell<bool> = const { std::cell::Cell::new(false) };
|
||||||
|
}
|
||||||
|
|
||||||
pub struct RawReadGuard;
|
pub struct RawReadGuard;
|
||||||
|
|
||||||
impl RawReadGuard {
|
impl RawReadGuard {
|
||||||
pub fn new() -> RawReadGuard {
|
pub fn new() -> RawReadGuard {
|
||||||
unsafe {
|
if RAW_READ.get() {
|
||||||
if RAW_READ {
|
panic!("Nested RawReadGuards");
|
||||||
panic!("Nested RawReadGuards");
|
|
||||||
}
|
|
||||||
RAW_READ = true;
|
|
||||||
}
|
}
|
||||||
|
RAW_READ.set(true);
|
||||||
RawReadGuard
|
RawReadGuard
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for RawReadGuard {
|
impl Drop for RawReadGuard {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
unsafe {
|
RAW_READ.set(false);
|
||||||
RAW_READ = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,8 +194,7 @@ impl ReadlineStream {
|
|||||||
|
|
||||||
#[cfg(feature = "repl")]
|
#[cfg(feature = "repl")]
|
||||||
fn call_readline(&mut self) -> std::io::Result<usize> {
|
fn call_readline(&mut self) -> std::io::Result<usize> {
|
||||||
let raw = unsafe { RAW_READ };
|
let text = if RAW_READ.get() {
|
||||||
let text = if raw {
|
|
||||||
let mut buffer = String::new();
|
let mut buffer = String::new();
|
||||||
let stdin = std::io::stdin();
|
let stdin = std::io::stdin();
|
||||||
match stdin.read_line(&mut buffer) {
|
match stdin.read_line(&mut buffer) {
|
||||||
|
|||||||
Reference in New Issue
Block a user