mirror of https://github.com/bobwen-dev/hunter
hide left/right columns
This commit is contained in:
parent
04c40ec3ca
commit
fc2d6d268c
16
src/fail.rs
16
src/fail.rs
|
@ -29,6 +29,8 @@ pub enum HError {
|
|||
PreviewFailed{file: String, backtrace: Backtrace},
|
||||
#[fail(display = "StalePreviewer for file: {}", file)]
|
||||
StalePreviewError{file: String},
|
||||
#[fail(display = "Accessed stale value")]
|
||||
StaleError(Backtrace),
|
||||
#[fail(display = "Failed: {}", error)]
|
||||
Error{#[cause] error: failure::Error , backtrace: Backtrace},
|
||||
#[fail(display = "Was None!")]
|
||||
|
@ -120,6 +122,10 @@ impl HError {
|
|||
pub fn terminal_resized<T>() -> HResult<T> {
|
||||
Err(HError::TerminalResizedError)
|
||||
}
|
||||
|
||||
pub fn stale<T>() -> HResult<T> {
|
||||
Err(HError::StaleError(Backtrace::new()))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -138,7 +144,8 @@ pub fn put_log<L: Into<LogEntry>>(log: L) -> HResult<()> {
|
|||
}
|
||||
|
||||
pub trait ErrorLog where Self: Sized {
|
||||
fn log(self) {}
|
||||
fn log(self);
|
||||
fn log_and(self) -> Self;
|
||||
}
|
||||
|
||||
impl<T> ErrorLog for HResult<T> {
|
||||
|
@ -148,6 +155,13 @@ impl<T> ErrorLog for HResult<T> {
|
|||
put_log(&err).ok();
|
||||
}
|
||||
}
|
||||
|
||||
fn log_and(self) -> Self {
|
||||
if let Err(err) = &self {
|
||||
put_log(err).ok();
|
||||
}
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -11,7 +11,6 @@ use std::ffi::{OsString, OsStr};
|
|||
|
||||
use crate::files::{File, Files, PathBufExt, OsStrTools};
|
||||
use crate::listview::ListView;
|
||||
//use crate::miller_columns::MillerColumns;
|
||||
use crate::hbox::HBox;
|
||||
use crate::widget::Widget;
|
||||
use crate::dirty::Dirtyable;
|
||||
|
@ -598,17 +597,8 @@ impl FileBrowser {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn toggle_colums(&mut self) -> HResult<()> {
|
||||
self.show_columns = !self.show_columns;
|
||||
|
||||
if !self.show_columns {
|
||||
self.columns.set_ratios(vec![1,99,1]);
|
||||
self.left_widget_mut()?.set_stale().log();
|
||||
self.preview_widget_mut()?.set_stale().log()
|
||||
}
|
||||
|
||||
self.core.set_dirty();
|
||||
self.refresh()
|
||||
pub fn toggle_colums(&mut self) {
|
||||
self.columns.toggle_zoom().log();
|
||||
}
|
||||
|
||||
pub fn quit_with_dir(&self) -> HResult<()> {
|
||||
|
@ -842,18 +832,13 @@ impl Widget for FileBrowser {
|
|||
self.save_selection().log();
|
||||
self.set_cwd().log();
|
||||
self.update_watches().log();
|
||||
self.update_preview().log();
|
||||
if !self.columns.zoom_active { self.update_preview().log(); }
|
||||
self.columns.refresh().log();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_drawlist(&self) -> HResult<String> {
|
||||
return self.columns.get_drawlist();
|
||||
let left = self.left_widget()?.get_drawlist()?;
|
||||
let main = self.main_widget()?.get_drawlist()?;
|
||||
let prev = self.preview_widget()?.get_drawlist()?;
|
||||
|
||||
Ok(left + &main + &prev)
|
||||
self.columns.get_drawlist()
|
||||
}
|
||||
|
||||
fn on_key(&mut self, key: Key) -> HResult<()> {
|
||||
|
@ -868,9 +853,10 @@ impl Widget for FileBrowser {
|
|||
Key::Char('w') => { self.proc_view.lock()?.popup()?; },
|
||||
Key::Char('l') => self.log_view.lock()?.popup()?,
|
||||
Key::Char('z') => self.run_subshell()?,
|
||||
Key::Char('c') => self.toggle_colums(),
|
||||
_ => { self.main_widget_mut()?.on_key(key)?; },
|
||||
}
|
||||
self.update_preview()?;
|
||||
if !self.columns.zoom_active { self.update_preview().log(); }
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
27
src/hbox.rs
27
src/hbox.rs
|
@ -9,6 +9,7 @@ pub struct HBox<T: Widget> {
|
|||
pub core: WidgetCore,
|
||||
pub widgets: Vec<T>,
|
||||
pub ratios: Option<Vec<usize>>,
|
||||
pub zoom_active: bool,
|
||||
pub active: Option<usize>,
|
||||
}
|
||||
|
||||
|
@ -18,6 +19,7 @@ impl<T> HBox<T> where T: Widget + PartialEq {
|
|||
HBox { core: core.clone(),
|
||||
widgets: vec![],
|
||||
ratios: None,
|
||||
zoom_active: false,
|
||||
active: None
|
||||
}
|
||||
}
|
||||
|
@ -27,6 +29,12 @@ impl<T> HBox<T> where T: Widget + PartialEq {
|
|||
let len = self.widgets.len();
|
||||
if len == 0 { return Ok(()) }
|
||||
|
||||
if self.zoom_active {
|
||||
let coords = self.core.coordinates.clone();
|
||||
self.active_widget_mut()?.set_coordinates(&coords).log();
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let coords: Vec<Coordinates> = self.calculate_coordinates()?;
|
||||
|
||||
|
||||
|
@ -50,6 +58,12 @@ impl<T> HBox<T> where T: Widget + PartialEq {
|
|||
self.widgets.insert(0, widget);
|
||||
}
|
||||
|
||||
pub fn toggle_zoom(&mut self) -> HResult<()> {
|
||||
self.clear().log();
|
||||
self.zoom_active = !self.zoom_active;
|
||||
self.resize_children()
|
||||
}
|
||||
|
||||
pub fn set_ratios(&mut self, ratios: Vec<usize>) {
|
||||
self.ratios = Some(ratios);
|
||||
}
|
||||
|
@ -140,6 +154,11 @@ impl<T> Widget for HBox<T> where T: Widget + PartialEq {
|
|||
}
|
||||
|
||||
fn refresh(&mut self) -> HResult<()> {
|
||||
if self.zoom_active {
|
||||
self.active_widget_mut()?.refresh().log();
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
self.resize_children().log();
|
||||
for child in &mut self.widgets {
|
||||
child.refresh().log();
|
||||
|
@ -148,13 +167,17 @@ impl<T> Widget for HBox<T> where T: Widget + PartialEq {
|
|||
}
|
||||
|
||||
fn get_drawlist(&self) -> HResult<String> {
|
||||
if self.zoom_active {
|
||||
return self.active_widget()?.get_drawlist();
|
||||
}
|
||||
|
||||
Ok(self.widgets.iter().map(|child| {
|
||||
child.get_drawlist().unwrap()
|
||||
child.get_drawlist().log_and().unwrap_or_else(|_| String::new())
|
||||
}).collect())
|
||||
}
|
||||
|
||||
fn on_event(&mut self, event: Event) -> HResult<()> {
|
||||
self.widgets.last_mut()?.on_event(event)?;
|
||||
self.active_widget_mut()?.on_event(event)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,6 +83,10 @@ impl<T: Send + 'static> WillBe<T> where {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn is_stale(&self) -> HResult<bool> {
|
||||
is_stale(&self.stale)
|
||||
}
|
||||
|
||||
pub fn take(&mut self) -> HResult<T> {
|
||||
self.check()?;
|
||||
Ok(self.thing.lock()?.take()?)
|
||||
|
@ -154,19 +158,27 @@ impl<T: Widget + Send + 'static> WillBeWidget<T> {
|
|||
self.willbe = willbe;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn set_stale(&mut self) -> HResult<()> {
|
||||
self.willbe.set_stale()
|
||||
}
|
||||
|
||||
pub fn is_stale(&self) -> HResult<bool> {
|
||||
self.willbe.is_stale()
|
||||
}
|
||||
|
||||
pub fn widget(&self) -> HResult<Arc<Mutex<Option<T>>>> {
|
||||
self.willbe.check()?;
|
||||
Ok(self.willbe.thing.clone())
|
||||
}
|
||||
|
||||
pub fn ready(&self) -> bool {
|
||||
match self.willbe.check() {
|
||||
Ok(_) => true,
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
|
||||
pub fn take(&mut self) -> HResult<T> {
|
||||
self.willbe.take()
|
||||
}
|
||||
|
@ -223,9 +235,11 @@ impl<T: Widget + Send + 'static> Widget for WillBeWidget<T> {
|
|||
let pos = crate::term::goto_xy(xpos, ypos);
|
||||
return Ok(clear + &pos + "...")
|
||||
}
|
||||
if is_stale(&self.willbe.stale)? {
|
||||
|
||||
if self.is_stale()? {
|
||||
return self.get_clearlist()
|
||||
}
|
||||
|
||||
let widget = self.widget()?;
|
||||
let widget = widget.lock()?;
|
||||
let widget = widget.as_ref()?;
|
||||
|
@ -282,6 +296,10 @@ impl Previewer {
|
|||
self.widget.set_coordinates(&coordinates).ok();
|
||||
}
|
||||
|
||||
pub fn set_stale(&mut self) -> HResult<()> {
|
||||
self.widget.set_stale()
|
||||
}
|
||||
|
||||
pub fn set_file(&mut self,
|
||||
file: &File,
|
||||
selection: Option<File>,
|
||||
|
|
Loading…
Reference in New Issue