diff options
Diffstat (limited to 'src/terminal')
-rw-r--r-- | src/terminal/decoding.rs | 35 |
1 files changed, 10 insertions, 25 deletions
diff --git a/src/terminal/decoding.rs b/src/terminal/decoding.rs index 11f6046..018730e 100644 --- a/src/terminal/decoding.rs +++ b/src/terminal/decoding.rs @@ -3,33 +3,31 @@ use crate::terminal::prelude::*; use crate::terminal::error; -use async_std::future::Future; -use async_std::io::{BufRead, BufReader, Read}; -use async_std::sync::{Arc, Mutex}; -use async_std::task::{Context, Poll}; use pin_project::pin_project; use pin_utils::pin_mut; +use std::future::Future; use std::pin::Pin; use std::str; -use std::sync::atomic::{AtomicBool, Ordering}; +use std::sync::Arc; +use std::task::{Context, Poll}; +use tokio::io::{AsyncBufRead, AsyncRead, BufReader}; +use tokio::sync::Mutex; #[pin_project] -pub struct CharBufReader<R: Read + Unpin> { +pub struct CharBufReader<R: AsyncRead + Unpin> { #[pin] byte_reader: BufReader<R>, #[pin] char_buffer: String, - is_interrupted: Arc<AtomicBool>, } #[pin_project] -struct FillBufFuture<R: Read + Unpin> { +struct FillBufFuture<R: AsyncRead + Unpin> { char_reader: Arc<Mutex<CharBufReader<R>>>, - //char_reader: Arc<CharBufReader<R>>, } -impl<R: Read + Unpin> Future for FillBufFuture<R> { +impl<R: AsyncRead + Unpin> Future for FillBufFuture<R> { type Output = Result<String>; fn poll(self: Pin<&mut Self>, context: &mut Context<'_>) @@ -45,16 +43,9 @@ impl<R: Read + Unpin> Future for FillBufFuture<R> { let mut byte_reader: Pin<&mut BufReader<R>> = Pin::new(&mut char_reader.byte_reader); loop { - if char_reader.is_interrupted.load(Ordering::Relaxed) { - println!("char reader got interrupt"); - return Poll::Pending; - } - - println!("about to fill_buf"); match byte_reader.as_mut().poll_fill_buf(context).map_err(error::input)? { Poll::Ready(byte_buffer) => { - println!("done with fill_buf"); match str::from_utf8(&byte_buffer) { Err(error) => { let n_valid = error.valid_up_to(); @@ -86,7 +77,6 @@ impl<R: Read + Unpin> Future for FillBufFuture<R> { } } Poll::Pending => { - println!("fill_buf pending"); return Poll::Pending; } } @@ -95,7 +85,6 @@ impl<R: Read + Unpin> Future for FillBufFuture<R> { return Poll::Ready(Ok(char_reader.char_buffer.to_string())); } Poll::Pending => { - println!("char_reader mutex pending"); return Poll::Pending; } } @@ -103,21 +92,17 @@ impl<R: Read + Unpin> Future for FillBufFuture<R> { } -impl<R: Read + Unpin> CharBufReader<R> { - pub fn new(input_stream: R, is_interrupted: Arc<AtomicBool>) - -> CharBufReader<R> - { +impl<R: AsyncRead + Unpin> CharBufReader<R> { + pub fn new(input_stream: R) -> CharBufReader<R> { let byte_reader = BufReader::new(input_stream); CharBufReader { byte_reader: byte_reader, char_buffer: String::new(), - is_interrupted: is_interrupted, } } pub fn fill_buf(reader: Arc<Mutex<Self>>) - //pub fn fill_buf(reader: Arc<Self>) -> impl Future<Output = Result<String>> { FillBufFuture { |