diff options
author | rabite <rabite@posteo.de> | 2019-03-19 01:08:22 +0100 |
---|---|---|
committer | rabite <rabite@posteo.de> | 2019-03-19 14:38:15 +0100 |
commit | 161ba5ac3f38733b45c0167cb1e29f0be6059775 (patch) | |
tree | 794ec2517c71f6e6e3b9c572ebcc0e2fca66c3f4 /src/bookmarks.rs | |
parent | c719ec7a3cb6ca3d2346f48dc11d2e0d5ee10d36 (diff) |
handle terminal resizing
Diffstat (limited to 'src/bookmarks.rs')
-rw-r--r-- | src/bookmarks.rs | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/src/bookmarks.rs b/src/bookmarks.rs index a561841..379565e 100644 --- a/src/bookmarks.rs +++ b/src/bookmarks.rs @@ -4,6 +4,7 @@ use std::collections::HashMap; use crate::fail::{HResult, HError, ErrorLog}; use crate::widget::{Widget, WidgetCore}; +use crate::coordinates::Coordinates; use crate::files::{Files, File}; use crate::term; @@ -68,19 +69,25 @@ pub struct BMPopup { impl BMPopup { pub fn new(core: &WidgetCore) -> BMPopup { - let bmpopup = BMPopup { + let mut bmpopup = BMPopup { core: core.clone(), bookmarks: Bookmarks::new(), bookmark_path: None, add_mode: false }; + bmpopup.set_coordinates(&core.coordinates).log(); bmpopup } pub fn pick(&mut self, cwd: String) -> HResult<String> { self.bookmark_path = Some(cwd); self.refresh()?; - self.popup()?; + match self.popup() { + Ok(_) => {}, + Err(HError::PopupFinnished) => {}, + err @ Err(HError::TerminalResizedError) => err?, + err @ Err(_) => err?, + } self.clear()?; let bookmark = self.bookmark_path.take(); @@ -120,16 +127,24 @@ impl Widget for BMPopup { Ok(&mut self.core) } fn refresh(&mut self) -> HResult<()> { - let tysize = crate::term::ysize(); - let txsize = crate::term::xsize(); - let len = self.bookmarks.mapping.len() as u16; - let ysize = tysize - (len + 1); + Ok(()) + } - self.core.coordinates.set_position(1, ysize); - self.core.coordinates.set_size(txsize, len+1); + fn resize(&mut self) -> HResult<()> { + HError::terminal_resized() + } + + fn set_coordinates(&mut self, coordinates: &Coordinates) -> HResult<()> { + let (xsize, ysize) = coordinates.size_u(); + let len = self.bookmarks.mapping.len(); + let ysize = ysize.saturating_sub( len + 1 ); + + self.core.coordinates.set_size_u(xsize.saturating_sub(1), len); + self.core.coordinates.set_position_u(1, ysize+2); Ok(()) } + fn get_drawlist(&self) -> HResult<String> { let ypos = self.get_coordinates()?.ypos(); |