diff --git a/asyncgit/src/sync/commit_details.rs b/asyncgit/src/sync/commit_details.rs index 8f74cb1e..4ad9435f 100644 --- a/asyncgit/src/sync/commit_details.rs +++ b/asyncgit/src/sync/commit_details.rs @@ -80,6 +80,13 @@ pub struct CommitDetails { pub hash: String, } +impl CommitDetails { + /// + pub fn short_hash(&self) -> &str { + &self.hash[0..7] + } +} + /// pub fn get_commit_details( repo_path: &str, diff --git a/src/components/commit_details/compare_details.rs b/src/components/commit_details/compare_details.rs index cfa356b1..1b42766e 100644 --- a/src/components/commit_details/compare_details.rs +++ b/src/components/commit_details/compare_details.rs @@ -8,7 +8,6 @@ use crate::{ CommandBlocking, CommandInfo, Component, DrawableComponent, EventState, }, - keys::SharedKeyConfig, strings::{self}, ui::style::SharedTheme, }; @@ -29,21 +28,15 @@ pub struct CompareDetailsComponent { data: Option<(CommitDetails, CommitDetails)>, theme: SharedTheme, focused: bool, - key_config: SharedKeyConfig, } impl CompareDetailsComponent { /// - pub const fn new( - theme: SharedTheme, - key_config: SharedKeyConfig, - focused: bool, - ) -> Self { + pub const fn new(theme: SharedTheme, focused: bool) -> Self { Self { data: None, theme, focused, - key_config, } } @@ -68,11 +61,7 @@ impl CompareDetailsComponent { fn get_commit_text(&self, data: &CommitDetails) -> Vec { let mut res = vec![ Spans::from(vec![ - style_detail( - &self.theme, - &self.key_config, - &Detail::Author, - ), + style_detail(&self.theme, &Detail::Author), Span::styled( Cow::from(format!( "{} <{}>", @@ -82,11 +71,7 @@ impl CompareDetailsComponent { ), ]), Spans::from(vec![ - style_detail( - &self.theme, - &self.key_config, - &Detail::Date, - ), + style_detail(&self.theme, &Detail::Date), Span::styled( Cow::from(time_to_string( data.author.time, @@ -97,48 +82,15 @@ impl CompareDetailsComponent { ]), ]; - if let Some(ref committer) = data.committer { - res.extend(vec![ - Spans::from(vec![ - style_detail( - &self.theme, - &self.key_config, - &Detail::Commiter, - ), - Span::styled( - Cow::from(format!( - "{} <{}>", - committer.name, committer.email - )), - self.theme.text(true, false), - ), - ]), - Spans::from(vec![ - style_detail( - &self.theme, - &self.key_config, - &Detail::Date, - ), - Span::styled( - Cow::from(time_to_string( - committer.time, - false, - )), - self.theme.text(true, false), - ), - ]), - ]); - } - res.push(Spans::from(vec![ + style_detail(&self.theme, &Detail::Message), Span::styled( - Cow::from(strings::commit::details_sha( - &self.key_config, - )), - self.theme.text(false, false), - ), - Span::styled( - Cow::from(data.hash.clone()), + Cow::from( + data.message + .as_ref() + .map(|msg| msg.subject.clone()) + .unwrap_or_default(), + ), self.theme.text(true, false), ), ])); @@ -166,6 +118,7 @@ impl DrawableComponent for CompareDetailsComponent { dialog_paragraph( &strings::commit::compare_details_info_title( true, + data.0.short_hash(), ), Text::from(self.get_commit_text(&data.0)), &self.theme, @@ -178,6 +131,7 @@ impl DrawableComponent for CompareDetailsComponent { dialog_paragraph( &strings::commit::compare_details_info_title( false, + data.1.short_hash(), ), Text::from(self.get_commit_text(&data.1)), &self.theme, diff --git a/src/components/commit_details/details.rs b/src/components/commit_details/details.rs index 6dc69926..a3243c87 100644 --- a/src/components/commit_details/details.rs +++ b/src/components/commit_details/details.rs @@ -155,11 +155,7 @@ impl DetailsComponent { if let Some(ref data) = self.data { let mut res = vec![ Spans::from(vec![ - style_detail( - &self.theme, - &self.key_config, - &Detail::Author, - ), + style_detail(&self.theme, &Detail::Author), Span::styled( Cow::from(format!( "{} <{}>", @@ -169,11 +165,7 @@ impl DetailsComponent { ), ]), Spans::from(vec![ - style_detail( - &self.theme, - &self.key_config, - &Detail::Date, - ), + style_detail(&self.theme, &Detail::Date), Span::styled( Cow::from(time_to_string( data.author.time, @@ -187,11 +179,7 @@ impl DetailsComponent { if let Some(ref committer) = data.committer { res.extend(vec![ Spans::from(vec![ - style_detail( - &self.theme, - &self.key_config, - &Detail::Commiter, - ), + style_detail(&self.theme, &Detail::Commiter), Span::styled( Cow::from(format!( "{} <{}>", @@ -201,11 +189,7 @@ impl DetailsComponent { ), ]), Spans::from(vec![ - style_detail( - &self.theme, - &self.key_config, - &Detail::Date, - ), + style_detail(&self.theme, &Detail::Date), Span::styled( Cow::from(time_to_string( committer.time, @@ -219,9 +203,7 @@ impl DetailsComponent { res.push(Spans::from(vec![ Span::styled( - Cow::from(strings::commit::details_sha( - &self.key_config, - )), + Cow::from(strings::commit::details_sha()), self.theme.text(false, false), ), Span::styled( @@ -233,7 +215,6 @@ impl DetailsComponent { if !self.tags.is_empty() { res.push(Spans::from(style_detail( &self.theme, - &self.key_config, &Detail::Sha, ))); diff --git a/src/components/commit_details/mod.rs b/src/components/commit_details/mod.rs index 5e52e0e5..5f81dedb 100644 --- a/src/components/commit_details/mod.rs +++ b/src/components/commit_details/mod.rs @@ -53,7 +53,6 @@ impl CommitDetailsComponent { ), compare_details: CompareDetailsComponent::new( theme.clone(), - key_config.clone(), false, ), git_commit_files: AsyncCommitFiles::new(sender), diff --git a/src/components/commit_details/style.rs b/src/components/commit_details/style.rs index 2f0ce72f..97555c19 100644 --- a/src/components/commit_details/style.rs +++ b/src/components/commit_details/style.rs @@ -1,4 +1,4 @@ -use crate::{keys::SharedKeyConfig, strings, ui::style::SharedTheme}; +use crate::{strings, ui::style::SharedTheme}; use std::borrow::Cow; use tui::text::Span; @@ -7,28 +7,32 @@ pub enum Detail { Date, Commiter, Sha, + Message, } pub fn style_detail<'a>( theme: &'a SharedTheme, - keys: &'a SharedKeyConfig, field: &Detail, ) -> Span<'a> { match field { Detail::Author => Span::styled( - Cow::from(strings::commit::details_author(keys)), + Cow::from(strings::commit::details_author()), theme.text(false, false), ), Detail::Date => Span::styled( - Cow::from(strings::commit::details_date(keys)), + Cow::from(strings::commit::details_date()), theme.text(false, false), ), Detail::Commiter => Span::styled( - Cow::from(strings::commit::details_committer(keys)), + Cow::from(strings::commit::details_committer()), theme.text(false, false), ), Detail::Sha => Span::styled( - Cow::from(strings::commit::details_tags(keys)), + Cow::from(strings::commit::details_tags()), + theme.text(false, false), + ), + Detail::Message => Span::styled( + Cow::from(strings::commit::details_message()), theme.text(false, false), ), } diff --git a/src/strings.rs b/src/strings.rs index d8e6e5af..dce92874 100644 --- a/src/strings.rs +++ b/src/strings.rs @@ -300,34 +300,34 @@ pub fn rename_branch_popup_msg( pub mod commit { use crate::keys::SharedKeyConfig; - pub fn details_author(_key_config: &SharedKeyConfig) -> String { + pub fn details_author() -> String { "Author: ".to_string() } - pub fn details_committer( - _key_config: &SharedKeyConfig, - ) -> String { + pub fn details_committer() -> String { "Committer: ".to_string() } - pub fn details_sha(_key_config: &SharedKeyConfig) -> String { + pub fn details_sha() -> String { "Sha: ".to_string() } - pub fn details_date(_key_config: &SharedKeyConfig) -> String { + pub fn details_date() -> String { "Date: ".to_string() } - pub fn details_tags(_key_config: &SharedKeyConfig) -> String { + pub fn details_tags() -> String { "Tags: ".to_string() } + pub fn details_message() -> String { + "Subject: ".to_string() + } pub fn details_info_title( _key_config: &SharedKeyConfig, ) -> String { "Info".to_string() } - pub fn compare_details_info_title(old: bool) -> String { - if old { - "Old".to_string() - } else { - "New".to_string() - } + pub fn compare_details_info_title( + old: bool, + hash: &str, + ) -> String { + format!("{}: {}", if old { "Old" } else { "New" }, hash) } pub fn details_message_title( _key_config: &SharedKeyConfig,