2023-10-06 22:35:27 -07:00
|
|
|
//! Welcome Window
|
2022-12-29 18:00:59 -08:00
|
|
|
use std::ops::{Deref, DerefMut};
|
|
|
|
|
2024-02-27 21:21:05 -08:00
|
|
|
use ratatui::{buffer::Buffer, layout::Rect};
|
2022-12-29 18:00:59 -08:00
|
|
|
|
2024-02-27 21:21:05 -08:00
|
|
|
use modalkit_ratatui::{textbox::TextBoxState, TermOffset, TerminalCursor, WindowOps};
|
2022-12-29 18:00:59 -08:00
|
|
|
|
2023-03-01 18:46:33 -08:00
|
|
|
use modalkit::editing::completion::CompletionList;
|
2024-02-27 21:21:05 -08:00
|
|
|
use modalkit::prelude::*;
|
2022-12-29 18:00:59 -08:00
|
|
|
|
2023-03-01 18:46:33 -08:00
|
|
|
use crate::base::{IambBufferId, IambInfo, IambResult, ProgramStore};
|
2022-12-29 18:00:59 -08:00
|
|
|
|
|
|
|
const WELCOME_TEXT: &str = include_str!("welcome.md");
|
|
|
|
|
|
|
|
pub struct WelcomeState {
|
|
|
|
tbox: TextBoxState<IambInfo>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl WelcomeState {
|
|
|
|
pub fn new(store: &mut ProgramStore) -> Self {
|
|
|
|
let buf = store.buffers.load_str(IambBufferId::Welcome, WELCOME_TEXT);
|
2023-01-03 13:57:28 -08:00
|
|
|
let mut tbox = TextBoxState::new(buf);
|
|
|
|
tbox.set_readonly(true);
|
2022-12-29 18:00:59 -08:00
|
|
|
|
2023-01-03 13:57:28 -08:00
|
|
|
WelcomeState { tbox }
|
2022-12-29 18:00:59 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Deref for WelcomeState {
|
|
|
|
type Target = TextBoxState<IambInfo>;
|
|
|
|
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
|
|
return &self.tbox;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl DerefMut for WelcomeState {
|
|
|
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
|
|
|
return &mut self.tbox;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TerminalCursor for WelcomeState {
|
|
|
|
fn get_term_cursor(&self) -> Option<TermOffset> {
|
|
|
|
self.tbox.get_term_cursor()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl WindowOps<IambInfo> for WelcomeState {
|
|
|
|
fn draw(&mut self, area: Rect, buf: &mut Buffer, focused: bool, store: &mut ProgramStore) {
|
|
|
|
self.tbox.draw(area, buf, focused, store)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn dup(&self, store: &mut ProgramStore) -> Self {
|
|
|
|
let tbox = self.tbox.dup(store);
|
|
|
|
|
|
|
|
WelcomeState { tbox }
|
|
|
|
}
|
|
|
|
|
|
|
|
fn close(&mut self, flags: CloseFlags, store: &mut ProgramStore) -> bool {
|
|
|
|
self.tbox.close(flags, store)
|
|
|
|
}
|
|
|
|
|
2023-03-01 18:46:33 -08:00
|
|
|
fn write(
|
|
|
|
&mut self,
|
|
|
|
path: Option<&str>,
|
|
|
|
flags: WriteFlags,
|
|
|
|
store: &mut ProgramStore,
|
|
|
|
) -> IambResult<EditInfo> {
|
|
|
|
self.tbox.write(path, flags, store)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_completions(&self) -> Option<CompletionList> {
|
|
|
|
self.tbox.get_completions()
|
|
|
|
}
|
|
|
|
|
2022-12-29 18:00:59 -08:00
|
|
|
fn get_cursor_word(&self, style: &WordStyle) -> Option<String> {
|
|
|
|
self.tbox.get_cursor_word(style)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_selected_word(&self) -> Option<String> {
|
|
|
|
self.tbox.get_selected_word()
|
|
|
|
}
|
|
|
|
}
|