#![cfg(FALSE)]
use crate::core::{Runtime, Msg, Effect};
use crate::app::AppState;
use crate::services::GitService;
use std::sync::Arc;
runtime: Runtime,
}
pub fn new(git_service: Arc<GitService>, repo_path: String) -> Self {
Self {
runtime: Runtime::new(git_service, repo_path),
}
}
pub fn dispatch_sync(&mut self, state: &mut AppState, msg: Msg) {
let _effect = crate::core::update(state, msg.clone());
self.runtime.action_logger_mut().log_action(&msg, false);
}
pub fn action_to_msg(action: &crate::app::Action) -> Option<Msg> {
use crate::app::Action;
match action {
Action::Tick => Some(Msg::Tick),
Action::Quit => Some(Msg::RequestQuit),
Action::ToggleHelp => Some(Msg::ToggleHelp),
Action::ShowThemePicker => Some(Msg::ShowThemePicker),
Action::HideThemePicker => Some(Msg::HideThemePicker),
Action::SetFeedback(msg) => Some(Msg::SetFeedback {
message: msg.clone()
}),
Action::FocusNext => Some(Msg::FocusNext),
Action::FocusPrev => Some(Msg::FocusPrev),
Action::StartCommit => Some(Msg::StartCommitInput),
Action::CancelCommit => Some(Msg::CancelCommitInput),
Action::SetCommitInput(text) => Some(Msg::UpdateCommitInput {
text: text.clone()
}),
_ => None,
}
}
pub fn action_stats(&self) -> std::collections::HashMap<String, usize> {
self.runtime.action_logger().action_stats()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_action_to_msg_mapping() {
use crate::app::Action;
assert!(matches!(
TeaBridge::action_to_msg(&Action::Tick),
Some(Msg::Tick)
));
assert!(matches!(
TeaBridge::action_to_msg(&Action::ToggleHelp),
Some(Msg::ToggleHelp)
));
assert!(matches!(
TeaBridge::action_to_msg(&Action::Quit),
Some(Msg::RequestQuit)
));
}
}