Skip to content

Add notification when correctly copying hash commit #1376

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Oct 26, 2022
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
50 changes: 45 additions & 5 deletions src/components/commitlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};
Expand Down Expand Up @@ -41,6 +42,7 @@ pub struct CommitList {
current_size: Cell<(u16, u16)>,
scroll_top: Cell<usize>,
theme: SharedTheme,
queue: Queue,
key_config: SharedKeyConfig,
}

Expand All @@ -49,6 +51,7 @@ impl CommitList {
pub fn new(
title: &str,
theme: SharedTheme,
queue: Queue,
key_config: SharedKeyConfig,
) -> Self {
Self {
Expand All @@ -62,6 +65,7 @@ impl CommitList {
current_size: Cell::new((0, 0)),
scroll_top: Cell::new(0),
theme,
queue,
key_config,
title: title.into(),
}
Expand Down Expand Up @@ -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
Expand All @@ -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(())
Expand All @@ -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),
));
}
}
_ => {}
Expand Down
11 changes: 11 additions & 0 deletions src/strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}"; //✓
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/tabs/revlog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ impl Revlog {
list: CommitList::new(
&strings::log_title(&key_config),
theme,
queue.clone(),
key_config.clone(),
),
git_log: AsyncLog::new(
Expand Down
1 change: 1 addition & 0 deletions src/tabs/stashlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ impl StashList {
list: CommitList::new(
&strings::stashlist_title(&key_config),
theme,
queue.clone(),
key_config.clone(),
),
queue: queue.clone(),
Expand Down