use std::borrow::Cow;
use crossterm::event::{KeyEvent, MouseEvent};
use crate::input::Command;
pub mod picker;
pub mod help;
pub mod tag_picker;
#[derive(Debug)]
pub struct OverlayFrame {
pub body: Vec<String>,
pub status: String,
}
#[derive(Debug)]
pub enum OverlayOutcome {
Stay,
Close,
CloseAnd(Command),
Apply(Command),
Refuse(&'static str),
}
pub struct OverlayContext<'a> {
pub file_set: &'a crate::file_set::FileSet,
}
pub trait Overlay {
fn handle_key(&mut self, key: KeyEvent) -> OverlayOutcome;
fn handle_mouse(&mut self, _ev: MouseEvent, _body_rows: u16) -> OverlayOutcome {
OverlayOutcome::Stay
}
fn render(&self, width: u16, height: u16) -> OverlayFrame;
fn title(&self) -> Cow<'_, str>;
fn refresh(&mut self, _ctx: OverlayContext) {}
}
#[cfg(test)]
mod tests {
use super::*;
struct Noop;
impl Overlay for Noop {
fn handle_key(&mut self, _k: KeyEvent) -> OverlayOutcome { OverlayOutcome::Close }
fn render(&self, _w: u16, _h: u16) -> OverlayFrame {
OverlayFrame { body: vec![], status: String::new() }
}
fn title(&self) -> Cow<'_, str> { Cow::Borrowed("noop") }
}
#[test]
fn overlay_trait_is_object_safe() {
let _: Box<dyn Overlay> = Box::new(Noop);
}
}