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