mirror of
https://github.com/extrawurst/gitui.git
synced 2024-12-27 11:03:03 +03:00
show subject line of commits compared
This commit is contained in:
parent
3db3b95dd0
commit
81924fb9f8
@ -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,
|
||||
|
@ -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<Spans> {
|
||||
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,
|
||||
|
@ -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,
|
||||
)));
|
||||
|
||||
|
@ -53,7 +53,6 @@ impl CommitDetailsComponent {
|
||||
),
|
||||
compare_details: CompareDetailsComponent::new(
|
||||
theme.clone(),
|
||||
key_config.clone(),
|
||||
false,
|
||||
),
|
||||
git_commit_files: AsyncCommitFiles::new(sender),
|
||||
|
@ -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),
|
||||
),
|
||||
}
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user