src/windows/welcome.rs

83 lines · 2031 bytes

 1//! Welcome Window
 2
 3use modalkit_ratatui::textbox::TextBoxState;
 4
 5use crate::prelude::*;
 6
 7const WELCOME_TEXT: &str = include_str!("welcome.md");
 8
 9pub struct WelcomeState {
10    tbox: TextBoxState<IambInfo>,
11}
12
13impl WelcomeState {
14    pub fn new(store: &mut ProgramStore) -> Self {
15        let buf = store.buffers.load_str(IambBufferId::Welcome, WELCOME_TEXT);
16        let mut tbox = TextBoxState::new(buf);
17        tbox.set_readonly(true);
18
19        WelcomeState { tbox }
20    }
21}
22
23impl Deref for WelcomeState {
24    type Target = TextBoxState<IambInfo>;
25
26    fn deref(&self) -> &Self::Target {
27        return &self.tbox;
28    }
29}
30
31impl DerefMut for WelcomeState {
32    fn deref_mut(&mut self) -> &mut Self::Target {
33        return &mut self.tbox;
34    }
35}
36
37impl TerminalCursor for WelcomeState {
38    fn get_term_cursor(&self) -> Option<TermOffset> {
39        self.tbox.get_term_cursor()
40    }
41
42    fn hide_term_cursor(&self) -> bool {
43        self.tbox.hide_term_cursor()
44    }
45}
46
47impl WindowOps<IambInfo> for WelcomeState {
48    fn draw(&mut self, area: Rect, buf: &mut Buffer, focused: bool, store: &mut ProgramStore) {
49        self.tbox.set_ignorecase(store.application.settings.tunables.ignorecase);
50        self.tbox.draw(area, buf, focused, store)
51    }
52
53    fn dup(&self, store: &mut ProgramStore) -> Self {
54        let tbox = self.tbox.dup(store);
55
56        WelcomeState { tbox }
57    }
58
59    fn close(&mut self, flags: CloseFlags, store: &mut ProgramStore) -> bool {
60        self.tbox.close(flags, store)
61    }
62
63    fn write(
64        &mut self,
65        path: Option<&str>,
66        flags: WriteFlags,
67        store: &mut ProgramStore,
68    ) -> IambResult<EditInfo> {
69        self.tbox.write(path, flags, store)
70    }
71
72    fn get_completions(&self) -> Option<CompletionList> {
73        self.tbox.get_completions()
74    }
75
76    fn get_cursor_word(&self, style: &WordStyle) -> Option<String> {
77        self.tbox.get_cursor_word(style)
78    }
79
80    fn get_selected_word(&self) -> Option<String> {
81        self.tbox.get_selected_word()
82    }
83}