anathema_testutils/
lib.rs

1use std::marker::PhantomData;
2
3use anathema::component::*;
4
5#[derive(Debug, State, Default)]
6pub struct BasicState {
7    pub boolean: Value<bool>,
8    pub number: Value<u32>,
9    pub string: Value<String>,
10}
11
12pub struct BasicComp<F, T>(F, PhantomData<T>);
13
14impl<F, T> BasicComp<F, T> {
15    pub fn new(f: F) -> Self {
16        Self(f, PhantomData)
17    }
18}
19
20impl<F, T> Component for BasicComp<F, T>
21where
22    F: FnMut(KeyEvent, &mut T, Children<'_, '_>, Context<'_, '_, T>) + 'static,
23    T: State,
24{
25    type Message = ();
26    type State = T;
27
28    fn on_key(
29        &mut self,
30        key: KeyEvent,
31        state: &mut Self::State,
32        children: Children<'_, '_>,
33        context: Context<'_, '_, Self::State>,
34    ) {
35        self.0(key, state, children, context);
36    }
37}
38
39pub fn character(c: char) -> KeyEvent {
40    KeyEvent {
41        code: KeyCode::Char(c),
42        ctrl: false,
43        state: KeyState::Press,
44    }
45}
46
47pub fn tab() -> KeyEvent {
48    KeyEvent {
49        code: KeyCode::Tab,
50        ctrl: false,
51        state: KeyState::Press,
52    }
53}