use crate::model::config::Strategy;
use crate::tui::screens::ButtonScreen;
use crate::tui::widgets::{ButtonDef, KeyResult};
use super::{ForgeChoice, InitResult, Screen, WizardState};
pub(crate) struct GitStrategyButtons {
pub(crate) strategy: Strategy,
}
impl ButtonScreen for GitStrategyButtons {
type State = WizardState;
type Result = InitResult;
type FullScreen = Screen;
fn question(&self) -> String {
crate::t!("git-strategy-question")
}
fn buttons(&self) -> Vec<ButtonDef> {
vec![
ButtonDef {
label: crate::t!("button-push"),
selected: self.strategy == Strategy::Push,
color: None,
},
ButtonDef {
label: crate::t!("button-branch"),
selected: self.strategy == Strategy::Branch,
color: None,
},
]
}
fn next(self) -> Self {
let strategy = match self.strategy {
Strategy::Push => Strategy::Branch,
Strategy::Branch => Strategy::Push,
};
GitStrategyButtons { strategy }
}
fn prev(self) -> Self {
self.next()
}
fn with_index(self, index: usize) -> Self {
let strategy = if index == 0 {
Strategy::Push
} else {
Strategy::Branch
};
GitStrategyButtons { strategy }
}
fn into_continue(self, state: WizardState) -> (WizardState, Screen) {
(state, Screen::GitStrategy(self.strategy))
}
fn on_confirm(
self,
mut state: WizardState,
) -> anyhow::Result<KeyResult<(WizardState, Screen), InitResult>> {
state.git_strategy = Some(self.strategy);
let default = match self.strategy {
Strategy::Push => ForgeChoice::Neither,
Strategy::Branch => ForgeChoice::GitHub,
};
Ok(KeyResult::Continue((state, Screen::ChooseForge(default))))
}
}