Skip to content

Commit 4932690

Browse files
committed
refactor: move checkout_option_to_string into CheckoutOptions::to_string_pair
1 parent 6bdece1 commit 4932690

File tree

2 files changed

+28
-27
lines changed

2 files changed

+28
-27
lines changed

src/popups/checkout_option.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::components::{
33
DrawableComponent, EventState,
44
};
55
use crate::queue::{InternalEvent, NeedsUpdate};
6-
use crate::strings::{checkout_option_to_string, CheckoutOptions};
6+
use crate::strings::CheckoutOptions;
77
use crate::try_or_popup;
88
use crate::{
99
app::Environment,
@@ -43,7 +43,7 @@ impl CheckoutOptionPopup {
4343
queue: env.queue.clone(),
4444
repo: env.repo.borrow().clone(),
4545
branch: None,
46-
option: CheckoutOptions::StashAndReapply,
46+
option: CheckoutOptions::KeepLocalChanges,
4747
visible: false,
4848
key_config: env.key_config.clone(),
4949
theme: env.theme.clone(),
@@ -64,8 +64,7 @@ impl CheckoutOptionPopup {
6464
),
6565
]));
6666

67-
let (kind_name, kind_desc) =
68-
checkout_option_to_string(self.option);
67+
let (kind_name, kind_desc) = self.option.to_string_pair();
6968

7069
txt.push(Line::from(vec![
7170
Span::styled(
@@ -108,7 +107,7 @@ impl CheckoutOptionPopup {
108107

109108
fn handle_event(&mut self) -> Result<()> {
110109
match self.option {
111-
CheckoutOptions::StashAndReapply => {
110+
CheckoutOptions::KeepLocalChanges => {
112111
let stash_id =
113112
stash_save(&self.repo, None, true, false)?;
114113
self.checkout()?;
@@ -133,21 +132,21 @@ impl CheckoutOptionPopup {
133132
fn change_kind(&mut self, incr: bool) {
134133
self.option = if incr {
135134
match self.option {
136-
CheckoutOptions::StashAndReapply => {
135+
CheckoutOptions::KeepLocalChanges => {
137136
CheckoutOptions::Unchange
138137
}
139138
CheckoutOptions::Unchange => CheckoutOptions::Discard,
140139
CheckoutOptions::Discard => {
141-
CheckoutOptions::StashAndReapply
140+
CheckoutOptions::KeepLocalChanges
142141
}
143142
}
144143
} else {
145144
match self.option {
146-
CheckoutOptions::StashAndReapply => {
145+
CheckoutOptions::KeepLocalChanges => {
147146
CheckoutOptions::Discard
148147
}
149148
CheckoutOptions::Unchange => {
150-
CheckoutOptions::StashAndReapply
149+
CheckoutOptions::KeepLocalChanges
151150
}
152151
CheckoutOptions::Discard => CheckoutOptions::Unchange,
153152
}

src/strings.rs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -440,29 +440,31 @@ pub fn ellipsis_trim_start(s: &str, width: usize) -> Cow<'_, str> {
440440

441441
#[derive(PartialEq, Eq, Clone, Copy)]
442442
pub enum CheckoutOptions {
443-
StashAndReapply,
443+
KeepLocalChanges,
444444
Unchange,
445445
Discard,
446446
}
447447

448-
pub const fn checkout_option_to_string(
449-
kind: CheckoutOptions,
450-
) -> (&'static str, &'static str) {
451-
const CHECKOUT_OPTION_STASH_AND_REAPPLY: &str =
452-
" 🟢 Stash and reapply changes";
453-
const CHECKOUT_OPTION_UNCHANGE: &str = " 🟡 Keep local changes";
454-
const CHECKOUT_OPTION_DISCARD: &str =
455-
" 🔴 Discard all local changes";
448+
impl CheckoutOptions {
449+
pub fn to_string_pair(&self) -> (&'static str, &'static str) {
450+
const CHECKOUT_OPTION_STASH_AND_REAPPLY: &str =
451+
" 🟢 Stash and reapply changes";
452+
const CHECKOUT_OPTION_UNCHANGE: &str =
453+
" 🟡 Keep local changes";
454+
const CHECKOUT_OPTION_DISCARD: &str =
455+
" 🔴 Discard all local changes";
456456

457-
match kind {
458-
CheckoutOptions::StashAndReapply => {
459-
("Stash and reapply", CHECKOUT_OPTION_STASH_AND_REAPPLY)
460-
}
461-
CheckoutOptions::Unchange => {
462-
("Don't change", CHECKOUT_OPTION_UNCHANGE)
463-
}
464-
CheckoutOptions::Discard => {
465-
("Discard", CHECKOUT_OPTION_DISCARD)
457+
match self {
458+
CheckoutOptions::KeepLocalChanges => (
459+
"Stash and reapply",
460+
CHECKOUT_OPTION_STASH_AND_REAPPLY,
461+
),
462+
CheckoutOptions::Unchange => {
463+
("Don't change", CHECKOUT_OPTION_UNCHANGE)
464+
}
465+
CheckoutOptions::Discard => {
466+
("Discard", CHECKOUT_OPTION_DISCARD)
467+
}
466468
}
467469
}
468470
}

0 commit comments

Comments
 (0)