Add notification when correctly copying hash commit (#1376)

This commit is contained in:
Sergio Alejandro Ribera Costa 2022-10-26 08:35:31 -04:00 committed by GitHub
parent c705712a05
commit 282e578ac3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 59 additions and 5 deletions

View file

@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* add `regex-fancy` and `regex-onig` features to allow building Syntect with Onigumara regex engine instead of the default engine based on fancy-regex [[@jirutka](https://github.com/jirutka)]
* add `vendor-openssl` feature to allow building without vendored openssl [[@jirutka](https://github.com/jirutka)]
* allow copying marked commits [[@remique](https://github.com/remique)] ([#1288](https://github.com/extrawurst/gitui/issues/1288))
* Feedback for success/failure of copying hash commit [[@sergioribera]](https://github.com/sergioribera)([#1160](https://github.com/extrawurst/gitui/issues/1160))
* display tags and branches in the log view [[@alexmaco]](https://github.com/alexmaco)([#1371](https://github.com/extrawurst/gitui/pull/1371))
* display current repository path in the top-right corner [[@alexmaco]](https://github.com/alexmaco)([#1387](https://github.com/extrawurst/gitui/pull/1387))

View file

@ -5,7 +5,8 @@ use crate::{
Component, DrawableComponent, EventState, ScrollType,
},
keys::{key_match, SharedKeyConfig},
strings::{self, symbol},
queue::{InternalEvent, Queue},
strings::{self, copy_fail, copy_success, symbol},
ui::style::{SharedTheme, Theme},
ui::{calc_scroll_top, draw_scrollbar},
};
@ -41,6 +42,7 @@ pub struct CommitList {
current_size: Cell<(u16, u16)>,
scroll_top: Cell<usize>,
theme: SharedTheme,
queue: Queue,
key_config: SharedKeyConfig,
}
@ -49,6 +51,7 @@ impl CommitList {
pub fn new(
title: &str,
theme: SharedTheme,
queue: Queue,
key_config: SharedKeyConfig,
) -> Self {
Self {
@ -62,6 +65,7 @@ impl CommitList {
current_size: Cell::new((0, 0)),
scroll_top: Cell::new(0),
theme,
queue,
key_config,
title: title.into(),
}
@ -178,7 +182,15 @@ impl CommitList {
if let (Some(f), Some(l)) = (first, last) {
let yank =
format!("{}^..{}", f.hash_short, l.hash_short);
crate::clipboard::copy_string(&yank)?;
if let Err(e) = crate::clipboard::copy_string(&yank) {
self.queue.push(InternalEvent::ShowErrorMsg(
copy_fail(&e.to_string()),
));
return Err(e);
}
self.queue.push(InternalEvent::ShowInfoMsg(
copy_success(&yank),
));
};
} else {
let separate = self
@ -194,7 +206,15 @@ impl CommitList {
})
.join(" ");
crate::clipboard::copy_string(&separate)?;
if let Err(e) = crate::clipboard::copy_string(&separate) {
self.queue.push(InternalEvent::ShowErrorMsg(
copy_fail(&e.to_string()),
));
return Err(e);
}
self.queue.push(InternalEvent::ShowInfoMsg(
copy_success(&separate),
));
}
Ok(())
@ -207,14 +227,34 @@ impl CommitList {
self.selection
.saturating_sub(self.items.index_offset()),
) {
crate::clipboard::copy_string(&e.hash_short)?;
if let Err(e) =
crate::clipboard::copy_string(&e.hash_short)
{
self.queue.push(InternalEvent::ShowErrorMsg(
copy_fail(&e.to_string()),
));
return Err(e);
}
self.queue.push(InternalEvent::ShowInfoMsg(
copy_success(&e.hash_short),
));
}
}
1 => {
if let Some(e) =
self.items.iter().nth(self.marked_indexes()[0])
{
crate::clipboard::copy_string(&e.hash_short)?;
if let Err(e) =
crate::clipboard::copy_string(&e.hash_short)
{
self.queue.push(InternalEvent::ShowErrorMsg(
copy_fail(&e.to_string()),
));
return Err(e);
}
self.queue.push(InternalEvent::ShowInfoMsg(
copy_success(&e.hash_short),
));
}
}
_ => {}

View file

@ -30,6 +30,9 @@ pub static PUSH_TAGS_STATES_DONE: &str = "done";
pub static POPUP_TITLE_SUBMODULES: &str = "Submodules";
pub static POPUP_TITLE_FUZZY_FIND: &str = "Fuzzy Finder";
pub static POPUP_FAIL_COPY: &str = "Failed to copy the Text";
pub static POPUP_SUCCESS_COPY: &str = "Copied Text";
pub mod symbol {
pub const WHITESPACE: &str = "\u{00B7}"; //·
pub const CHECKMARK: &str = "\u{2713}"; //✓
@ -353,6 +356,14 @@ pub fn rename_branch_popup_msg(
"new branch name".to_string()
}
pub fn copy_success(s: &str) -> String {
format!("{POPUP_SUCCESS_COPY} \"{s}\"")
}
pub fn copy_fail(e: &str) -> String {
format!("{POPUP_FAIL_COPY}: {e}")
}
pub fn ellipsis_trim_start(s: &str, width: usize) -> Cow<str> {
if s.width() <= width {
Cow::Borrowed(s)

View file

@ -62,6 +62,7 @@ impl Revlog {
list: CommitList::new(
&strings::log_title(&key_config),
theme,
queue.clone(),
key_config.clone(),
),
git_log: AsyncLog::new(

View file

@ -34,6 +34,7 @@ impl StashList {
list: CommitList::new(
&strings::stashlist_title(&key_config),
theme,
queue.clone(),
key_config.clone(),
),
queue: queue.clone(),