diff --git a/src/main.rs b/src/main.rs
index d989b81..7ee8bd1 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,24 +1,24 @@
//! A simple CLI app for displaying rich 24 hour time information for multiple
-//! people and/or time zones.
+//! locations.
mod config;
+mod message;
+mod model;
+mod update;
+mod view;
use std::{ffi::OsString, io, time::Duration};
-use chrono::{NaiveTime, TimeDelta, Timelike, Utc, offset::LocalResult};
-use chrono_tz::Tz;
use clap::Parser;
-use crossterm::event::{self, Event, KeyCode, KeyEvent, KeyEventKind, KeyModifiers};
-use ratatui::{
- DefaultTerminal,
- prelude::*,
- symbols::border,
- widgets::{Block, BorderType::Rounded, Cell, Padding, Row, Table, TableState},
-};
-use ratatui_textarea::{Input, TextArea};
-use unidecode::unidecode;
+use crossterm::event::{self, Event, KeyCode, KeyEventKind, KeyModifiers};
+use ratatui::DefaultTerminal;
-use crate::config::{Config, Location};
+use crate::{
+ config::Config,
+ message::Message,
+ model::{FocusState, Model, RunningState},
+ view::view,
+};
/// A simple CLI app for displaying rich 24 hour time information for multiple
/// people and/or time zones.
@@ -40,70 +40,42 @@ fn main() -> color_eyre::Result<()> {
/// TUI render loop.
fn run(terminal: &mut DefaultTerminal, config: Config) -> color_eyre::Result<()> {
let mut model = Model::from_config(config);
-
while model.running_state != RunningState::Done {
- terminal.draw(|f| view(&mut model, f))?;
-
- // Handle events and map to a Message
- let mut current_msg = handle_event(&model)?;
-
+ model.update_loop(Some(Message::TimeProgressed))?;
+ terminal.draw(|frame| view(&mut model, frame))?;
// Process updates as long as they return a non-None message
- while current_msg.is_some() {
- current_msg = update(&mut model, current_msg.unwrap());
- }
+ model.update_loop(handle_event(&model)?)?;
}
-
Ok(())
}
-/// App-wide Elm model.
-#[derive(Debug)]
-struct Model<'a> {
- config: Config,
- table_state: TableState,
- running_state: RunningState,
- focus_state: FocusState,
- filter_textarea: TextArea<'a>,
-}
-
-impl<'a> Model<'a> {
- fn from_config(config: Config) -> Self {
- Self {
- config,
- table_state: Default::default(),
- running_state: Default::default(),
- focus_state: Default::default(),
- filter_textarea: Default::default(),
- }
- }
-}
-
-#[derive(Debug, Default, Eq, PartialEq)]
-enum RunningState {
- #[default]
- Running,
- Done,
-}
-
-#[derive(Debug, Default, Eq, PartialEq)]
-enum FocusState {
- #[default]
- Table,
- Filter,
-}
-
-enum Message {
- Quit,
- FilterOpened,
- FilterCancelled,
- FilterUpdated(Input),
-}
-
+/// Momentarily block until a crossterm event is detected or the internal
+/// timeout expires.
fn handle_event(model: &Model) -> io::Result