diff --git a/CHANGELOG.md b/CHANGELOG.md index f08e41f29c..321028d945 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) diff --git a/src/components/commitlist.rs b/src/components/commitlist.rs index c4540ec6d5..bb84c16869 100644 --- a/src/components/commitlist.rs +++ b/src/components/commitlist.rs @@ -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, 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), + )); } } _ => {} diff --git a/src/strings.rs b/src/strings.rs index 420c2aa04b..47bf594a09 100644 --- a/src/strings.rs +++ b/src/strings.rs @@ -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 { if s.width() <= width { Cow::Borrowed(s) diff --git a/src/tabs/revlog.rs b/src/tabs/revlog.rs index f7cfc22aec..d8c83fa730 100644 --- a/src/tabs/revlog.rs +++ b/src/tabs/revlog.rs @@ -62,6 +62,7 @@ impl Revlog { list: CommitList::new( &strings::log_title(&key_config), theme, + queue.clone(), key_config.clone(), ), git_log: AsyncLog::new( diff --git a/src/tabs/stashlist.rs b/src/tabs/stashlist.rs index fbdf0fe25d..89176e93ca 100644 --- a/src/tabs/stashlist.rs +++ b/src/tabs/stashlist.rs @@ -34,6 +34,7 @@ impl StashList { list: CommitList::new( &strings::stashlist_title(&key_config), theme, + queue.clone(), key_config.clone(), ), queue: queue.clone(),