Refresh after running command

pull/3/head
Arijit Basu 3 years ago
parent 044b7860a1
commit 8221140756
No known key found for this signature in database
GPG Key ID: 7D7BF809E7378863

2
Cargo.lock generated

@ -1133,7 +1133,7 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]] [[package]]
name = "xplr" name = "xplr"
version = "0.1.7" version = "0.1.8"
dependencies = [ dependencies = [
"criterion", "criterion",
"crossterm", "crossterm",

@ -1,6 +1,6 @@
[package] [package]
name = "xplr" name = "xplr"
version = "0.1.7" # Update app.rs version = "0.1.8" # Update app.rs
authors = ["Arijit Basu <sayanarijit@gmail.com>"] authors = ["Arijit Basu <sayanarijit@gmail.com>"]
edition = "2018" edition = "2018"
description = "An experimental, minimal, configurable TUI file explorer, stealing ideas from nnn and fzf." description = "An experimental, minimal, configurable TUI file explorer, stealing ideas from nnn and fzf."

@ -49,5 +49,7 @@ TODO research
- [ ] Research saner configuration formats. - [ ] Research saner configuration formats.
- [ ] Research saner key binding options. - [ ] Research saner key binding options.
- [ ] Research how to go beyond filesystem and explore any tree-like structure. - [ ] 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. - [ ] CLI options and help menu.
- [ ] Go beyond research and implement things. - [ ] Go beyond research and implement things.

@ -16,14 +16,14 @@ fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("focus next item", |b| { c.bench_function("focus next item", |b| {
b.iter(|| { b.iter(|| {
app.clone() app.clone()
.handle(&config::Action::Global(config::GlobalAction::FocusNextItem)) .handle(&config::Action::Global(config::GlobalAction::FocusNext))
}) })
}); });
c.bench_function("focus previous item", |b| { c.bench_function("focus previous item", |b| {
b.iter(|| { b.iter(|| {
app.clone().handle(&config::Action::Global( 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| { c.bench_function("focus first item", |b| {
b.iter(|| { b.iter(|| {
app.clone() app.clone()
.handle(&config::Action::Global(config::GlobalAction::FocusFirstItem)) .handle(&config::Action::Global(config::GlobalAction::FocusFirst))
}) })
}); });
c.bench_function("focus last item", |b| { c.bench_function("focus last item", |b| {
b.iter(|| { b.iter(|| {
app.clone() app.clone()
.handle(&config::Action::Global(config::GlobalAction::FocusLastItem)) .handle(&config::Action::Global(config::GlobalAction::FocusLast))
}) })
}); });
} }

@ -14,7 +14,7 @@ use std::io::BufReader;
use std::path::Path; use std::path::Path;
use std::path::PathBuf; 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 UNSUPPORTED_STR: &str = "???";
pub const TOTAL_ROWS: usize = 50; pub const TOTAL_ROWS: usize = 50;
@ -301,15 +301,33 @@ impl App {
}) })
} }
pub fn refresh(self) -> Result<Self, Error> {
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<Self, Error> { pub fn exit_submode(self) -> Result<Self, Error> {
let mut app = self; let mode = match self.mode {
let mode = match app.mode {
Mode::ExploreSubmode(_) => Mode::Explore, Mode::ExploreSubmode(_) => Mode::Explore,
Mode::SelectSubmode(_) => Mode::Select, Mode::SelectSubmode(_) => Mode::Select,
m => m, m => m,
}; };
app.mode = mode; Self::new(
Ok(app) &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<Self, Error> { pub fn toggle_hidden(self) -> Result<Self, Error> {
@ -765,9 +783,10 @@ pub fn create() -> Result<App, Error> {
}; };
if !config.version.eq(VERSION) { if !config.version.eq(VERSION) {
return Err(Error::IncompatibleVersion( return Err(Error::IncompatibleVersion(format!(
format!("Config file {} is outdated", config_file.to_string_lossy()), "Config file {} is outdated",
)); config_file.to_string_lossy()
)));
} }
let root = Path::new("/"); let root = Path::new("/");

@ -230,9 +230,10 @@ impl Default for KeyBindings {
help: edit help: edit
actions: actions:
- Call: - Call:
command: vim command: bash
args: args:
- "{{shellescape relativePath}}" - -c
- FILE="{{shellescape relativePath}}" && "${EDITOR:-vim}" "${FILE:?}"
forward-slash: forward-slash:
help: search help: search
actions: actions:
@ -472,11 +473,11 @@ impl Default for GeneralConfig {
- format: "╰─" - format: "╰─"
normal_ui: normal_ui:
prefix: " " prefix: " "
suffix: " " suffix: ""
focused_ui: focused_ui:
prefix: "▸ [" prefix: "▸["
suffix: "]" suffix: "]"
style: style:
fg: Blue fg: Blue
@ -486,7 +487,7 @@ impl Default for GeneralConfig {
bits: 0 bits: 0
selected_ui: selected_ui:
prefix: " {" prefix: " {"
suffix: "}" suffix: "}"
style: style:
fg: LightGreen fg: LightGreen

@ -87,6 +87,7 @@ fn main() -> Result<(), Error> {
let stdout = AlternateScreen::from(stdout); let stdout = AlternateScreen::from(stdout);
let backend = CrosstermBackend::new(stdout); let backend = CrosstermBackend::new(stdout);
terminal = Terminal::new(backend)?; terminal = Terminal::new(backend)?;
a = a.refresh()?;
terminal.draw(|f| { terminal.draw(|f| {
ui::draw(&a, &hb, f, &mut table_state, &mut list_state) ui::draw(&a, &hb, f, &mut table_state, &mut list_state)
})?; })?;

Loading…
Cancel
Save