summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Oram <dev@mitmaro.ca>2019-06-22 18:16:16 -0230
committerGitHub <noreply@github.com>2019-06-22 18:16:16 -0230
commit669f865a1d28be02f0cef10410492721888208af (patch)
treeca9ec78f864a7940fdb08d1046a6e9af1395351c
parentd285279510c5e3a02b641c7c5d0f6f40a7cf8a69 (diff)
parentb0d76a1badc50506989622d5a3e8daf7883d254c (diff)
Merge pull request #143 from MitMaro/tim/confirm-rebase-to-module
Move confirm rebase to module
-rw-r--r--src/application.rs40
-rw-r--r--src/confirm_rebase/confirm_rebase.rs38
-rw-r--r--src/confirm_rebase/mod.rs4
-rw-r--r--src/main.rs1
4 files changed, 54 insertions, 29 deletions
diff --git a/src/application.rs b/src/application.rs
index a65f1ee..f012ea3 100644
--- a/src/application.rs
+++ b/src/application.rs
@@ -3,6 +3,7 @@ use crate::git_interactive::GitInteractive;
use crate::config::Config;
use crate::confirm_abort::ConfirmAbort;
+use crate::confirm_rebase::ConfirmRebase;
use crate::constants::{LIST_HELP_LINES, VISUAL_MODE_HELP_LINES};
use crate::edit::Edit;
use crate::input::{Input, InputHandler};
@@ -25,6 +26,7 @@ use std::process::ExitStatus as ProcessExitStatus;
pub struct Application<'a> {
config: &'a Config,
confirm_abort: ConfirmAbort,
+ confirm_rebase: ConfirmRebase,
edit: Edit,
git_interactive: GitInteractive,
input_handler: &'a InputHandler<'a>,
@@ -43,6 +45,7 @@ impl<'a> Application<'a> {
Self {
config,
confirm_abort: ConfirmAbort::new(),
+ confirm_rebase: ConfirmRebase::new(),
edit: Edit::new(),
git_interactive,
input_handler,
@@ -58,7 +61,7 @@ impl<'a> Application<'a> {
pub fn activate(&mut self, state: State) {
match state {
State::ConfirmAbort => self.confirm_abort.activate(state, &self.git_interactive),
- State::ConfirmRebase => {},
+ State::ConfirmRebase => self.confirm_rebase.activate(state, &self.git_interactive),
State::Edit => self.edit.activate(state, &self.git_interactive),
State::Error { .. } => {},
State::Exiting => {},
@@ -76,7 +79,7 @@ impl<'a> Application<'a> {
pub fn deactivate(&mut self, state: State) {
match state {
State::ConfirmAbort => self.confirm_abort.deactivate(),
- State::ConfirmRebase => {},
+ State::ConfirmRebase => self.confirm_rebase.deactivate(),
State::Edit => self.edit.deactivate(),
State::Error { .. } => {},
State::Exiting => {},
@@ -94,7 +97,7 @@ impl<'a> Application<'a> {
pub fn process(&mut self, state: State) -> ProcessResult {
match state {
State::ConfirmAbort => self.confirm_abort.process(&mut self.git_interactive),
- State::ConfirmRebase => ProcessResult::new(),
+ State::ConfirmRebase => self.confirm_rebase.process(&mut self.git_interactive),
State::Edit => self.edit.process(&mut self.git_interactive),
State::Error { .. } => ProcessResult::new(),
State::Exiting => ProcessResult::new(),
@@ -166,7 +169,7 @@ impl<'a> Application<'a> {
self.view.clear();
match state {
State::ConfirmAbort => self.confirm_abort.render(&self.view, &self.git_interactive),
- State::ConfirmRebase => self.draw_confirm_rebase(),
+ State::ConfirmRebase => self.confirm_rebase.render(&self.view, &self.git_interactive),
State::Edit => self.edit.render(&self.view, &self.git_interactive),
State::Error { message, .. } => self.draw_error(message.as_str()),
State::Exiting => self.draw_exiting(),
@@ -182,10 +185,6 @@ impl<'a> Application<'a> {
self.view.refresh()
}
- fn draw_confirm_rebase(&self) {
- self.view.draw_confirm("Are you sure you want to rebase");
- }
-
fn draw_error(&self, error_message: &str) {
self.view.draw_error(error_message);
}
@@ -226,17 +225,16 @@ impl<'a> Application<'a> {
self.input_handler.get_input()
}
- pub fn get_confirm(&mut self) -> Input {
- self.input_handler.get_confirm()
- }
-
pub fn handle_input(&mut self, state: State) -> HandleInputResult {
match state {
State::ConfirmAbort => {
self.confirm_abort
.handle_input(self.input_handler, &mut self.git_interactive)
},
- State::ConfirmRebase => self.handle_confirm_rebase_input(),
+ State::ConfirmRebase => {
+ self.confirm_rebase
+ .handle_input(self.input_handler, &mut self.git_interactive)
+ },
State::Edit => self.edit.handle_input(&self.input_handler, &mut self.git_interactive),
State::Error { return_state, .. } => self.handle_error_input(return_state.borrow()),
State::Exiting => HandleInputResult::new(Input::Other),
@@ -316,22 +314,6 @@ impl<'a> Application<'a> {
result.build()
}
- fn handle_confirm_rebase_input(&mut self) -> HandleInputResult {
- let input = self.get_confirm();
- let mut result = HandleInputResultBuilder::new(input);
- match input {
- Input::Yes => {
- result = result.exit_status(ExitStatus::Good).state(State::Exiting);
- },
- Input::No => {
- result = result.state(State::List);
- },
- _ => {},
- }
-
- result.build()
- }
-
pub fn handle_error_input(&mut self, return_state: &State) -> HandleInputResult {
let input = self.get_input();
let mut result = HandleInputResultBuilder::new(input);
diff --git a/src/confirm_rebase/confirm_rebase.rs b/src/confirm_rebase/confirm_rebase.rs
new file mode 100644
index 0000000..1189ff2
--- /dev/null
+++ b/src/confirm_rebase/confirm_rebase.rs
@@ -0,0 +1,38 @@
+use crate::git_interactive::GitInteractive;
+use crate::input::{Input, InputHandler};
+use crate::process::{ExitStatus, HandleInputResult, HandleInputResultBuilder, ProcessModule, State};
+use crate::view::View;
+
+pub struct ConfirmRebase {}
+
+impl ProcessModule for ConfirmRebase {
+ fn handle_input(
+ &mut self,
+ input_handler: &InputHandler,
+ _git_interactive: &mut GitInteractive,
+ ) -> HandleInputResult
+ {
+ let input = input_handler.get_confirm();
+ let mut result = HandleInputResultBuilder::new(input);
+ match input {
+ Input::Yes => {
+ result = result.exit_status(ExitStatus::Good).state(State::Exiting);
+ },
+ Input::No => {
+ result = result.state(State::List);
+ },
+ _ => {},
+ }
+ result.build()
+ }
+
+ fn render(&self, view: &View, _git_interactive: &GitInteractive) {
+ view.draw_confirm("Are you sure you want to rebase");
+ }
+}
+
+impl ConfirmRebase {
+ pub fn new() -> Self {
+ Self {}
+ }
+}
diff --git a/src/confirm_rebase/mod.rs b/src/confirm_rebase/mod.rs
new file mode 100644
index 0000000..d737016
--- /dev/null
+++ b/src/confirm_rebase/mod.rs
@@ -0,0 +1,4 @@
+#[allow(clippy::module_inception)]
+mod confirm_rebase;
+
+pub use self::confirm_rebase::ConfirmRebase;
diff --git a/src/main.rs b/src/main.rs
index a7bcc7c..a4983d3 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -8,6 +8,7 @@ mod color;
mod commit;
mod config;
mod confirm_abort;
+mod confirm_rebase;
mod constants;
mod edit;
mod git_interactive;