From 003efa4a15f3776cf1e9b4b1b5f369f875c527c2 Mon Sep 17 00:00:00 2001 From: Sergio Ribera Date: Tue, 4 Oct 2022 00:58:52 -0400 Subject: [PATCH 1/8] Add notification when correctly copying hash commit --- src/components/commitlist.rs | 17 +++++++++++++++++ src/tabs/revlog.rs | 1 + src/tabs/stashlist.rs | 1 + 3 files changed, 19 insertions(+) diff --git a/src/components/commitlist.rs b/src/components/commitlist.rs index ebe4edc48a..adefc7f684 100644 --- a/src/components/commitlist.rs +++ b/src/components/commitlist.rs @@ -5,6 +5,7 @@ use crate::{ Component, DrawableComponent, EventState, ScrollType, }, keys::{key_match, SharedKeyConfig}, + queue::{InternalEvent, Queue}, strings::{self, symbol}, ui::style::{SharedTheme, Theme}, ui::{calc_scroll_top, draw_scrollbar}, @@ -26,6 +27,7 @@ use tui::{ }; const ELEMENTS_PER_LINE: usize = 9; +const SUCCESS_COPY: &str = "Correctly Copied"; /// pub struct CommitList { @@ -40,6 +42,7 @@ pub struct CommitList { current_size: Cell<(u16, u16)>, scroll_top: Cell, theme: SharedTheme, + queue: Queue, key_config: SharedKeyConfig, } @@ -48,6 +51,7 @@ impl CommitList { pub fn new( title: &str, theme: SharedTheme, + queue: Queue, key_config: SharedKeyConfig, ) -> Self { Self { @@ -61,6 +65,7 @@ impl CommitList { current_size: Cell::new((0, 0)), scroll_top: Cell::new(0), theme, + queue, key_config, title: title.into(), } @@ -183,6 +188,9 @@ impl CommitList { let yank = format!("{}^..{}", f.hash_short, l.hash_short); crate::clipboard::copy_string(&yank)?; + self.queue.push(InternalEvent::ShowInfoMsg( + String::from(SUCCESS_COPY), + )); }; } else { let separate = self @@ -199,6 +207,9 @@ impl CommitList { .join(" "); crate::clipboard::copy_string(&separate)?; + self.queue.push(InternalEvent::ShowInfoMsg( + String::from(SUCCESS_COPY), + )); } Ok(()) @@ -212,6 +223,9 @@ impl CommitList { .saturating_sub(self.items.index_offset()), ) { crate::clipboard::copy_string(&e.hash_short)?; + self.queue.push(InternalEvent::ShowInfoMsg( + String::from(SUCCESS_COPY), + )); } } 1 => { @@ -219,6 +233,9 @@ impl CommitList { self.items.iter().nth(self.marked_indexes()[0]) { crate::clipboard::copy_string(&e.hash_short)?; + self.queue.push(InternalEvent::ShowInfoMsg( + String::from(SUCCESS_COPY), + )); } } _ => {} diff --git a/src/tabs/revlog.rs b/src/tabs/revlog.rs index 710617ca1a..111318d9d8 100644 --- a/src/tabs/revlog.rs +++ b/src/tabs/revlog.rs @@ -64,6 +64,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 1d61d988ac..9a85c05d53 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(), From 7afdad1496652d0e12529373236cb2a4b6af35e3 Mon Sep 17 00:00:00 2001 From: Sergio Ribera Date: Tue, 4 Oct 2022 01:25:42 -0400 Subject: [PATCH 2/8] Add changes to Changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fea975dc30..b5c975306f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,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)) +* Add notification when correctly copying hash commit ([#1160](https://github.com/extrawurst/gitui/issues/1160)) ### Fixes * remove insecure dependency `ansi_term` ([#1290](https://github.com/extrawurst/gitui/issues/1290)) From 0c80422aad26d3c69481372d436e1bf393edda02 Mon Sep 17 00:00:00 2001 From: Sergio Ribera Date: Tue, 11 Oct 2022 00:13:58 -0400 Subject: [PATCH 3/8] Add notification when fail copy --- src/components/commitlist.rs | 39 +++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/src/components/commitlist.rs b/src/components/commitlist.rs index adefc7f684..36f92eee4b 100644 --- a/src/components/commitlist.rs +++ b/src/components/commitlist.rs @@ -27,7 +27,8 @@ use tui::{ }; const ELEMENTS_PER_LINE: usize = 9; -const SUCCESS_COPY: &str = "Correctly Copied"; +const FAIL_COPY: &str = "Failed to copy the Text"; +const SUCCESS_COPY: &str = "Copied Text"; /// pub struct CommitList { @@ -187,9 +188,14 @@ 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( + format!("{}: {}", FAIL_COPY, e), + )); + return Err(e); + } self.queue.push(InternalEvent::ShowInfoMsg( - String::from(SUCCESS_COPY), + format!("{} \"{}\"", SUCCESS_COPY, &yank), )); }; } else { @@ -206,9 +212,14 @@ impl CommitList { }) .join(" "); - crate::clipboard::copy_string(&separate)?; + if let Err(e) = crate::clipboard::copy_string(&separate) { + self.queue.push(InternalEvent::ShowErrorMsg( + format!("{}: {}", FAIL_COPY, e), + )); + return Err(e); + } self.queue.push(InternalEvent::ShowInfoMsg( - String::from(SUCCESS_COPY), + format!("{} \"{}\"", SUCCESS_COPY, &separate), )); } @@ -222,9 +233,14 @@ 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( + format!("{}: {}", FAIL_COPY, e), + )); + return Err(e); + } self.queue.push(InternalEvent::ShowInfoMsg( - String::from(SUCCESS_COPY), + format!("{} \"{}\"", SUCCESS_COPY, &e.hash_short), )); } } @@ -232,9 +248,14 @@ impl CommitList { 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( + format!("{}: {}", FAIL_COPY, e), + )); + return Err(e); + } self.queue.push(InternalEvent::ShowInfoMsg( - String::from(SUCCESS_COPY), + format!("{} \"{}\"", SUCCESS_COPY, &e.hash_short), )); } } From ae69f1df7fc67599d2e8467d13a2085318cf1ec0 Mon Sep 17 00:00:00 2001 From: Sergio Ribera Date: Sat, 15 Oct 2022 16:25:06 -0400 Subject: [PATCH 4/8] move apy string message to strings file --- src/components/commitlist.rs | 63 ++++++++++++++++++------------------ src/strings.rs | 10 ++++++ 2 files changed, 42 insertions(+), 31 deletions(-) diff --git a/src/components/commitlist.rs b/src/components/commitlist.rs index 36f92eee4b..96e4f465a6 100644 --- a/src/components/commitlist.rs +++ b/src/components/commitlist.rs @@ -6,7 +6,7 @@ use crate::{ }, keys::{key_match, SharedKeyConfig}, queue::{InternalEvent, Queue}, - strings::{self, symbol}, + strings::{self, copy_fail, copy_success, symbol}, ui::style::{SharedTheme, Theme}, ui::{calc_scroll_top, draw_scrollbar}, }; @@ -27,8 +27,6 @@ use tui::{ }; const ELEMENTS_PER_LINE: usize = 9; -const FAIL_COPY: &str = "Failed to copy the Text"; -const SUCCESS_COPY: &str = "Copied Text"; /// pub struct CommitList { @@ -188,14 +186,14 @@ impl CommitList { if let (Some(f), Some(l)) = (first, last) { let yank = format!("{}^..{}", f.hash_short, l.hash_short); - if let Err(e) = crate::clipboard::copy_string(&yank) { - self.queue.push(InternalEvent::ShowErrorMsg( - format!("{}: {}", FAIL_COPY, e), - )); - return Err(e); - } + 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( - format!("{} \"{}\"", SUCCESS_COPY, &yank), + copy_success(&yank), )); }; } else { @@ -212,14 +210,13 @@ impl CommitList { }) .join(" "); - if let Err(e) = crate::clipboard::copy_string(&separate) { - self.queue.push(InternalEvent::ShowErrorMsg( - format!("{}: {}", FAIL_COPY, e), - )); - return Err(e); - } + 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( - format!("{} \"{}\"", SUCCESS_COPY, &separate), + copy_success(&separate), )); } @@ -233,14 +230,16 @@ impl CommitList { self.selection .saturating_sub(self.items.index_offset()), ) { - if let Err(e) = crate::clipboard::copy_string(&e.hash_short) { - self.queue.push(InternalEvent::ShowErrorMsg( - format!("{}: {}", FAIL_COPY, e), - )); - return Err(e); - } + 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( - format!("{} \"{}\"", SUCCESS_COPY, &e.hash_short), + copy_success(&e.hash_short), )); } } @@ -248,14 +247,16 @@ impl CommitList { if let Some(e) = self.items.iter().nth(self.marked_indexes()[0]) { - if let Err(e) = crate::clipboard::copy_string(&e.hash_short) { - self.queue.push(InternalEvent::ShowErrorMsg( - format!("{}: {}", FAIL_COPY, e), - )); - return Err(e); - } + 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( - format!("{} \"{}\"", SUCCESS_COPY, &e.hash_short), + copy_success(&e.hash_short), )); } } diff --git a/src/strings.rs b/src/strings.rs index bb76aca2b6..ca56fcf0ab 100644 --- a/src/strings.rs +++ b/src/strings.rs @@ -26,6 +26,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}"; //✓ @@ -348,6 +351,13 @@ 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: String) -> String { + format!("{}: {}", POPUP_FAIL_COPY, e) +} + pub mod commit { use crate::keys::SharedKeyConfig; From e17ee696bb143d7040d9c7b4d2e861a1f5aec7b4 Mon Sep 17 00:00:00 2001 From: Sergio Ribera Date: Sat, 15 Oct 2022 16:28:57 -0400 Subject: [PATCH 5/8] Add error notification in the changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b5c975306f..2fe37adbea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * 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)) * Add notification when correctly copying hash commit ([#1160](https://github.com/extrawurst/gitui/issues/1160)) +* Add a notification with details when the copy throws an error ### Fixes * remove insecure dependency `ansi_term` ([#1290](https://github.com/extrawurst/gitui/issues/1290)) From fefd64a8ac515626f32623ef21e577cf6b526c67 Mon Sep 17 00:00:00 2001 From: Sergio Ribera Date: Tue, 18 Oct 2022 18:11:59 -0400 Subject: [PATCH 6/8] correct format --- src/components/commitlist.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/commitlist.rs b/src/components/commitlist.rs index a67da4d4a8..0d0ab5af3e 100644 --- a/src/components/commitlist.rs +++ b/src/components/commitlist.rs @@ -214,8 +214,9 @@ impl CommitList { .join(" "); if let Err(e) = crate::clipboard::copy_string(&separate) { - self.queue - .push(InternalEvent::ShowErrorMsg(copy_fail(e.to_string()))); + self.queue.push(InternalEvent::ShowErrorMsg( + copy_fail(e.to_string()), + )); return Err(e); } self.queue.push(InternalEvent::ShowInfoMsg( From 4e659e76989aada312e6c0a32b8a9b47a07c0ee3 Mon Sep 17 00:00:00 2001 From: Sergio Ribera Date: Wed, 19 Oct 2022 18:51:14 -0400 Subject: [PATCH 7/8] Fix clippy String to &str --- src/components/commitlist.rs | 8 ++++---- src/strings.rs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/components/commitlist.rs b/src/components/commitlist.rs index d24d1dc8ee..bb84c16869 100644 --- a/src/components/commitlist.rs +++ b/src/components/commitlist.rs @@ -184,7 +184,7 @@ impl CommitList { format!("{}^..{}", f.hash_short, l.hash_short); if let Err(e) = crate::clipboard::copy_string(&yank) { self.queue.push(InternalEvent::ShowErrorMsg( - copy_fail(e.to_string()), + copy_fail(&e.to_string()), )); return Err(e); } @@ -208,7 +208,7 @@ impl CommitList { if let Err(e) = crate::clipboard::copy_string(&separate) { self.queue.push(InternalEvent::ShowErrorMsg( - copy_fail(e.to_string()), + copy_fail(&e.to_string()), )); return Err(e); } @@ -231,7 +231,7 @@ impl CommitList { crate::clipboard::copy_string(&e.hash_short) { self.queue.push(InternalEvent::ShowErrorMsg( - copy_fail(e.to_string()), + copy_fail(&e.to_string()), )); return Err(e); } @@ -248,7 +248,7 @@ impl CommitList { crate::clipboard::copy_string(&e.hash_short) { self.queue.push(InternalEvent::ShowErrorMsg( - copy_fail(e.to_string()), + copy_fail(&e.to_string()), )); return Err(e); } diff --git a/src/strings.rs b/src/strings.rs index fb8e55b601..ea602f7cea 100644 --- a/src/strings.rs +++ b/src/strings.rs @@ -354,7 +354,7 @@ pub fn rename_branch_popup_msg( pub fn copy_success(s: &str) -> String { format!("{} \"{}\"", POPUP_SUCCESS_COPY, s) } -pub fn copy_fail(e: String) -> String { +pub fn copy_fail(e: &str) -> String { format!("{}: {}", POPUP_FAIL_COPY, e) } From 9517491d4975d9dade28cf6c688ebfa83993dd5f Mon Sep 17 00:00:00 2001 From: Sergio Ribera Date: Mon, 24 Oct 2022 23:14:01 -0400 Subject: [PATCH 8/8] Fix clippy error with string format --- src/strings.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/strings.rs b/src/strings.rs index 703a581a91..47bf594a09 100644 --- a/src/strings.rs +++ b/src/strings.rs @@ -357,11 +357,11 @@ pub fn rename_branch_popup_msg( } pub fn copy_success(s: &str) -> String { - format!("{} \"{}\"", POPUP_SUCCESS_COPY, s) + format!("{POPUP_SUCCESS_COPY} \"{s}\"") } pub fn copy_fail(e: &str) -> String { - format!("{}: {}", POPUP_FAIL_COPY, e) + format!("{POPUP_FAIL_COPY}: {e}") } pub fn ellipsis_trim_start(s: &str, width: usize) -> Cow {