use hjkl_engine::{CursorShape, Host, Viewport};
use std::time::Instant;
pub struct FormFieldHost {
last_cursor_shape: CursorShape,
started: Instant,
clipboard: Option<String>,
viewport: Viewport,
}
impl FormFieldHost {
pub fn new() -> Self {
Self {
last_cursor_shape: CursorShape::Block,
started: Instant::now(),
clipboard: None,
viewport: Viewport {
top_row: 0,
top_col: 0,
width: 40,
height: 1,
..Viewport::default()
},
}
}
pub fn cursor_shape(&self) -> CursorShape {
self.last_cursor_shape
}
}
impl Default for FormFieldHost {
fn default() -> Self {
Self::new()
}
}
impl Host for FormFieldHost {
type Intent = ();
fn write_clipboard(&mut self, text: String) {
self.clipboard = Some(text);
}
fn read_clipboard(&mut self) -> Option<String> {
self.clipboard.clone()
}
fn now(&self) -> std::time::Duration {
self.started.elapsed()
}
fn prompt_search(&mut self) -> Option<String> {
None
}
fn emit_cursor_shape(&mut self, shape: CursorShape) {
self.last_cursor_shape = shape;
}
fn emit_intent(&mut self, _intent: Self::Intent) {}
fn viewport(&self) -> &Viewport {
&self.viewport
}
fn viewport_mut(&mut self) -> &mut Viewport {
&mut self.viewport
}
}