Skip to content

Commit bb78714

Browse files
committed
♻️ refactor: add more feature gating
1 parent cb20254 commit bb78714

File tree

2 files changed

+86
-38
lines changed

2 files changed

+86
-38
lines changed

src/popups/conventional_commit.rs

Lines changed: 85 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ enum CommitType {
5050
CI,
5151
}
5252

53+
#[cfg(feature = "gitmoji")]
5354
#[derive(Copy, Clone)]
5455
enum MoreInfoCommit {
5556
/// 🎨
@@ -150,6 +151,7 @@ enum MoreInfoCommit {
150151
Validation,
151152
}
152153

154+
#[cfg(feature = "gitmoji")]
153155
impl MoreInfoCommit {
154156
const fn strings(
155157
self,
@@ -237,6 +239,7 @@ impl MoreInfoCommit {
237239
}
238240
}
239241

242+
#[cfg(feature = "gitmoji")]
240243
impl CommitType {
241244
#[allow(clippy::pedantic)]
242245
fn more_info(&self) -> Vec<MoreInfoCommit> {
@@ -358,6 +361,7 @@ pub struct ConventionalCommitPopup {
358361
selected_index: usize,
359362
options: Vec<CommitType>,
360363
query_results_type: Vec<CommitType>,
364+
#[cfg(feature = "gitmoji")]
361365
query_results_more_info: Vec<MoreInfoCommit>,
362366
input: TextInputComponent,
363367
theme: SharedTheme,
@@ -377,6 +381,7 @@ impl ConventionalCommitPopup {
377381
input,
378382
options: CommitType::iter().collect_vec(),
379383
query_results_type: CommitType::iter().collect_vec(),
384+
#[cfg(feature = "gitmoji")]
380385
query_results_more_info: Vec::new(),
381386
is_insert: false,
382387
is_breaking: false,
@@ -396,30 +401,48 @@ impl ConventionalCommitPopup {
396401

397402
let quick_shortcuts = self.quick_shortcuts();
398403

399-
let title = format!(
400-
"Results: {}",
401-
if self.seleted_commit_type.is_some() {
402-
self.query_results_more_info.len()
403-
} else {
404+
let results = {
405+
#[cfg(feature = "gitmoji")]
406+
{
407+
if self.seleted_commit_type.is_some() {
408+
self.query_results_more_info.len()
409+
} else {
410+
self.query_results_type.len()
411+
}
412+
}
413+
#[cfg(not(feature = "gitmoji"))]
414+
{
404415
self.query_results_type.len()
405416
}
406-
);
417+
};
418+
419+
let title = format!("Results: {results}",);
407420

408421
let iter_over = if self.seleted_commit_type.is_some() {
409-
self.query_results_more_info
410-
.iter()
411-
.enumerate()
412-
.take(height)
413-
.map(|(idx, more_info)| {
414-
let (emoji, _, long_name) = more_info.strings();
415-
let text_string = format!("{emoji} {long_name}");
416-
let text = trim_length_left(&text_string, width);
417-
(
418-
self.selected_index == idx,
419-
format!("{text}{:width$}", " "),
420-
)
421-
})
422-
.collect_vec()
422+
#[cfg(feature = "gitmoji")]
423+
{
424+
self.query_results_more_info
425+
.iter()
426+
.enumerate()
427+
.take(height)
428+
.map(|(idx, more_info)| {
429+
let (emoji, _, long_name) =
430+
more_info.strings();
431+
let text_string =
432+
format!("{emoji} {long_name}");
433+
let text =
434+
trim_length_left(&text_string, width);
435+
(
436+
self.selected_index == idx,
437+
format!("{text}{:width$}", " "),
438+
)
439+
})
440+
.collect_vec()
441+
}
442+
#[cfg(not(feature = "gitmoji"))]
443+
{
444+
vec![]
445+
}
423446
} else {
424447
let max_len = self
425448
.query_results_type
@@ -516,7 +539,14 @@ impl ConventionalCommitPopup {
516539
let new_selection = new_selection.clamp(
517540
0,
518541
if self.seleted_commit_type.is_some() {
519-
self.query_results_more_info.len()
542+
#[cfg(feature = "gitmoji")]
543+
{
544+
self.query_results_more_info.len()
545+
}
546+
#[cfg(not(feature = "gitmoji"))]
547+
{
548+
self.query_results_type.len()
549+
}
520550
} else {
521551
self.query_results_type.len()
522552
}
@@ -544,20 +574,29 @@ impl ConventionalCommitPopup {
544574
let new_len = if let Some(commit_type) =
545575
&self.seleted_commit_type
546576
{
547-
self.query_results_more_info = commit_type
548-
.more_info()
549-
.iter()
550-
.filter(|more_info_commit| {
551-
more_info_commit
552-
.strings()
553-
.2
554-
.to_lowercase()
555-
.contains(&query)
556-
})
557-
.copied()
558-
.collect_vec();
577+
#[cfg(feature = "gitmoji")]
578+
{
579+
self.query_results_more_info = commit_type
580+
.more_info()
581+
.iter()
582+
.filter(|more_info_commit| {
583+
more_info_commit
584+
.strings()
585+
.2
586+
.to_lowercase()
587+
.contains(&query)
588+
})
589+
.copied()
590+
.collect_vec();
559591

560-
self.query_results_more_info.len()
592+
self.query_results_more_info.len()
593+
}
594+
#[cfg(not(feature = "gitmoji"))]
595+
{
596+
let _ = commit_type;
597+
self.hide();
598+
self.query_results_type.len()
599+
}
561600
} else {
562601
self.query_results_type = self
563602
.options
@@ -641,9 +680,14 @@ impl DrawableComponent for ConventionalCommitPopup {
641680
.borders(Borders::all())
642681
.style(self.theme.title(true))
643682
.title(Span::styled(
644-
if self.seleted_commit_type.is_some() {
645-
strings::POPUP_TITLE_GITMOJI
646-
} else {
683+
{
684+
#[cfg(feature = "gitmoji")]
685+
if self.seleted_commit_type.is_some() {
686+
strings::POPUP_TITLE_GITMOJI
687+
} else {
688+
strings::POPUP_TITLE_CONVENTIONAL_COMMIT
689+
}
690+
#[cfg(not(feature = "gitmoji"))]
647691
strings::POPUP_TITLE_CONVENTIONAL_COMMIT
648692
},
649693
self.theme.title(true),
@@ -835,7 +879,10 @@ impl Component for ConventionalCommitPopup {
835879
self.is_visible = false;
836880
self.seleted_commit_type = None;
837881
self.query_results_type = CommitType::iter().collect_vec();
838-
self.query_results_more_info = Vec::new();
882+
#[cfg(feature = "gitmoji")]
883+
{
884+
self.query_results_more_info.clear();
885+
}
839886
}
840887

841888
fn show(&mut self) -> Result<()> {

src/strings.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub static PUSH_POPUP_STATES_PUSHING: &str = "pushing (3/3)";
2424
pub static PUSH_POPUP_STATES_TRANSFER: &str = "transfer";
2525
pub static PUSH_POPUP_STATES_DONE: &str = "done";
2626
pub const POPUP_TITLE_CONVENTIONAL_COMMIT: &str = "Type of Commit";
27+
#[cfg(feature = "gitmoji")]
2728
pub const POPUP_TITLE_GITMOJI: &str = "Emoji of Commit";
2829

2930
pub static PUSH_TAGS_POPUP_MSG: &str = "Push Tags";

0 commit comments

Comments
 (0)