diff options
-rw-r--r-- | src/file_browser.rs | 22 | ||||
-rw-r--r-- | src/preview.rs | 42 | ||||
-rw-r--r-- | src/proclist.rs | 50 | ||||
-rw-r--r-- | src/widget.rs | 21 |
4 files changed, 100 insertions, 35 deletions
diff --git a/src/file_browser.rs b/src/file_browser.rs index 592eac4..17e7b05 100644 --- a/src/file_browser.rs +++ b/src/file_browser.rs @@ -244,7 +244,7 @@ impl FileBrowser { list.refresh().log(); if startup { - list.animate_slide_up().log(); + list.animate_slide_up(None).log(); } list.content.meta_all(); @@ -275,7 +275,7 @@ impl FileBrowser { list.refresh().log(); if startup { - list.animate_slide_up().log(); + list.animate_slide_up(None).log(); } Ok(list) @@ -787,6 +787,7 @@ impl FileBrowser { } pub fn toggle_colums(&mut self) { + self.preview_widget().map(|preview| preview.cancel_animation()).log(); self.columns.toggle_zoom().log(); } @@ -849,6 +850,7 @@ impl FileBrowser { pub fn run_subshell(&mut self) -> HResult<()> { self.core.get_sender().send(Events::InputEnabled(false))?; + self.preview_widget().map(|preview| preview.cancel_animation()).log(); self.core.screen.cursor_show().log(); self.core.screen.drop_screen(); @@ -874,6 +876,18 @@ impl FileBrowser { Ok(()) } + pub fn show_procview(&mut self) -> HResult<()> { + self.preview_widget().map(|preview| preview.cancel_animation()).log(); + self.proc_view.lock()?.popup()?; + Ok(()) + } + + pub fn show_log(&mut self) -> HResult<()> { + self.preview_widget().map(|preview| preview.cancel_animation()).log(); + self.log_view.lock()?.popup()?; + Ok(()) + } + pub fn get_footer(&self) -> HResult<String> { let xsize = self.get_coordinates()?.xsize(); let ypos = self.get_coordinates()?.position().y(); @@ -991,8 +1005,8 @@ impl Widget for FileBrowser { Key::Char('-') => { self.goto_prev_cwd()?; }, Key::Char('`') => { self.goto_bookmark()?; }, Key::Char('m') => { self.add_bookmark()?; }, - Key::Char('w') => { self.proc_view.lock()?.popup()?; }, - Key::Char('l') => self.log_view.lock()?.popup()?, + Key::Char('w') => { self.show_procview()?; }, + Key::Char('l') => self.show_log()?, Key::Char('z') => self.run_subshell()?, Key::Char('c') => self.toggle_colums(), _ => { self.main_widget_mut()?.on_key(key)?; }, diff --git a/src/preview.rs b/src/preview.rs index 4607fa4..c395e86 100644 --- a/src/preview.rs +++ b/src/preview.rs @@ -420,6 +420,7 @@ pub struct Previewer { core: WidgetCore, file: Option<File>, pub cache: FsCache, + animator: Stale } @@ -434,7 +435,8 @@ impl Previewer { Previewer { widget: widget, core: core.clone(), file: None, - cache: cache } + cache: cache, + animator: Stale::new()} } fn become_preview(&mut self, @@ -453,6 +455,10 @@ impl Previewer { self.file.as_ref() } + pub fn cancel_animation(&self) -> HResult<()> { + self.animator.set_stale() + } + pub fn take_files(&mut self) -> HResult<Files> { let core = self.core.clone(); let mut widget = AsyncWidget::new(&core.clone(), Box::new(move |_| { @@ -513,8 +519,10 @@ impl Previewer { let file = file.clone(); let core = self.core.clone(); let cache = self.cache.clone(); + let animator = self.animator.clone(); self.widget.set_stale().ok(); + self.animator.set_fresh().log(); self.become_preview(Ok(AsyncWidget::new(&self.core, Box::new(move |stale: Stale| { @@ -524,21 +532,28 @@ impl Previewer { let preview = Previewer::preview_dir(&file, cache, &core, - stale); + stale, + animator); return preview; } if file.is_text() { - return Previewer::preview_text(&file, &core, stale) + return Previewer::preview_text(&file, + &core, + stale, + animator); } - let preview = Previewer::preview_external(&file, &core, stale); + let preview = Previewer::preview_external(&file, + &core, + stale, + animator.clone()); if preview.is_ok() { return preview; } else { let mut blank = TextView::new_blank(&core); blank.set_coordinates(&coordinates).log(); blank.refresh().log(); - blank.animate_slide_up().log(); + blank.animate_slide_up(Some(animator)).log(); return Ok(PreviewWidget::TextView(blank)) } })))) @@ -560,7 +575,8 @@ impl Previewer { fn preview_dir(file: &File, cache: FsCache, core: &WidgetCore, - stale: Stale) + stale: Stale, + animator: Stale) -> HResult<PreviewWidget> { let (selection, cached_files) = cache.get_files(&file, stale.clone())?; @@ -577,11 +593,14 @@ impl Previewer { file_list.set_coordinates(&core.coordinates)?; file_list.refresh()?; if is_stale(&stale)? { return Previewer::preview_failed(&file) } - file_list.animate_slide_up()?; + file_list.animate_slide_up(Some(animator))?; Ok(PreviewWidget::FileList(file_list)) } - fn preview_text(file: &File, core: &WidgetCore, stale: Stale) + fn preview_text(file: &File, + core: &WidgetCore, + stale: Stale, + animator: Stale) -> HResult<PreviewWidget> { let lines = core.coordinates.ysize() as usize; let mut textview @@ -595,13 +614,14 @@ impl Previewer { if is_stale(&stale)? { return Previewer::preview_failed(&file) } - textview.animate_slide_up()?; + textview.animate_slide_up(Some(animator))?; Ok(PreviewWidget::TextView(textview)) } fn preview_external(file: &File, core: &WidgetCore, - stale: Stale) + stale: Stale, + animator: Stale) -> HResult<PreviewWidget> { let process = std::process::Command::new("scope.sh") @@ -644,7 +664,7 @@ impl Previewer { offset: 0}; textview.set_coordinates(&core.coordinates).log(); textview.refresh().log(); - textview.animate_slide_up().log(); + textview.animate_slide_up(Some(animator)).log(); return Ok(PreviewWidget::TextView(textview)) } HError::preview_failed(file) diff --git a/src/proclist.rs b/src/proclist.rs index 98645c8..c43df26 100644 --- a/src/proclist.rs +++ b/src/proclist.rs @@ -13,6 +13,7 @@ use crate::listview::{Listable, ListView}; use crate::textview::TextView; use crate::widget::{Widget, Events, WidgetCore}; use crate::coordinates::Coordinates; +use crate::preview::{AsyncWidget, Stale}; use crate::dirty::Dirtyable; use crate::hbox::HBox; use crate::fail::{HResult, HError, ErrorLog}; @@ -298,7 +299,7 @@ impl ListView<Vec<Process>> { #[derive(PartialEq)] enum ProcViewWidgets { List(ListView<Vec<Process>>), - TextView(TextView), + TextView(AsyncWidget<TextView>), } impl Widget for ProcViewWidgets { @@ -331,7 +332,8 @@ impl Widget for ProcViewWidgets { pub struct ProcView { core: WidgetCore, hbox: HBox<ProcViewWidgets>, - viewing: Option<usize> + viewing: Option<usize>, + animator: Stale } impl HBox<ProcViewWidgets> { @@ -347,7 +349,7 @@ impl HBox<ProcViewWidgets> { _ => unreachable!() } } - fn get_textview(&mut self) -> &mut TextView { + fn get_textview(&mut self) -> &mut AsyncWidget<TextView> { match &mut self.widgets[1] { ProcViewWidgets::TextView(textview) => textview, _ => unreachable!() @@ -359,7 +361,10 @@ impl ProcView { pub fn new(core: &WidgetCore) -> ProcView { let tcore = core.clone(); let listview = ListView::new(&core, vec![]); - let textview = TextView::new_blank(&tcore); + let textview = AsyncWidget::new(&core, Box::new(move |_| { + let textview = TextView::new_blank(&tcore); + Ok(textview) + })); let mut hbox = HBox::new(&core); hbox.push_widget(ProcViewWidgets::List(listview)); hbox.push_widget(ProcViewWidgets::TextView(textview)); @@ -368,7 +373,8 @@ impl ProcView { ProcView { core: core.clone(), hbox: hbox, - viewing: None + viewing: None, + animator: Stale::new() } } @@ -380,7 +386,7 @@ impl ProcView { self.hbox.get_listview_mut() } - fn get_textview(&mut self) -> &mut TextView { + fn get_textview(&mut self) -> &mut AsyncWidget<TextView> { self.hbox.get_textview() } @@ -398,7 +404,7 @@ impl ProcView { if self.get_listview_mut().content.len() == 0 { return Ok(()) } self.get_listview_mut().remove_proc()?; self.get_textview().clear(); - self.get_textview().set_text("") + self.get_textview().widget_mut()?.set_text("") } fn show_output(&mut self) -> HResult<()> { @@ -407,45 +413,52 @@ impl ProcView { } let output = self.get_listview_mut().selected_proc()?.output.lock()?.clone(); - self.get_textview().set_text(&output).log(); - self.get_textview().animate_slide_up().log(); + let animator = self.animator.clone(); + animator.set_fresh(); + + self.get_textview().change_to(Box::new(move |_, core| { + let mut textview = TextView::new_blank(&core); + textview.set_text(&output).log(); + textview.animate_slide_up(Some(animator)); + Ok(textview) + })); self.viewing = Some(self.get_listview_mut().get_selection()); Ok(()) } pub fn toggle_follow(&mut self) -> HResult<()> { - self.get_textview().toggle_follow(); + self.get_textview().widget_mut()?.toggle_follow(); Ok(()) } pub fn scroll_up(&mut self) -> HResult<()> { - self.get_textview().scroll_up(); + self.get_textview().widget_mut()?.scroll_up(); Ok(()) } pub fn scroll_down(&mut self) -> HResult<()> { - self.get_textview().scroll_down(); + self.get_textview().widget_mut()?.scroll_down(); Ok(()) } pub fn page_up(&mut self) -> HResult<()> { - self.get_textview().page_up(); + self.get_textview().widget_mut()?.page_up(); Ok(()) } pub fn page_down(&mut self) -> HResult<()> { - self.get_textview().page_down(); + self.get_textview().widget_mut()?.page_down(); Ok(()) } pub fn scroll_top(&mut self) -> HResult<()> { - self.get_textview().scroll_top(); + self.get_textview().widget_mut()?.scroll_top(); Ok(()) } pub fn scroll_bottom(&mut self) -> HResult<()> { - self.get_textview().scroll_bottom(); + self.get_textview().widget_mut()?.scroll_bottom(); Ok(()) } } @@ -536,7 +549,10 @@ impl Widget for ProcView { } fn on_key(&mut self, key: Key) -> HResult<()> { match key { - Key::Char('w') => { return Err(HError::PopupFinnished) } + Key::Char('w') => { + self.animator.set_stale(); + self.clear(); + return Err(HError::PopupFinnished) } Key::Char('d') => { self.remove_proc()? } Key::Char('k') => { self.get_listview_mut().kill_proc()? } Key::Up | Key::Char('p') => { diff --git a/src/widget.rs b/src/widget.rs index e1e6055..fbcb6df 100644 --- a/src/widget.rs +++ b/src/widget.rs @@ -11,6 +11,7 @@ use crate::minibuffer::MiniBuffer; use crate::term; use crate::term::{Screen, ScreenExt}; use crate::dirty::{Dirtyable, DirtyBit}; +use crate::preview::Stale; use crate::signal_notify::{notify, Signal}; @@ -264,6 +265,7 @@ pub trait Widget { } Events::WidgetReady => { self.refresh().log(); + self.draw().log(); } Events::Status(status) => { self.show_status(&status).log(); @@ -289,7 +291,7 @@ pub trait Widget { self.write_to_screen(&clearlist) } - fn animate_slide_up(&mut self) -> HResult<()> { + fn animate_slide_up(&mut self, animator: Option<Stale>) -> HResult<()> { let coords = self.get_coordinates()?.clone(); let xpos = coords.position().x(); let ypos = coords.position().y(); @@ -298,20 +300,33 @@ pub trait Widget { let clear = self.get_clearlist()?; let pause = std::time::Duration::from_millis(5); + if let Some(ref animator) = animator { + if animator.is_stale()? { + return Ok(()) + } + } + self.write_to_screen(&clear).log(); for i in (0..10).rev() { - let coords = Coordinates { size: Size((xsize,ysize-i)), + if let Some(ref animator) = animator { + if animator.is_stale()? { + self.set_coordinates(&coords).log(); + return Ok(()) + } + } + let ani_coords = Coordinates { size: Size((xsize,ysize-i)), position: Position ((xpos, ypos+i)) }; - self.set_coordinates(&coords).log(); + self.set_coordinates(&ani_coords).log(); let buffer = self.get_drawlist()?; self.write_to_screen(&buffer).log(); std::thread::sleep(pause); } + Ok(()) } |