thedes_tui_core/runtime/device/
null.rs

1use crate::{
2    input::{self, device::InputDevice},
3    panic::{self, restore::PanicRestoreGuard},
4    screen::{self, device::ScreenDevice},
5};
6
7use super::{Error, RuntimeDevice};
8
9pub fn open() -> Box<dyn RuntimeDevice> {
10    Box::new(NullRuntimeDevice::new())
11}
12
13#[derive(Debug)]
14struct NullRuntimeDevice {
15    initialized: bool,
16}
17
18impl NullRuntimeDevice {
19    pub fn new() -> Self {
20        Self { initialized: false }
21    }
22}
23
24impl RuntimeDevice for NullRuntimeDevice {
25    fn blocking_init(&mut self) -> Result<(), Error> {
26        if self.initialized {
27            Err(Error::AlreadyInit)?
28        }
29        self.initialized = true;
30        Ok(())
31    }
32
33    fn blocking_shutdown(&mut self) -> Result<(), Error> {
34        if !self.initialized {
35            Err(Error::NotInit)?
36        }
37        self.initialized = false;
38        Ok(())
39    }
40
41    fn open_input_device(&mut self) -> Box<dyn InputDevice> {
42        input::device::null::open()
43    }
44
45    fn open_screen_device(&mut self) -> Box<dyn ScreenDevice> {
46        screen::device::null::open()
47    }
48
49    fn open_panic_restore_guard(&mut self) -> Box<dyn PanicRestoreGuard> {
50        panic::restore::null::open()
51    }
52}