From 2d5e6c6a0758a39ac16de217bc4bd6bd53104d1c Mon Sep 17 00:00:00 2001 From: Irene Knapp Date: Mon, 7 Jun 2021 03:28:22 -0700 Subject: wooooo! switch to using tokio; make ^C work properly --- src/terminal/decoding.rs | 35 ++++++++++------------------------- 1 file changed, 10 insertions(+), 25 deletions(-) (limited to 'src/terminal') 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 { +pub struct CharBufReader { #[pin] byte_reader: BufReader, #[pin] char_buffer: String, - is_interrupted: Arc, } #[pin_project] -struct FillBufFuture { +struct FillBufFuture { char_reader: Arc>>, - //char_reader: Arc>, } -impl Future for FillBufFuture { +impl Future for FillBufFuture { type Output = Result; fn poll(self: Pin<&mut Self>, context: &mut Context<'_>) @@ -45,16 +43,9 @@ impl Future for FillBufFuture { let mut byte_reader: Pin<&mut BufReader> = 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 Future for FillBufFuture { } } Poll::Pending => { - println!("fill_buf pending"); return Poll::Pending; } } @@ -95,7 +85,6 @@ impl Future for FillBufFuture { 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 Future for FillBufFuture { } -impl CharBufReader { - pub fn new(input_stream: R, is_interrupted: Arc) - -> CharBufReader - { +impl CharBufReader { + pub fn new(input_stream: R) -> CharBufReader { 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>) - //pub fn fill_buf(reader: Arc) -> impl Future> { FillBufFuture { -- cgit 1.4.1