use reovim_kernel::api::v1::ModeId;
pub use crate::transition::{PopResult, TransitionContext};
pub trait ModeApi: Send {
fn current_mode(&self) -> &ModeId;
fn home_mode(&self) -> &ModeId;
fn mode_depth(&self) -> usize;
fn is_mode_active(&self, mode: &ModeId) -> bool;
fn mode_stack(&self) -> Vec<ModeId>;
fn push_mode(&mut self, mode: ModeId, ctx: TransitionContext);
fn pop_mode(&mut self, result: Option<PopResult>) -> Result<(), ModeError>;
fn set_mode(&mut self, mode: ModeId, ctx: TransitionContext);
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ModeError {
CannotPopHomeMode,
}
impl std::fmt::Display for ModeError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::CannotPopHomeMode => write!(f, "cannot pop home mode"),
}
}
}
impl std::error::Error for ModeError {}
#[cfg(test)]
#[path = "tests/mode.rs"]
mod tests;