diff options
Diffstat (limited to 'src')
64 files changed, 2240 insertions, 2274 deletions
@@ -1,7 +1,7 @@ use crate::constants::{NAME, VERSION}; use clap::App; -pub fn build_cli() -> App<'static, 'static> { +pub(crate) fn build_cli() -> App<'static, 'static> { App::new(NAME) .version(VERSION) .about("Full feature terminal based sequence editor for git interactive rebase.") diff --git a/src/commit/commit.rs b/src/commit/commit.rs deleted file mode 100644 index 4da3fb2..0000000 --- a/src/commit/commit.rs +++ /dev/null @@ -1,70 +0,0 @@ -use crate::commit::file_stat::FileStat; -use crate::commit::user::User; -use crate::commit::utils::load_commit_state; -use chrono::{DateTime, Local}; - -#[derive(Debug, PartialEq)] -pub struct Commit { - author: User, - body: Option<String>, - committer: User, - date: DateTime<Local>, - file_stats: Option<Vec<FileStat>>, - hash: String, -} - -impl Commit { - pub fn new( - hash: String, - author: User, - committer: User, - date: DateTime<Local>, - file_stats: Option<Vec<FileStat>>, - body: Option<String>, - ) -> Self - { - Commit { - author, - body, - committer, - date, - file_stats, - hash, - } - } - - pub fn from_commit_hash(hash: &str) -> Result<Self, String> { - load_commit_state(hash).map_err(|e| String::from(e.message())) - } - - pub fn get_author(&self) -> &User { - &self.author - } - - pub fn get_committer(&self) -> &User { - &self.committer - } - - pub fn get_date(&self) -> &DateTime<Local> { - &self.date - } - - pub fn get_hash(&self) -> &String { - &self.hash - } - - pub fn get_body(&self) -> &Option<String> { - &self.body - } - - pub fn get_file_stats(&self) -> &Option<Vec<FileStat>> { - &self.file_stats - } - - pub fn get_file_stats_length(&self) -> usize { - match &self.file_stats { - Some(s) => s.len(), - None => 0, - } - } -} diff --git a/src/commit/file_stat.rs b/src/commit/file_stat.rs index d1eec95..5b9342b 100644 --- a/src/commit/file_stat.rs +++ b/src/commit/file_stat.rs @@ -1,14 +1,14 @@ use git2::Delta; #[derive(Debug, PartialEq)] -pub struct FileStat { +pub(crate) struct FileStat { status: Delta, to_name: String, from_name: String, } impl FileStat { - pub fn new(from_name: String, to_name: String, status: Delta) -> Self { + pub(super) fn new(from_name: String, to_name: String, status: Delta) -> Self { FileStat { status, to_name, @@ -16,15 +16,15 @@ impl FileStat { } } - pub fn get_status(&self) -> &Delta { + pub(crate) fn get_status(&self) -> &Delta { &self.status } - pub fn get_to_name(&self) -> &String { + pub(crate) fn get_to_name(&self) -> &String { &self.to_name } - pub fn get_from_name(&self) -> &String { + pub(crate) fn get_from_name(&self) -> &String { &self.from_name } } diff --git a/src/commit/mod.rs b/src/commit/mod.rs index a4d04aa..927c7dc 100644 --- a/src/commit/mod.rs +++ b/src/commit/mod.rs @@ -1,7 +1,74 @@ -#[allow(clippy::module_inception)] -mod commit; mod file_stat; mod user; mod utils; -pub use self::commit::Commit; +use crate::commit::file_stat::FileStat; +use crate::commit::user::User; +use crate::commit::utils::load_commit_state; +use chrono::{DateTime, Local}; + +#[derive(Debug, PartialEq)] +pub(crate) struct Commit { + author: User, + body: Option<String>, + committer: User, + date: DateTime<Local>, + file_stats: Option<Vec<FileStat>>, + hash: String, +} + +impl Commit { + pub(super) fn new( + hash: String, + author: User, + committer: User, + date: DateTime<Local>, + file_stats: Option<Vec<FileStat>>, + body: Option<String>, + ) -> Self + { + Commit { + author, + body, + committer, + date, + file_stats, + hash, + } + } + + pub(crate) fn from_commit_hash(hash: &str) -> Result<Self, String> { + load_commit_state(hash).map_err(|e| String::from(e.message())) + } + + pub(crate) fn get_author(&self) -> &User { + &self.author + } + + pub(crate) fn get_committer(&self) -> &User { + &self.committer + } + + pub(crate) fn get_date(&self) -> &DateTime<Local> { + &self.date + } + + pub(crate) fn get_hash(&self) -> &String { + &self.hash + } + + pub(crate) fn get_body(&self) -> &Option<String> { + &self.body + } + + pub(crate) fn get_file_stats(&self) -> &Option<Vec<FileStat>> { + &self.file_stats + } + + pub(crate) fn get_file_stats_length(&self) -> usize { + match &self.file_stats { + Some(s) => s.len(), + None => 0, + } + } +} diff --git a/src/commit/user.rs b/src/commit/user.rs index cc4e963..d786ad1 100644 --- a/src/commit/user.rs +++ b/src/commit/user.rs @@ -1,18 +1,18 @@ #[derive(Debug, Eq, PartialEq)] -pub struct User { +pub(crate) struct User { name: Option<String>, email: Option<String>, } impl User { - pub fn new(name: Option<&str>, email: Option<&str>) -> Self { + pub(super) fn new(name: Option<&str>, email: Option<&str>) -> Self { User { email: email.map(String::from), name: name.map(String::from), } } - pub fn to_string(&self) -> Option<String> { + pub(crate) fn to_string(&self) -> Option<String> { let name = &self.name; let email = &self.email; match name { diff --git a/src/commit/utils.rs b/src/commit/utils.rs index 63b5308..e113428 100644 --- a/src/commit/utils.rs +++ b/src/commit/utils.rs @@ -1,10 +1,10 @@ -use crate::commit::commit::Commit; use crate::commit::file_stat::FileStat; use crate::commit::user::User; +use crate::commit::Commit; use chrono::{Local, TimeZone}; use git2::{Delta, DiffFindOptions, DiffOptions, Error, Repository}; -pub(crate) fn load_commit_state(hash: &str) -> Result<Commit, Error> { +pub(super) fn load_commit_state(hash: &str) -> Result<Commit, Error> { let repo = Repository::open_from_env()?; let commit = repo.find_commit(repo.revparse_single(hash)?.id())?; diff --git a/src/config/config.rs b/src/config/config.rs deleted file mode 100644 index 92e8155..0000000 --- a/src/config/config.rs +++ /dev/null @@ -1,105 +0,0 @@ -use crate::config::utils::{editor_from_env, get_bool, get_color, get_input, get_string, open_git_config}; -use crate::config::Theme; -use crate::display::Color; -use std::convert::TryFrom; - -#[derive(Clone, Debug)] -pub struct Config { - pub theme: Theme, - pub auto_select_next: bool, - pub comment_char: String, - pub editor: String, - pub input_abort: String, - pub input_action_break: String, - pub input_action_drop: String, - pub input_action_edit: String, - pub input_action_fixup: String, - pub input_action_pick: String, - pub input_action_reword: String, - pub input_action_squash: String, - pub input_confirm_no: String, - pub input_confirm_yes: String, - pub input_edit: String, - pub input_force_abort: String, - pub input_force_rebase: String, - pub input_help: String, - pub input_move_down: String, - pub input_move_down_step: String, - pub input_move_left: String, - pub input_move_right: String, - pub input_move_selection_down: String, - pub input_move_selection_up: String, - pub input_move_up: String, - pub input_move_up_step: String, - pub input_open_in_external_editor: String, - pub input_rebase: String, - pub input_show_commit: String, - pub input_toggle_visual_mode: String, -} - -impl Config { - pub fn new() -> Result<Self, String> { - let git_config = open_git_config()?; - Ok(Config { - theme: Theme { - color_foreground: get_color(&git_config, "interactive-rebase-tool.foregroundColor", Color::White)?, - color_background: get_color(&git_config, "interactive-rebase-tool.backgroundColor", Color::Default)?, - color_selected_background: get_color( - &git_config, - "interactive-rebase-tool.selectedBackgroundColor", - Color::try_from("35,35,40").unwrap(), - )?, - color_indicator: get_color(&git_config, "interactive-rebase-tool.indicatorColor", Color::Cyan)?, - color_action_break: get_color(&git_config, "interactive-rebase-tool.breakColor", Color::White)?, - color_action_drop: get_color(&git_config, "interactive-rebase-tool.dropColor", Color::Red)?, - color_action_edit: get_color(&git_config, "interactive-rebase-tool.editColor", Color::Blue)?, - color_action_exec: get_color(&git_config, "interactive-rebase-tool.execColor", Color::White)?, - color_action_fixup: get_color(&git_config, "interactive-rebase-tool.fixupColor", Color::Magenta)?, - color_action_pick: get_color(&git_config, "interactive-rebase-tool.pickColor", Color::Green)?, - color_action_reword: get_color(&git_config, "interactive-rebase-tool.rewordColor", Color::Yellow)?, - color_action_squash: get_color(&git_config, "interactive-rebase-tool.squashColor", Color::Cyan)?, - color_diff_add: get_color(&git_config, "interactive-rebase-tool.diffAddColor", Color::Green)?, - color_diff_change: get_color(&git_config, "interactive-rebase-tool.diffChangeColor", Color::Yellow)?, - color_diff_remove: get_color(&git_config, "interactive-rebase-tool.diffRemoveColor", Color::Red)?, - character_vertical_spacing: get_string( - &git_config, - "interactive-rebase-tool.verticalSpacingCharacter", - "~", - )?, - }, - auto_select_next: get_bool(&git_config, "interactive-rebase-tool.autoSelectNext", false)?, - comment_char: get_string(&git_config, "core.commentChar", "#")?, - editor: get_string(&git_config, "core.editor", editor_from_env().as_str())?, - input_abort: get_input(&git_config, "interactive-rebase-tool.inputAbort", "q")?, - input_action_break: get_input(&git_config, "interactive-rebase-tool.inputActionBreak", "b")?, - input_action_drop: get_input(&git_config, "interactive-rebase-tool.inputActionDrop", "d")?, - input_action_edit: get_input(&git_config, "interactive-rebase-tool.inputActionEdit", "e")?, - input_action_fixup: get_input(&git_config, "interactive-rebase-tool.inputActionFixup", "f")?, - input_action_pick: get_input(&git_config, "interactive-rebase-tool.inputActionPick", "p")?, - input_action_reword: get_input(&git_config, "interactive-rebase-tool.inputActionReword", "r")?, - input_action_squash: get_input(&git_config, "interactive-rebase-tool.inputActionSquash", "s")?, - input_confirm_no: get_input(&git_config, "interactive-rebase-tool.inputConfirmNo", "n")?, - input_confirm_yes: get_input(&git_config, "interactive-rebase-tool.inputConfirmYes", "y")?, - input_edit: get_input(&git_config, "interactive-rebase-tool.inputEdit", "E")?, - input_force_abort: get_input(&git_config, "interactive-rebase-tool.inputForceAbort", "Q")?, - input_force_rebase: get_input(&git_config, "interactive-rebase-tool.inputForceRebase", "W")?, - input_help: get_input(&git_config, "interactive-rebase-tool.inputHelp", "?")?, - input_move_down: get_input(&git_config, "interactive-rebase-tool.inputMoveDown", "Down")?, - input_move_left: get_input(&git_config, "interactive-rebase-tool.inputMoveLeft", "Left")?, - input_move_right: get_input(&git_config, "interactive-rebase-tool.inputMoveRight", "Right")?, - input_move_up_step: get_input(&git_config, "interactive-rebase-tool.inputMoveStepUp", "PageUp")?, - input_move_down_step: get_input(&git_config, "interactive-rebase-tool.inputMoveStepDown", "PageDown")?, - input_move_selection_down: get_input(&git_config, "interactive-rebase-tool.inputMoveSelectionDown", "j")?, - input_move_selection_up: get_input(&git_config, "interactive-rebase-tool.inputMoveSelectionUp", "k")?, - input_move_up: get_input(&git_config, "interactive-rebase-tool.inputMoveUp", "Up")?, - input_open_in_external_editor: get_input( - &git_config, - "interactive-rebase-tool.inputOpenInExternalEditor", - "!", - )?, - input_rebase: get_input(&git_config, "interactive-rebase-tool.inputRebase", "w")?, - input_show_commit: get_input(&git_config, "interactive-rebase-tool.inputShowCommit", "c")?, - input_toggle_visual_mode: get_input(&git_config, "interactive-rebase-tool.inputToggleVisualMode", "v")?, - }) - } -} diff --git a/src/config/mod.rs b/src/config/mod.rs index 5afbb84..f786701 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -1,7 +1,108 @@ -#[allow(clippy::module_inception)] -mod config; -mod theme; +pub(crate) mod theme; mod utils; -pub use self::config::Config; -pub use self::theme::Theme; +use crate::config::theme::Theme; +use crate::config::utils::{editor_from_env, get_bool, get_color, get_input, get_string, open_git_config}; +use crate::display::color::Color; +use std::convert::TryFrom; + +#[derive(Clone, Debug)] +pub(crate) struct Config { + pub(crate) theme: Theme, + pub(crate) auto_select_next: bool, + pub(crate) comment_char: String, + pub(crate) editor: String, + pub(crate) input_abort: String, + pub(crate) input_action_break: String, + pub(crate) input_action_drop: String, + pub(crate) input_action_edit: String, + pub(crate) input_action_fixup: String, + pub(crate) input_action_pick: String, + pub(crate) input_action_reword: String, + pub(crate) input_action_squash: String, + pub(crate) input_confirm_no: String, + pub(crate) input_confirm_yes: String, + pub(crate) input_edit: String, + pub(crate) input_force_abort: String, + pub(crate) input_force_rebase: String, + pub(crate) input_help: String, + pub(crate) input_move_down: String, + pub(crate) input_move_down_step: String, + pub(crate) input_move_left: String, + pub(crate) input_move_right: String, + pub(crate) input_move_selection_down: String, + pub(crate) input_move_selection_up: String, + pub(crate) input_move_up: String, + pub(crate) input_move_up_step: String, + pub(crate) input_open_in_external_editor: String, + pub(crate) input_rebase: String, + pub(crate) input_show_commit: String, + pub(crate) input_toggle_visual_mode: String, +} + +impl Config { + pub(crate) fn new() -> Result<Self, String> { + let git_config = open_git_config()?; + Ok(Config { + theme: Theme { + color_foreground: get_color(&git_config, "interactive-rebase-tool.foregroundColor", Color::White)?, + color_background: get_color(&git_config, "interactive-rebase-tool.backgroundColor", Color::Default)?, + color_selected_background: get_color( + &git_config, + "interactive-rebase-tool.selectedBackgroundColor", + Color::try_from("35,35,40").unwrap(), + )?, + color_indicator: get_color(&git_config, "interactive-rebase-tool.indicatorColor", Color::Cyan)?, + color_action_break: get_color(&git_config, "interactive-rebase-tool.breakColor", Color::White)?, + color_action_drop: get_color(&git_config, "interactive-rebase-tool.dropColor", Color::Red)?, + color_action_edit: get_color(&git_config, "interactive-rebase-tool.editColor", Color::Blue)?, + color_action_exec: get_color(&git_config, "interactive-rebase-tool.execColor", Color::White)?, + color_action_fixup: get_color(&git_config, "interactive-rebase-tool.fixupColor", Color::Magenta)?, + color_action_pick: get_color(&git_config, "interactive-rebase-tool.pickColor", Color::Green)?, + color_action_reword: get_color(&git_config, "interactive-rebase-tool.rewordColor", Color::Yellow)?, + color_action_squash: get_color(&git_config, "interactive-rebase-tool.squashColor", Color::Cyan)?, + color_diff_add: get_color(&git_config, "interactive-rebase-tool.diffAddColor", Color::Green)?, + color_diff_change: get_color(&git_config, "interactive-rebase-tool.diffChangeColor", Color::Yellow)?, + color_diff_remove: get_color(&git_config, "interactive-rebase-tool.diffRemoveColor", Color::Red)?, + character_vertical_spacing: get_string( + &git_config, + "interactive-rebase-tool.verticalSpacingCharacter", + "~", + )?, + }, + auto_select_next: get_bool(&git_config, "interactive-rebase-tool.autoSelectNext", false)?, + comment_char: get_string(&git_config, "core.commentChar", "#")?, + editor: get_string(&git_config, "core.editor", editor_from_env().as_str())?, + input_abort: get_input(&git_config, "interactive-rebase-tool.inputAbort", "q")?, + input_action_break: get_input(&git_config, "interactive-rebase-tool.inputActionBreak", "b")?, + input_action_drop: get_input(&git_config, "interactive-rebase-tool.inputActionDrop", "d")?, + input_action_edit: get_input(&git_config, "interactive-rebase-tool.inputActionEdit", "e")?, + input_action_fixup: get_input(&git_config, "interactive-rebase-tool.inputActionFixup", "f")?, + input_action_pick: get_input(&git_config, "interactive-rebase-tool.inputActionPick", "p")?, + input_action_reword: get_input(&git_c |