feat: Support entry removing

Signed-off-by: Awiteb <a@4rs.nl>
This commit is contained in:
Awiteb 2024-12-27 19:42:29 +00:00
parent fa001be60c
commit 642e0c3c26
Signed by: awiteb
GPG key ID: 3F6B55640AA6682F
5 changed files with 29 additions and 0 deletions

View file

@ -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 |

View file

@ -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) {

View 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(())
}
}

View file

@ -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")
}
}

View file

@ -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