summaryrefslogtreecommitdiffstats
path: root/src/commands/command_line.rs
diff options
context:
space:
mode:
authorJiayi Zhao <jeff.no.zhao@gmail.com>2019-06-29 22:19:47 -0400
committerJiayi Zhao <jeff.no.zhao@gmail.com>2019-06-29 22:23:31 -0400
commit65f0f33a564d91bd8126ce684c02f245e5ea9a1f (patch)
treebc9bb5d877cee131dc7870c5f9f5d0c71898efbd /src/commands/command_line.rs
parent58f6428e2aead58b7f930008b294ce56df59e3cb (diff)
rework error system
- JoshutoErrorKind now envelops all possible errors by Joshuto - JoshutoError behaves like std::io::Error - add JoshutoResult
Diffstat (limited to 'src/commands/command_line.rs')
-rw-r--r--src/commands/command_line.rs24
1 files changed, 5 insertions, 19 deletions
diff --git a/src/commands/command_line.rs b/src/commands/command_line.rs
index 036ad55..585ae23 100644
--- a/src/commands/command_line.rs
+++ b/src/commands/command_line.rs
@@ -1,6 +1,6 @@
use crate::commands::{self, JoshutoCommand, JoshutoRunnable};
use crate::context::JoshutoContext;
-use crate::error::JoshutoError;
+use crate::error::JoshutoResult;
use crate::textfield::JoshutoTextField;
use crate::ui;
use crate::window::JoshutoView;
@@ -19,11 +19,7 @@ impl CommandLine {
"console"
}
- pub fn readline(
- &self,
- context: &mut JoshutoContext,
- view: &JoshutoView,
- ) -> Result<(), JoshutoError> {
+ pub fn readline(&self, context: &mut JoshutoContext, view: &JoshutoView) -> JoshutoResult<()> {
const PROMPT: &str = ":";
let (term_rows, term_cols) = ui::getmaxyx();
let user_input: Option<String> = {
@@ -49,15 +45,9 @@ impl CommandLine {
Ok(wexp) => wexp.iter().collect(),
Err(_) => Vec::new(),
};
- match commands::from_args(command, &args) {
- Ok(s) => s.execute(context, view),
- Err(e) => Err(JoshutoError::Keymap(e)),
- }
+ commands::from_args(command, &args)?.execute(context, view)
}
- None => match commands::from_args(trimmed, &Vec::new()) {
- Ok(s) => s.execute(context, view),
- Err(e) => Err(JoshutoError::Keymap(e)),
- },
+ None => commands::from_args(trimmed, &Vec::new())?.execute(context, view),
}
} else {
Ok(())
@@ -74,11 +64,7 @@ impl std::fmt::Display for CommandLine {
}
impl JoshutoRunnable for CommandLine {
- fn execute(
- &self,
- context: &mut JoshutoContext,
- view: &JoshutoView,
- ) -> Result<(), JoshutoError> {
+ fn execute(&self, context: &mut JoshutoContext, view: &JoshutoView) -> JoshutoResult<()> {
let res = self.readline(context, view);
ncurses::doupdate();
res