summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.rs22
-rw-r--r--src/model/mod.rs3
-rw-r--r--src/model/task.rs20
-rw-r--r--src/render.rs73
-rw-r--r--src/render/footer.rs20
-rw-r--r--src/render/tasks.rs34
-rw-r--r--src/tui.rs24
7 files changed, 0 insertions, 196 deletions
diff --git a/src/main.rs b/src/main.rs
deleted file mode 100644
index 39e81c9..0000000
--- a/src/main.rs
+++ /dev/null
@@ -1,22 +0,0 @@
-
-use render::App;
-use sqlx::{self, Connection, SqliteConnection};
-
-use std::error::Error;
-
-mod tui;
-mod render;
-mod model;
-
-
-#[tokio::main]
-async fn main() -> Result<(), Box<dyn Error>> {
- let mut conn = SqliteConnection::connect("sqlite::memory:").await?;
-
- let mut terminal = tui::init()?;
- let res = App::default().run(&mut terminal);
- tui::restore()?;
-
- res?;
- Ok(())
-}
diff --git a/src/model/mod.rs b/src/model/mod.rs
deleted file mode 100644
index d869a4f..0000000
--- a/src/model/mod.rs
+++ /dev/null
@@ -1,3 +0,0 @@
-mod task;
-
-pub use task::Task;
diff --git a/src/model/task.rs b/src/model/task.rs
deleted file mode 100644
index e90dd8e..0000000
--- a/src/model/task.rs
+++ /dev/null
@@ -1,20 +0,0 @@
-
-use sqlx::FromRow;
-
-#[derive(Debug, FromRow)]
-pub struct Task {
- pub id: i64,
- pub group_id: i64,
- pub name: String,
- pub description: String,
-}
-
-impl Task {
- pub fn new(id: i64, group_id: i64, name: &str, description: &str) -> Task {
- Task {
- id, group_id,
- name: String::from(name),
- description: String::from(description),
- }
- }
-}
diff --git a/src/render.rs b/src/render.rs
deleted file mode 100644
index d1d5f19..0000000
--- a/src/render.rs
+++ /dev/null
@@ -1,73 +0,0 @@
-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);
- }
-}
diff --git a/src/render/footer.rs b/src/render/footer.rs
deleted file mode 100644
index 9e74de8..0000000
--- a/src/render/footer.rs
+++ /dev/null
@@ -1,20 +0,0 @@
-use ratatui::{style::{Modifier, Style}, widgets::{Paragraph, Widget}};
-
-
-#[derive(Debug, Default)]
-pub struct Footer;
-
-impl Footer {
- pub fn new() -> Footer {
- return Footer {}
- }
-}
-
-impl Widget for &Footer {
-
- fn render(self, area: ratatui::prelude::Rect, buf: &mut ratatui::prelude::Buffer) {
- Paragraph::new("hellow")
- .style(Style::default().add_modifier(Modifier::REVERSED))
- .render(area, buf);
- }
-}
diff --git a/src/render/tasks.rs b/src/render/tasks.rs
deleted file mode 100644
index 0f6a79a..0000000
--- a/src/render/tasks.rs
+++ /dev/null
@@ -1,34 +0,0 @@
-use ratatui::{layout::Constraint, widgets::{Row, Table, Widget}, prelude::Text};
-
-use crate::model::Task;
-
-
-
-#[derive(Debug)]
-pub struct TaskList<'a> {
- tasks: &'a[Task]
-}
-
-impl<'a> TaskList<'a> {
- pub fn new(tasks: &'a[Task]) -> TaskList<'a> {
- TaskList {
- tasks
- }
- }
-}
-
-impl<'a> Widget for &TaskList<'a> {
- fn render(self, area: ratatui::prelude::Rect, buf: &mut ratatui::prelude::Buffer) {
- let rows: Vec<Row> = self.tasks.into_iter()
- .map(|t: &Task| Row::new(vec![Text::from(t.name.as_str()), Text::from(t.description.as_str())]))
- .collect();
-
- let widths = [
- Constraint::Percentage(50),
- Constraint::Fill(1),
- ];
-
- Table::new(rows, widths)
- .render(area, buf);
- }
-}
diff --git a/src/tui.rs b/src/tui.rs
deleted file mode 100644
index 7bae1ab..0000000
--- a/src/tui.rs
+++ /dev/null
@@ -1,24 +0,0 @@
-use crossterm::{execute, terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen}};
-
-use ratatui::{
- prelude::CrosstermBackend,
- Terminal,
-};
-
-use std::io::{self, stdout, Stdout};
-
-
-pub type Tui = Terminal<CrosstermBackend<Stdout>>;
-
-pub fn init() -> io::Result<Tui> {
- execute!(stdout(), EnterAlternateScreen)?;
- enable_raw_mode()?;
- Terminal::new(CrosstermBackend::new(stdout()))
-}
-
-pub fn restore() -> io::Result<()> {
- execute!(stdout(), LeaveAlternateScreen)?;
- disable_raw_mode()?;
-
- Ok(())
-}