From a83d921f4906eacadeb259bbb213ebfe26190e8b Mon Sep 17 00:00:00 2001 From: Akshay Date: Wed, 11 Mar 2020 18:21:13 +0530 Subject: add config cruft --- src/main.rs | 96 +++++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 65 insertions(+), 31 deletions(-) diff --git a/src/main.rs b/src/main.rs index 5115aab..bec4536 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,52 +2,86 @@ use chrono::NaiveDate; +use lazy_static::lazy_static; + //use cursive::views::{Dialog, EditView, LinearLayout, ListView, SelectView}; +use cursive::theme::{BaseColor, Color}; use cursive::Cursive; mod habit; -use crate::habit::{Habit, HabitTrait, HabitType}; - -mod views; -use crate::views::habitview::HabitView; +use crate::habit::{Bit, Count, Habit}; mod app; mod theme; use crate::app::{App, ViewMode}; +mod views; + +pub struct AppConfig { + pub true_chr: char, + pub false_chr: char, + pub future_chr: char, + + // view dimensions + pub view_width: usize, + pub view_height: usize, + + // app dimensions + pub grid_width: usize, + + // color config + pub reached_color: Color, + pub todo_color: Color, + pub future_color: Color, +} + +lazy_static! { + pub static ref CONFIGURATION: AppConfig = load_configuration_file(); +} + +fn load_configuration_file() -> AppConfig { + return AppConfig { + true_chr: '·', + false_chr: '·', + future_chr: '·', + view_width: 25, + view_height: 8, + grid_width: 3, + reached_color: Color::Dark(BaseColor::Cyan), + todo_color: Color::Dark(BaseColor::Magenta), + future_color: Color::Light(BaseColor::Black), + }; +} + fn main() { let mut s = Cursive::default(); - let mut gymming = Habit::new("gym", HabitType::Count(5)); - gymming.insert_entry(NaiveDate::from_ymd(2020, 2, 11), HabitType::Count(7)); - gymming.insert_entry(NaiveDate::from_ymd(2020, 2, 12), HabitType::Count(8)); - gymming.insert_entry(NaiveDate::from_ymd(2020, 2, 13), HabitType::Count(9)); - gymming.insert_entry(NaiveDate::from_ymd(2020, 2, 14), HabitType::Count(10)); - gymming.insert_entry(NaiveDate::from_ymd(2020, 2, 15), HabitType::Count(11)); - - let mut reading = Habit::new("read", HabitType::Bit(true)); - reading.insert_entry(NaiveDate::from_ymd(2020, 2, 11), HabitType::Bit(true)); - reading.insert_entry(NaiveDate::from_ymd(2020, 2, 12), HabitType::Bit(false)); - reading.insert_entry(NaiveDate::from_ymd(2020, 2, 13), HabitType::Bit(true)); - reading.insert_entry(NaiveDate::from_ymd(2020, 2, 14), HabitType::Bit(false)); - reading.insert_entry(NaiveDate::from_ymd(2020, 2, 15), HabitType::Bit(true)); - - let mut walking = Habit::new("walk", HabitType::Bit(true)); - walking.insert_entry(NaiveDate::from_ymd(2020, 2, 11), HabitType::Bit(true)); - walking.insert_entry(NaiveDate::from_ymd(2020, 2, 12), HabitType::Bit(false)); - walking.insert_entry(NaiveDate::from_ymd(2020, 2, 13), HabitType::Bit(true)); - walking.insert_entry(NaiveDate::from_ymd(2020, 2, 14), HabitType::Bit(false)); - walking.insert_entry(NaiveDate::from_ymd(2020, 2, 15), HabitType::Bit(true)); - - let gym_view = HabitView::new(gymming); - let read_view = HabitView::new(reading); - let walk_view = HabitView::new(walking); + let mut gymming = Count::new("gym", 5); + gymming.insert_entry(NaiveDate::from_ymd(2020, 3, 11), 7); + gymming.insert_entry(NaiveDate::from_ymd(2020, 3, 12), 8); + gymming.insert_entry(NaiveDate::from_ymd(2020, 3, 13), 9); + gymming.insert_entry(NaiveDate::from_ymd(2020, 3, 14), 10); + gymming.insert_entry(NaiveDate::from_ymd(2020, 3, 15), 11); + + let mut reading = Bit::new("read"); + reading.insert_entry(NaiveDate::from_ymd(2020, 3, 11), true.into()); + reading.insert_entry(NaiveDate::from_ymd(2020, 3, 12), false.into()); + reading.insert_entry(NaiveDate::from_ymd(2020, 3, 13), true.into()); + reading.insert_entry(NaiveDate::from_ymd(2020, 3, 14), false.into()); + reading.insert_entry(NaiveDate::from_ymd(2020, 3, 15), true.into()); + + let mut walking = Bit::new("walk"); + walking.insert_entry(NaiveDate::from_ymd(2020, 3, 11), true.into()); + walking.insert_entry(NaiveDate::from_ymd(2020, 3, 12), false.into()); + walking.insert_entry(NaiveDate::from_ymd(2020, 3, 13), true.into()); + walking.insert_entry(NaiveDate::from_ymd(2020, 3, 14), false.into()); + walking.insert_entry(NaiveDate::from_ymd(2020, 3, 15), true.into()); s.add_global_callback('q', |a| a.quit()); let app = App::new() - .add_habit(gym_view) - .add_habit(read_view) - .add_habit(walk_view) + .add_habit(Box::new(gymming)) + .add_habit(Box::new(reading)) + .add_habit(Box::new(walking)) .set_mode(ViewMode::Month); s.add_layer(app); -- cgit v1.2.3