use std::io; use crossterm::event::{self, Event, KeyCode, KeyEvent, KeyEventKind}; use ratatui::{ buffer::Buffer, layout::{Alignment, Constraint, Direction, Layout, Rect}, style::Stylize, symbols::border, text::Text, widgets::{block::Title, Block, Borders, Paragraph, Widget}, Frame }; use crate::{tui, model::Task}; use self::{footer::Footer, tasks::TaskList}; mod footer; mod tasks; #[derive(Debug, Default)] pub struct App { exit: bool, } impl App { pub fn run(&mut self, terminal: &mut tui::Tui) -> io::Result<()> { while !self.exit { terminal.draw(|frame| self.render_frame(frame))?; self.handle_events()?; } Ok(()) } fn render_frame(&self, frame: &mut Frame) { frame.render_widget(self, frame.size()); } fn handle_events(&mut self) -> io::Result<()> { match event::read()?{ Event::Key(key_event) if key_event.kind == KeyEventKind::Press => { self.handle_key_event(key_event); } _ => () } Ok(()) } pub fn exit(&mut self) { self.exit = true; } fn handle_key_event(&mut self, event: KeyEvent) { match event.code { KeyCode::Char('q') => self.exit(), _ => () } } } impl Widget for &App { fn render(self, area: Rect, buf: &mut Buffer) { let chunks = Layout::default() .direction(Direction::Vertical) .constraints([ Constraint::Min(1), Constraint::Length(1), ]) .split(area); TaskList::new(&vec![ Task::new(1, 1, "Hej", "Hej med dig hvordan går det"), Task::new(2, 1, "Lul", "Hej med dig hvordan går det"), Task::new(3, 1, "Hvordan lige", ""), Task::new(4, 1, "Hej med dig", ""), ]).render(chunks[0], buf); Footer::new().render(chunks[1], buf); } }