feat: Support entry removing
Signed-off-by: Awiteb <a@4rs.nl>
This commit is contained in:
parent
fa001be60c
commit
642e0c3c26
5 changed files with 29 additions and 0 deletions
|
@ -59,6 +59,7 @@ The key bindings are configurable. For the set of configurable keys and key comb
|
|||
| `right arrow` | `--keybinding.expand_dir=left` | expand an entry directory |
|
||||
| `r` | `--keybinding.rename_mode=r` | Enter rename mode (To exit rename mode press `quit` keybinding) |
|
||||
| `ctrl+r` | `--keybinding.reload=r` | collapse all directories and reload root directory |
|
||||
| `d` | `--keybinding.remove=d` | remove a file/directory |
|
||||
| `return` | `--keybinding.file_action=return` | perform configured file action |
|
||||
| `esc` | `--keybinding.quit=q` | quit |
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ mod file_action;
|
|||
mod modes;
|
||||
mod quit;
|
||||
mod reload;
|
||||
mod remove;
|
||||
mod rename;
|
||||
|
||||
impl<W: Write> EventQueue<W> {
|
||||
|
@ -32,6 +33,7 @@ impl<W: Write> EventQueue<W> {
|
|||
(Mode::Normal, k) if k == Key::from(&ck.quit) => self.do_quit(),
|
||||
(Mode::Normal, k) if k == Key::from(&ck.reload) => self.do_reload(),
|
||||
(Mode::Normal, k) if k == Key::from(&ck.rename_mode) => self.do_enter_rename_mode(),
|
||||
(Mode::Normal, k) if k == Key::from(&ck.remove) => self.do_remove_entry(),
|
||||
(Mode::Rename(..), k) if k == Key::from(&ck.quit) => self.do_enter_normal_mode(),
|
||||
(Mode::Rename(new_name), k) if k == Key::from("return") => {
|
||||
if !new_name.chars().all(char::is_whitespace) {
|
||||
|
|
19
src/controller/key_event_matcher/remove.rs
Normal file
19
src/controller/key_event_matcher/remove.rs
Normal file
|
@ -0,0 +1,19 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
// Copyright (c) 2024 Awiteb <a@4rs.nl>
|
||||
|
||||
use std::{fs, io::Write};
|
||||
|
||||
use crate::controller::EventQueue;
|
||||
|
||||
impl<W: Write> EventQueue<W> {
|
||||
/// Remove the current entry
|
||||
pub fn do_remove_entry(&mut self) -> Option<()> {
|
||||
if self.pager.current_entry.is_dir() {
|
||||
let _ = fs::remove_dir_all(&self.pager.current_entry);
|
||||
} else {
|
||||
let _ = fs::remove_file(&self.pager.current_entry);
|
||||
}
|
||||
self.do_reload();
|
||||
Some(())
|
||||
}
|
||||
}
|
|
@ -22,6 +22,8 @@ pub struct Keybinding {
|
|||
pub reload: String,
|
||||
#[serde(default = "Keybinding::default_rename_mode")]
|
||||
pub rename_mode: String,
|
||||
#[serde(default = "Keybinding::default_remove")]
|
||||
pub remove: String,
|
||||
}
|
||||
|
||||
impl Default for Keybinding {
|
||||
|
@ -35,6 +37,7 @@ impl Default for Keybinding {
|
|||
file_action: Self::default_file_action(),
|
||||
reload: Self::default_reload(),
|
||||
rename_mode: Self::default_rename_mode(),
|
||||
remove: Self::default_remove(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -64,4 +67,7 @@ impl Keybinding {
|
|||
fn default_rename_mode() -> String {
|
||||
String::from("r")
|
||||
}
|
||||
fn default_remove() -> String {
|
||||
String::from("d")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,6 +51,7 @@ quit = "esc"
|
|||
reload = "ctrl+r"
|
||||
skip_up = "ctrl+up"
|
||||
skip_down = "ctrl+down"
|
||||
remove = "d"
|
||||
|
||||
[setup]
|
||||
# the working directory used when starting
|
||||
|
|
Loading…
Reference in a new issue