Skip to content
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

Make gh-emoji optional #954

Merged
merged 1 commit into from
Nov 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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"]

Expand Down
17 changes: 17 additions & 0 deletions src/components/utils/emoji.rs
Original file line number Diff line number Diff line change
@@ -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;
}
}
9 changes: 7 additions & 2 deletions src/components/utils/logitems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -27,9 +28,12 @@ impl From<CommitInfo> 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 {
Expand Down Expand Up @@ -113,6 +117,7 @@ impl ItemBatch {
}

#[cfg(test)]
#[cfg(feature = "ghemoji")]
mod tests {
use super::*;

Expand Down
19 changes: 2 additions & 17 deletions src/components/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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()
Expand Down