summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/commands/command_line.rs4
-rw-r--r--src/commands/key_command.rs15
-rw-r--r--src/config/keymap/keymapping.rs3
3 files changed, 14 insertions, 8 deletions
diff --git a/src/commands/command_line.rs b/src/commands/command_line.rs
index 910364a..0c80aa2 100644
--- a/src/commands/command_line.rs
+++ b/src/commands/command_line.rs
@@ -1,3 +1,5 @@
+use std::str::FromStr;
+
use crate::commands::KeyCommand;
use crate::context::AppContext;
use crate::error::JoshutoResult;
@@ -21,7 +23,7 @@ pub fn readline(
if let Some(s) = user_input {
let trimmed = s.trim_start();
- let command = KeyCommand::parse_command(trimmed)?;
+ let command = KeyCommand::from_str(trimmed)?;
command.execute(context, backend)
} else {
Ok(())
diff --git a/src/commands/key_command.rs b/src/commands/key_command.rs
index b0deba1..556ac87 100644
--- a/src/commands/key_command.rs
+++ b/src/commands/key_command.rs
@@ -133,8 +133,12 @@ impl KeyCommand {
Self::TabSwitch(_) => "tab_switch",
}
}
+}
+
+impl std::str::FromStr for KeyCommand {
+ type Err = JoshutoError;
- pub fn parse_command(s: &str) -> JoshutoResult<Self> {
+ fn from_str(s: &str) -> Result<Self, Self::Err> {
if let Some(stripped) = s.strip_prefix(':') {
return Ok(Self::CommandLine(stripped.to_owned(), "".to_owned()));
}
@@ -216,14 +220,13 @@ impl KeyCommand {
if arg.is_empty() {
Err(JoshutoError::new(
JoshutoErrorKind::InvalidParameters,
- format!("{}: missing additional parameter", command),
+ format!("{}: no directory name given", command),
))
} else {
Ok(Self::NewDirectory(path::PathBuf::from(arg)))
}
}
"new_tab" => Ok(Self::NewTab),
-
"open" => Ok(Self::OpenFile),
"open_with" => match arg {
"" => Ok(Self::OpenFileWith(None)),
@@ -314,7 +317,7 @@ impl KeyCommand {
Ok(s) if !s.is_empty() => Ok(Self::ShellCommand(s)),
Ok(_) => Err(JoshutoError::new(
JoshutoErrorKind::InvalidParameters,
- format!("sort: args {}", arg),
+ format!("{}: No commands given", command),
)),
Err(e) => Err(JoshutoError::new(
JoshutoErrorKind::InvalidParameters,
@@ -328,7 +331,7 @@ impl KeyCommand {
Some(s) => Ok(Self::Sort(s)),
None => Err(JoshutoError::new(
JoshutoErrorKind::InvalidParameters,
- format!("sort: Unknown option {}", arg),
+ format!("{}: Unknown option '{}'", command, arg),
)),
},
},
@@ -342,7 +345,7 @@ impl KeyCommand {
"toggle_hidden" => Ok(Self::ToggleHiddenFiles),
inp => Err(JoshutoError::new(
JoshutoErrorKind::UnrecognizedCommand,
- format!("Unknown command: {}", inp),
+ format!("Unrecognized command '{}'", inp),
)),
}
}
diff --git a/src/config/keymap/keymapping.rs b/src/config/keymap/keymapping.rs
index 6ceb4a4..c86e4e4 100644
--- a/src/config/keymap/keymapping.rs
+++ b/src/config/keymap/keymapping.rs
@@ -1,6 +1,7 @@
use serde_derive::Deserialize;
use std::collections::{hash_map::Entry, HashMap};
+use std::str::FromStr;
#[cfg(feature = "mouse")]
use termion::event::MouseEvent;
@@ -27,7 +28,7 @@ impl Flattenable<AppKeyMapping> for RawAppKeyMapping {
fn flatten(self) -> AppKeyMapping {
let mut keymaps = AppKeyMapping::new();
for m in self.mapcommand {
- match KeyCommand::parse_command(m.command.as_str()) {
+ match KeyCommand::from_str(m.command.as_str()) {
Ok(command) => {
let events: Vec<Event> = m
.keys