diff options
-rw-r--r-- | src/listview.rs | 8 | ||||
-rw-r--r-- | src/main.rs | 2 | ||||
-rw-r--r-- | src/preview.rs | 67 | ||||
-rw-r--r-- | src/textview.rs | 2 | ||||
-rw-r--r-- | src/widget.rs | 3 |
5 files changed, 56 insertions, 26 deletions
diff --git a/src/listview.rs b/src/listview.rs index b3ab73f..99adaaf 100644 --- a/src/listview.rs +++ b/src/listview.rs @@ -196,8 +196,8 @@ where let pos = self .content .files - .par_iter() - .position_any(|item| item == file) + .iter() + .position(|item| item == file) .unwrap_or(0); self.set_selection(pos); } @@ -346,7 +346,7 @@ where let offset = self.offset; self.content .files - .par_iter() + .iter() .skip(offset) .take(ysize) .map(|file| self.render_line(&file)) @@ -378,7 +378,7 @@ impl Widget for ListView<Files> { output += &self .buffer - .par_iter() + .iter() //.skip(self.offset) //.take(ysize as usize) .enumerate() diff --git a/src/main.rs b/src/main.rs index 602fb11..3ac01ac 100644 --- a/src/main.rs +++ b/src/main.rs @@ -37,7 +37,7 @@ mod tabview; mod async_widget; use window::Window; -use async_widget::AsyncPlug; +///use async_widget::AsyncPlug; use widget::Widget; fn main() { diff --git a/src/preview.rs b/src/preview.rs index 859c8eb..662529e 100644 --- a/src/preview.rs +++ b/src/preview.rs @@ -2,13 +2,13 @@ use std::io::Write; use std::sync::Mutex; use std::sync::Arc; -use crate::coordinates::{Coordinates, Position, Size}; +use crate::coordinates::{Coordinates}; use crate::files::{File, Files, Kind}; use crate::listview::ListView; use crate::textview::TextView; use crate::widget::Widget; -use crate::async_widget::AsyncPlug; - +//use crate::async_widget::AsyncPlug; +use crate::async_widget::AsyncPlug2; lazy_static! { static ref PIDS: Arc<Mutex<Vec<u32>>> = { Arc::new(Mutex::new(vec![])) }; @@ -30,36 +30,43 @@ fn is_current(file: &File) -> bool { } } +enum WillBe<T> { + Is(T), + Becoming, + Wont(Box<std::error::Error>) +} + #[derive(PartialEq)] pub struct AsyncPreviewer { pub file: Option<File>, pub buffer: String, pub coordinates: Coordinates, - pub async_plug: AsyncPlug + pub async_plug: AsyncPlug2<Box<dyn Widget + Send + 'static>> } impl AsyncPreviewer { pub fn new() -> AsyncPreviewer { - let textview = crate::textview::TextView { - lines: vec![], - buffer: "".to_string(), - coordinates: Coordinates::new(), - }; - let textview = Box::new(textview); - + let closure = Box::new(|| { + Box::new(crate::textview::TextView { + lines: vec![], + buffer: "".to_string(), + coordinates: Coordinates::new() + }) as Box<dyn Widget + Send + 'static> + }); + AsyncPreviewer { file: None, buffer: String::new(), coordinates: Coordinates::new(), - async_plug: AsyncPlug::new(textview) + async_plug: AsyncPlug2::new_from_closure(closure), } } pub fn set_file(&mut self, file: &File) { let coordinates = self.coordinates.clone(); let file = file.clone(); let redraw = crate::term::reset() + &self.get_redraw_empty_list(0); - let pids = PIDS.clone(); - kill_procs(); + //let pids = PIDS.clone(); + //kill_procs(); self.async_plug.replace_widget(Box::new(move || { kill_procs(); @@ -75,7 +82,7 @@ impl AsyncPreviewer { file_list.refresh(); //if !is_current(&file) { return } file_list.animate_slide_up(); - return Box::new(file_list) as Box<dyn Widget + Send>; + return Box::new(file_list) } Err(err) => { @@ -85,7 +92,7 @@ impl AsyncPreviewer { buffer: "".to_string(), coordinates: Coordinates::new(), }; - return Box::new(textview) as Box<dyn Widget + Send>; + return Box::new(textview) }, } _ => { @@ -99,7 +106,7 @@ impl AsyncPreviewer { textview.refresh(); //if !is_current(&file) { return } textview.animate_slide_up(); - return Box::new(textview); + return Box::new(textview) } else { let process = std::process::Command::new("scope.sh") @@ -135,7 +142,7 @@ impl AsyncPreviewer { textview.set_coordinates(&coordinates); textview.refresh(); textview.animate_slide_up(); - return Box::new(textview); + return Box::new(textview) } }, None => {} } @@ -149,7 +156,7 @@ impl AsyncPreviewer { buffer: "".to_string(), coordinates: Coordinates::new(), }; - return Box::new(textview); + return Box::new(textview) } } }})) @@ -184,3 +191,25 @@ impl Widget for AsyncPreviewer { "".to_string() } } + +impl<T> Widget for Box<T> where T: Widget + ?Sized { + fn get_coordinates(&self) -> &Coordinates { + (**self).get_coordinates() + } + fn set_coordinates(&mut self, coordinates: &Coordinates) { + if (**self).get_coordinates() == coordinates { + return; + } + (**self).set_coordinates(&coordinates); + (**self).refresh(); + } + fn render_header(&self) -> String { + (**self).render_header() + } + fn refresh(&mut self) { + (**self).refresh() + } + fn get_drawlist(&self) -> String { + (**self).get_drawlist() + } +} diff --git a/src/textview.rs b/src/textview.rs index 73b7741..f229828 100644 --- a/src/textview.rs +++ b/src/textview.rs @@ -63,7 +63,7 @@ impl Widget for TextView { self.buffer = self.get_clearlist() + &self .lines - .par_iter() + .iter() .take(ysize as usize) .enumerate() .map(|(i, line)| { diff --git a/src/widget.rs b/src/widget.rs index 5cbcec6..dec2fa7 100644 --- a/src/widget.rs +++ b/src/widget.rs @@ -132,7 +132,8 @@ pub trait Widget { let buffer = self.get_drawlist(); write!(bufout, "{}{}", clear, buffer).unwrap(); - + bufout.flush(); + std::thread::sleep(pause); } |