summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorqkzk <qu3nt1n@gmail.com>2023-02-16 20:27:18 +0100
committerqkzk <qu3nt1n@gmail.com>2023-02-16 20:27:18 +0100
commite7662cfffe9825fdfd10da2e5ad4e671b6a82b5c (patch)
tree4b9d292e72b6797b93926fd04bf242e2e53606ba
parent2f3b7cdbfb1e23a9f1c4642946e36e82c6ae2c94 (diff)
command mode. use : to type and complete an existing command
-rw-r--r--development.md2
-rw-r--r--src/action_map.rs6
-rw-r--r--src/completion.rs18
-rw-r--r--src/event_exec.rs17
-rw-r--r--src/help.rs1
-rw-r--r--src/keybindings.rs1
-rw-r--r--src/mode.rs1
-rw-r--r--src/tab.rs3
8 files changed, 47 insertions, 2 deletions
diff --git a/development.md b/development.md
index ca8220c0..c28359d3 100644
--- a/development.md
+++ b/development.md
@@ -382,6 +382,8 @@ New view: Tree ! Toggle with 't', fold with 'z'. Navigate normally.
- [x] navigate in marks
- [x] compress flagged files: method is chosen from a list of compression method.
- [x] decompress any archive we can create
+ - [x] command mode with :
+ some commands does nothing :(
- [ ] Version 0.1.50 : safety & memory usage
diff --git a/src/action_map.rs b/src/action_map.rs
index 5800f3a6..7f8b507a 100644
--- a/src/action_map.rs
+++ b/src/action_map.rs
@@ -1,4 +1,4 @@
-use strum_macros::{Display, EnumString};
+use strum_macros::{Display, EnumIter, EnumString};
use crate::config::Colors;
use crate::event_exec::EventExec;
@@ -9,7 +9,7 @@ use crate::status::Status;
/// All those actions are mapped to a key and this enum
/// makes the junction between received Key events and
/// actions in the application.
-#[derive(Clone, Debug, Display, EnumString)]
+#[derive(Clone, Debug, Display, EnumString, EnumIter)]
pub enum ActionMap {
Back,
BackTab,
@@ -17,6 +17,7 @@ pub enum ActionMap {
Bulkrename,
Chmod,
ClearFlags,
+ Command,
Compress,
CopyFilename,
CopyFilepath,
@@ -94,6 +95,7 @@ impl ActionMap {
ActionMap::Bulkrename => EventExec::event_bulkrename(status),
ActionMap::Chmod => EventExec::event_chmod(status),
ActionMap::ClearFlags => EventExec::event_clear_flags(status),
+ ActionMap::Command => EventExec::event_command(current_tab),
ActionMap::Compress => EventExec::event_compress(status),
ActionMap::CopyFilename => EventExec::event_copy_filename(status),
ActionMap::CopyFilepath => EventExec::event_copy_filepath(status),
diff --git a/src/completion.rs b/src/completion.rs
index 6894bb85..a4733ae5 100644
--- a/src/completion.rs
+++ b/src/completion.rs
@@ -1,5 +1,7 @@
use std::fs::{self, ReadDir};
+use strum::IntoEnumIterator;
+
use crate::fileinfo::PathContent;
use crate::fm_error::FmResult;
use crate::mode::Mode;
@@ -17,6 +19,8 @@ pub enum InputCompleted {
Search,
/// Complete an executable name from $PATH
Exec,
+ /// Command
+ Command,
}
/// Holds a `Vec<String>` of possible completions and an `usize` index
@@ -158,6 +162,20 @@ impl Completion {
Ok(())
}
+ pub fn command(&mut self, input_string: &str) -> FmResult<()> {
+ let proposals = crate::action_map::ActionMap::iter()
+ .filter(|command| {
+ command
+ .to_string()
+ .to_lowercase()
+ .contains(&input_string.to_lowercase())
+ })
+ .map(|command| command.to_string())
+ .collect();
+ self.update(proposals);
+ Ok(())
+ }
+
fn find_completion_in_path(
path: std::path::PathBuf,
input_string: &str,
diff --git a/src/event_exec.rs b/src/event_exec.rs
index 7aaeece7..e29a7b28 100644
--- a/src/event_exec.rs
+++ b/src/event_exec.rs
@@ -2,11 +2,13 @@ use std::borrow::Borrow;
use std::cmp::min;
use std::fs;
use std::path;
+use std::str::FromStr;
use copypasta::{ClipboardContext, ClipboardProvider};
use log::info;
use sysinfo::SystemExt;
+use crate::action_map::ActionMap;
use crate::bulkrename::Bulkrename;
use crate::completion::InputCompleted;
use crate::config::Colors;
@@ -1337,6 +1339,9 @@ impl EventExec {
EventExec::exec_search(status, colors)?
}
Mode::InputCompleted(InputCompleted::Goto) => EventExec::exec_goto(status.selected())?,
+ Mode::InputCompleted(InputCompleted::Command) => {
+ EventExec::exec_command(status, colors)?
+ }
Mode::Normal => EventExec::exec_file(status)?,
Mode::Tree => EventExec::exec_tree(status, colors)?,
Mode::NeedConfirmation(_)
@@ -1756,6 +1761,18 @@ impl EventExec {
pub fn event_compression_next(status: &mut Status) {
status.compression.next()
}
+
+ pub fn event_command(tab: &mut Tab) -> FmResult<()> {
+ tab.set_mode(Mode::InputCompleted(InputCompleted::Command));
+ tab.completion.reset();
+ Ok(())
+ }
+
+ pub fn exec_command(status: &mut Status, colors: &Colors) -> FmResult<()> {
+ let command_str = status.selected_non_mut().completion.current_proposition();
+ let Ok(command) = ActionMap::from_str(command_str) else { return Ok(()) };
+ command.matcher(status, colors)
+ }
}
fn string_to_path(path_string: &str) -> FmResult<path::PathBuf> {
diff --git a/src/help.rs b/src/help.rs
index 21f2dea6..d8430b61 100644
--- a/src/help.rs
+++ b/src/help.rs
@@ -83,6 +83,7 @@ Navigate as usual. Most actions works as in 'normal' view.
{EncryptedDrive}: ENCRYPTED DRIVE
(m: open & mount, u: unmount & close)
{Search}: SEARCH
+{Command}: COMMAND
{Filter}: FILTER
(by name \"n name\", by ext \"e ext\", only directories d or all for reset)
{Enter}: Execute mode then NORMAL
diff --git a/src/keybindings.rs b/src/keybindings.rs
index c2cbc4a5..054f90c2 100644
--- a/src/keybindings.rs
+++ b/src/keybindings.rs
@@ -44,6 +44,7 @@ impl Bindings {
(Key::Char('\''), ActionMap::MarksJump),
(Key::Char('-'), ActionMap::Back),
(Key::Char('~'), ActionMap::Home),
+ (Key::Char(':'), ActionMap::Command),
(Key::Char('B'), ActionMap::Bulkrename),
(Key::Char('C'), ActionMap::Compress),
(Key::Char('D'), ActionMap::ToggleDualPane),
diff --git a/src/mode.rs b/src/mode.rs
index 10e2e84d..cb1ec30d 100644
--- a/src/mode.rs
+++ b/src/mode.rs
@@ -142,6 +142,7 @@ impl fmt::Display for Mode {
Mode::InputCompleted(InputCompleted::Goto) => write!(f, "Goto : "),
Mode::InputCompleted(InputCompleted::Search) => write!(f, "Search: "),
Mode::InputCompleted(InputCompleted::Nothing) => write!(f, "Nothing: "),
+ Mode::InputCompleted(InputCompleted::Command) => write!(f, "Command: "),
Mode::Navigate(Navigate::Jump) => write!(f, "Jump : "),
Mode::Navigate(Navigate::History) => write!(f, "History :"),
Mode::Navigate(Navigate::Shortcut) => write!(f, "Shortcut :"),
diff --git a/src/tab.rs b/src/tab.rs
index 4f4b238e..293c5cf0 100644
--- a/src/tab.rs
+++ b/src/tab.rs
@@ -119,6 +119,9 @@ impl Tab {
self.completion
.search_from_tree(&self.input.string(), &self.directory.content)
}
+ Mode::InputCompleted(InputCompleted::Command) => {
+ self.completion.command(&self.input.string())
+ }
_ => Ok(()),
}
}