src/windows/welcome.rs

86 lines · 2146 bytes

 1//! Welcome Window
 2
 3use modalkit_ratatui::textbox::{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, _: bool, store: &mut ProgramStore) {
49        self.tbox.set_ignorecase(store.application.settings.tunables.ignorecase);
50
51        // Render textbox:
52        let style = store.application.settings.theme.default;
53        TextBox::new().style(style).render(area, buf, &mut self.tbox)
54    }
55
56    fn dup(&self, store: &mut ProgramStore) -> Self {
57        let tbox = self.tbox.dup(store);
58
59        WelcomeState { tbox }
60    }
61
62    fn close(&mut self, flags: CloseFlags, store: &mut ProgramStore) -> bool {
63        self.tbox.close(flags, store)
64    }
65
66    fn write(
67        &mut self,
68        path: Option<&str>,
69        flags: WriteFlags,
70        store: &mut ProgramStore,
71    ) -> IambResult<EditInfo> {
72        self.tbox.write(path, flags, store)
73    }
74
75    fn get_completions(&self) -> Option<CompletionList> {
76        self.tbox.get_completions()
77    }
78
79    fn get_cursor_word(&self, style: &WordStyle) -> Option<String> {
80        self.tbox.get_cursor_word(style)
81    }
82
83    fn get_selected_word(&self) -> Option<String> {
84        self.tbox.get_selected_word()
85    }
86}