diff --git a/CHANGELOG.md b/CHANGELOG.md index 4707ef2d96..dd2869b695 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - support merging and rebasing remote branches ([#920](https://github.com/extrawurst/gitui/issues/920)) - add highlighting matches in fuzzy finder ([#893](https://github.com/extrawurst/gitui/issues/893)) - support `home` and `end` keys in branchlist ([#957](https://github.com/extrawurst/gitui/issues/957)) +- add `ghemoji` feature to make gh-emoji (GitHub emoji) optional ([#954](https://github.com/extrawurst/gitui/pull/954)) ## Fixed - honor options (for untracked files) in `stage_all` command ([#933](https://github.com/extrawurst/gitui/issues/933)) diff --git a/Cargo.toml b/Cargo.toml index c075a4324a..0c15212fba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,7 +47,7 @@ easy-cast = "0.4" bugreport = "0.4" lazy_static = "1.4" syntect = { version = "4.5", default-features = false, features = ["metadata", "default-fancy"]} -gh-emoji = "1.0.6" +gh-emoji = { version = "1.0.6", optional = true } fuzzy-matcher = "0.3" [target.'cfg(all(target_family="unix",not(target_os="macos")))'.dependencies] @@ -64,7 +64,8 @@ pretty_assertions = "1.0" maintenance = { status = "actively-developed" } [features] -default=["trace-libgit"] +default=["ghemoji", "trace-libgit"] +ghemoji=["gh-emoji"] timing=["scopetime/enabled"] trace-libgit=["asyncgit/trace-libgit"] diff --git a/src/components/utils/emoji.rs b/src/components/utils/emoji.rs new file mode 100644 index 0000000000..4d158cb916 --- /dev/null +++ b/src/components/utils/emoji.rs @@ -0,0 +1,17 @@ +use lazy_static::lazy_static; +use std::borrow::Cow; + +lazy_static! { + static ref EMOJI_REPLACER: gh_emoji::Replacer = + gh_emoji::Replacer::new(); +} + +// Replace markdown emojis with Unicode equivalent +// :hammer: --> 🔨 +#[inline] +pub fn emojifi_string(s: &mut String) { + let resulting_cow = EMOJI_REPLACER.replace_all(s); + if let Cow::Owned(altered_s) = resulting_cow { + *s = altered_s; + } +} diff --git a/src/components/utils/logitems.rs b/src/components/utils/logitems.rs index 67b83a9aec..a87a96f0b2 100644 --- a/src/components/utils/logitems.rs +++ b/src/components/utils/logitems.rs @@ -2,7 +2,8 @@ use asyncgit::sync::{CommitId, CommitInfo}; use chrono::{DateTime, Duration, Local, NaiveDateTime, Utc}; use std::slice::Iter; -use crate::components::utils::emojifi_string; +#[cfg(feature = "ghemoji")] +use super::emoji::emojifi_string; static SLICE_OFFSET_RELOAD_THRESHOLD: usize = 100; @@ -27,9 +28,12 @@ impl From for LogEntry { Utc, )); - // Replace markdown emojis with Unicode equivalent let author = c.author; + #[allow(unused_mut)] let mut msg = c.message; + + // Replace markdown emojis with Unicode equivalent + #[cfg(feature = "ghemoji")] emojifi_string(&mut msg); Self { @@ -113,6 +117,7 @@ impl ItemBatch { } #[cfg(test)] +#[cfg(feature = "ghemoji")] mod tests { use super::*; diff --git a/src/components/utils/mod.rs b/src/components/utils/mod.rs index da2208ae2f..2041346f71 100644 --- a/src/components/utils/mod.rs +++ b/src/components/utils/mod.rs @@ -1,8 +1,8 @@ use chrono::{DateTime, Local, NaiveDateTime, Utc}; -use lazy_static::lazy_static; -use std::borrow::Cow; use unicode_width::UnicodeWidthStr; +#[cfg(feature = "ghemoji")] +pub mod emoji; pub mod filetree; pub mod logitems; pub mod scroll_vertical; @@ -55,21 +55,6 @@ pub fn string_width_align(s: &str, width: usize) -> String { } } -lazy_static! { - static ref EMOJI_REPLACER: gh_emoji::Replacer = - gh_emoji::Replacer::new(); -} - -// Replace markdown emojis with Unicode equivalent -// :hammer: --> 🔨 -#[inline] -pub fn emojifi_string(s: &mut String) { - let resulting_cow = EMOJI_REPLACER.replace_all(s); - if let Cow::Owned(altered_s) = resulting_cow { - *s = altered_s; - } -} - #[inline] fn find_truncate_point(s: &str, chars: usize) -> usize { s.chars().take(chars).map(char::len_utf8).sum()