From 8221140756aa3f41c48da13e0ad03863b77de1fa Mon Sep 17 00:00:00 2001 From: Arijit Basu Date: Wed, 3 Mar 2021 17:16:13 +0530 Subject: [PATCH] Refresh after running command --- Cargo.lock | 2 +- Cargo.toml | 2 +- README.md | 2 ++ benches/navigation.rs | 8 ++++---- src/app.rs | 35 +++++++++++++++++++++++++++-------- src/config.rs | 13 +++++++------ src/main.rs | 1 + 7 files changed, 43 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d41cc80..c082257 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1133,7 +1133,7 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "xplr" -version = "0.1.7" +version = "0.1.8" dependencies = [ "criterion", "crossterm", diff --git a/Cargo.toml b/Cargo.toml index 2f7959a..4935b8a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "xplr" -version = "0.1.7" # Update app.rs +version = "0.1.8" # Update app.rs authors = ["Arijit Basu "] edition = "2018" description = "An experimental, minimal, configurable TUI file explorer, stealing ideas from nnn and fzf." diff --git a/README.md b/README.md index 7d1233c..d4d5ece 100644 --- a/README.md +++ b/README.md @@ -49,5 +49,7 @@ TODO research - [ ] Research saner configuration formats. - [ ] Research saner key binding options. - [ ] Research how to go beyond filesystem and explore any tree-like structure. +- [ ] Research ways to make it faster (load and run). +- [ ] Research ways to implement a plugin system. - [ ] CLI options and help menu. - [ ] Go beyond research and implement things. diff --git a/benches/navigation.rs b/benches/navigation.rs index 9d8aff7..8fd5b3b 100644 --- a/benches/navigation.rs +++ b/benches/navigation.rs @@ -16,14 +16,14 @@ fn criterion_benchmark(c: &mut Criterion) { c.bench_function("focus next item", |b| { b.iter(|| { app.clone() - .handle(&config::Action::Global(config::GlobalAction::FocusNextItem)) + .handle(&config::Action::Global(config::GlobalAction::FocusNext)) }) }); c.bench_function("focus previous item", |b| { b.iter(|| { app.clone().handle(&config::Action::Global( - config::GlobalAction::FocusPreviousItem, + config::GlobalAction::FocusPrevious, )) }) }); @@ -31,14 +31,14 @@ fn criterion_benchmark(c: &mut Criterion) { c.bench_function("focus first item", |b| { b.iter(|| { app.clone() - .handle(&config::Action::Global(config::GlobalAction::FocusFirstItem)) + .handle(&config::Action::Global(config::GlobalAction::FocusFirst)) }) }); c.bench_function("focus last item", |b| { b.iter(|| { app.clone() - .handle(&config::Action::Global(config::GlobalAction::FocusLastItem)) + .handle(&config::Action::Global(config::GlobalAction::FocusLast)) }) }); } diff --git a/src/app.rs b/src/app.rs index 34ddd84..f767d2c 100644 --- a/src/app.rs +++ b/src/app.rs @@ -14,7 +14,7 @@ use std::io::BufReader; use std::path::Path; use std::path::PathBuf; -pub const VERSION: &str = "v0.1.7"; // Update Cargo.toml +pub const VERSION: &str = "v0.1.8"; // Update Cargo.toml pub const UNSUPPORTED_STR: &str = "???"; pub const TOTAL_ROWS: usize = 50; @@ -301,15 +301,33 @@ impl App { }) } + pub fn refresh(self) -> Result { + Self::new( + &self.config, + &self.directory_buffer.pwd, + &self.saved_buffers, + &self.selected_paths, + self.mode, + self.show_hidden, + self.directory_buffer.focus, + ) + } + pub fn exit_submode(self) -> Result { - let mut app = self; - let mode = match app.mode { + let mode = match self.mode { Mode::ExploreSubmode(_) => Mode::Explore, Mode::SelectSubmode(_) => Mode::Select, m => m, }; - app.mode = mode; - Ok(app) + Self::new( + &self.config, + &self.directory_buffer.pwd, + &self.saved_buffers, + &self.selected_paths, + mode, + self.show_hidden, + self.directory_buffer.focus, + ) } pub fn toggle_hidden(self) -> Result { @@ -765,9 +783,10 @@ pub fn create() -> Result { }; if !config.version.eq(VERSION) { - return Err(Error::IncompatibleVersion( - format!("Config file {} is outdated", config_file.to_string_lossy()), - )); + return Err(Error::IncompatibleVersion(format!( + "Config file {} is outdated", + config_file.to_string_lossy() + ))); } let root = Path::new("/"); diff --git a/src/config.rs b/src/config.rs index f3f6f6f..3277004 100644 --- a/src/config.rs +++ b/src/config.rs @@ -230,9 +230,10 @@ impl Default for KeyBindings { help: edit actions: - Call: - command: vim + command: bash args: - - "{{shellescape relativePath}}" + - -c + - FILE="{{shellescape relativePath}}" && "${EDITOR:-vim}" "${FILE:?}" forward-slash: help: search actions: @@ -472,11 +473,11 @@ impl Default for GeneralConfig { - format: "╰─" normal_ui: - prefix: " " - suffix: " " + prefix: " " + suffix: "" focused_ui: - prefix: "▸ [" + prefix: "▸[" suffix: "]" style: fg: Blue @@ -486,7 +487,7 @@ impl Default for GeneralConfig { bits: 0 selected_ui: - prefix: " {" + prefix: " {" suffix: "}" style: fg: LightGreen diff --git a/src/main.rs b/src/main.rs index 8e6bf9d..2044dbe 100644 --- a/src/main.rs +++ b/src/main.rs @@ -87,6 +87,7 @@ fn main() -> Result<(), Error> { let stdout = AlternateScreen::from(stdout); let backend = CrosstermBackend::new(stdout); terminal = Terminal::new(backend)?; + a = a.refresh()?; terminal.draw(|f| { ui::draw(&a, &hb, f, &mut table_state, &mut list_state) })?;