src/windows/welcome.rs
71 lines · 1734 bytes
1use std::ops::{Deref, DerefMut};
2
3use modalkit::tui::{buffer::Buffer, layout::Rect};
4
5use modalkit::{
6 widgets::textbox::TextBoxState,
7 widgets::WindowOps,
8 widgets::{TermOffset, TerminalCursor},
9};
10
11use modalkit::editing::base::{CloseFlags, WordStyle};
12
13use crate::base::{IambBufferId, IambInfo, ProgramStore};
14
15const WELCOME_TEXT: &str = include_str!("welcome.md");
16
17pub struct WelcomeState {
18 tbox: TextBoxState<IambInfo>,
19}
20
21impl WelcomeState {
22 pub fn new(store: &mut ProgramStore) -> Self {
23 let buf = store.buffers.load_str(IambBufferId::Welcome, WELCOME_TEXT);
24
25 WelcomeState { tbox: TextBoxState::new(buf) }
26 }
27}
28
29impl Deref for WelcomeState {
30 type Target = TextBoxState<IambInfo>;
31
32 fn deref(&self) -> &Self::Target {
33 return &self.tbox;
34 }
35}
36
37impl DerefMut for WelcomeState {
38 fn deref_mut(&mut self) -> &mut Self::Target {
39 return &mut self.tbox;
40 }
41}
42
43impl TerminalCursor for WelcomeState {
44 fn get_term_cursor(&self) -> Option<TermOffset> {
45 self.tbox.get_term_cursor()
46 }
47}
48
49impl WindowOps<IambInfo> for WelcomeState {
50 fn draw(&mut self, area: Rect, buf: &mut Buffer, focused: bool, store: &mut ProgramStore) {
51 self.tbox.draw(area, buf, focused, store)
52 }
53
54 fn dup(&self, store: &mut ProgramStore) -> Self {
55 let tbox = self.tbox.dup(store);
56
57 WelcomeState { tbox }
58 }
59
60 fn close(&mut self, flags: CloseFlags, store: &mut ProgramStore) -> bool {
61 self.tbox.close(flags, store)
62 }
63
64 fn get_cursor_word(&self, style: &WordStyle) -> Option<String> {
65 self.tbox.get_cursor_word(style)
66 }
67
68 fn get_selected_word(&self) -> Option<String> {
69 self.tbox.get_selected_word()
70 }
71}