aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.rs96
1 files 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 @@
2 2
3use chrono::NaiveDate; 3use chrono::NaiveDate;
4 4
5use lazy_static::lazy_static;
6
5//use cursive::views::{Dialog, EditView, LinearLayout, ListView, SelectView}; 7//use cursive::views::{Dialog, EditView, LinearLayout, ListView, SelectView};
8use cursive::theme::{BaseColor, Color};
6use cursive::Cursive; 9use cursive::Cursive;
7 10
8mod habit; 11mod habit;
9use crate::habit::{Habit, HabitTrait, HabitType}; 12use crate::habit::{Bit, Count, Habit};
10
11mod views;
12use crate::views::habitview::HabitView;
13 13
14mod app; 14mod app;
15mod theme; 15mod theme;
16use crate::app::{App, ViewMode}; 16use crate::app::{App, ViewMode};
17 17
18mod views;
19
20pub struct AppConfig {
21 pub true_chr: char,
22 pub false_chr: char,
23 pub future_chr: char,
24
25 // view dimensions
26 pub view_width: usize,
27 pub view_height: usize,
28
29 // app dimensions
30 pub grid_width: usize,
31
32 // color config
33 pub reached_color: Color,
34 pub todo_color: Color,
35 pub future_color: Color,
36}
37
38lazy_static! {
39 pub static ref CONFIGURATION: AppConfig = load_configuration_file();
40}
41
42fn load_configuration_file() -> AppConfig {
43 return AppConfig {
44 true_chr: '·',
45 false_chr: '·',
46 future_chr: '·',
47 view_width: 25,
48 view_height: 8,
49 grid_width: 3,
50 reached_color: Color::Dark(BaseColor::Cyan),
51 todo_color: Color::Dark(BaseColor::Magenta),
52 future_color: Color::Light(BaseColor::Black),
53 };
54}
55
18fn main() { 56fn main() {
19 let mut s = Cursive::default(); 57 let mut s = Cursive::default();
20 58
21 let mut gymming = Habit::new("gym", HabitType::Count(5)); 59 let mut gymming = Count::new("gym", 5);
22 gymming.insert_entry(NaiveDate::from_ymd(2020, 2, 11), HabitType::Count(7)); 60 gymming.insert_entry(NaiveDate::from_ymd(2020, 3, 11), 7);
23 gymming.insert_entry(NaiveDate::from_ymd(2020, 2, 12), HabitType::Count(8)); 61 gymming.insert_entry(NaiveDate::from_ymd(2020, 3, 12), 8);
24 gymming.insert_entry(NaiveDate::from_ymd(2020, 2, 13), HabitType::Count(9)); 62 gymming.insert_entry(NaiveDate::from_ymd(2020, 3, 13), 9);
25 gymming.insert_entry(NaiveDate::from_ymd(2020, 2, 14), HabitType::Count(10)); 63 gymming.insert_entry(NaiveDate::from_ymd(2020, 3, 14), 10);
26 gymming.insert_entry(NaiveDate::from_ymd(2020, 2, 15), HabitType::Count(11)); 64 gymming.insert_entry(NaiveDate::from_ymd(2020, 3, 15), 11);
27 65
28 let mut reading = Habit::new("read", HabitType::Bit(true)); 66 let mut reading = Bit::new("read");
29 reading.insert_entry(NaiveDate::from_ymd(2020, 2, 11), HabitType::Bit(true)); 67 reading.insert_entry(NaiveDate::from_ymd(2020, 3, 11), true.into());
30 reading.insert_entry(NaiveDate::from_ymd(2020, 2, 12), HabitType::Bit(false)); 68 reading.insert_entry(NaiveDate::from_ymd(2020, 3, 12), false.into());
31 reading.insert_entry(NaiveDate::from_ymd(2020, 2, 13), HabitType::Bit(true)); 69 reading.insert_entry(NaiveDate::from_ymd(2020, 3, 13), true.into());
32 reading.insert_entry(NaiveDate::from_ymd(2020, 2, 14), HabitType::Bit(false)); 70 reading.insert_entry(NaiveDate::from_ymd(2020, 3, 14), false.into());
33 reading.insert_entry(NaiveDate::from_ymd(2020, 2, 15), HabitType::Bit(true)); 71 reading.insert_entry(NaiveDate::from_ymd(2020, 3, 15), true.into());
34 72
35 let mut walking = Habit::new("walk", HabitType::Bit(true)); 73 let mut walking = Bit::new("walk");
36 walking.insert_entry(NaiveDate::from_ymd(2020, 2, 11), HabitType::Bit(true)); 74 walking.insert_entry(NaiveDate::from_ymd(2020, 3, 11), true.into());
37 walking.insert_entry(NaiveDate::from_ymd(2020, 2, 12), HabitType::Bit(false)); 75 walking.insert_entry(NaiveDate::from_ymd(2020, 3, 12), false.into());
38 walking.insert_entry(NaiveDate::from_ymd(2020, 2, 13), HabitType::Bit(true)); 76 walking.insert_entry(NaiveDate::from_ymd(2020, 3, 13), true.into());
39 walking.insert_entry(NaiveDate::from_ymd(2020, 2, 14), HabitType::Bit(false)); 77 walking.insert_entry(NaiveDate::from_ymd(2020, 3, 14), false.into());
40 walking.insert_entry(NaiveDate::from_ymd(2020, 2, 15), HabitType::Bit(true)); 78 walking.insert_entry(NaiveDate::from_ymd(2020, 3, 15), true.into());
41
42 let gym_view = HabitView::new(gymming);
43 let read_view = HabitView::new(reading);
44 let walk_view = HabitView::new(walking);
45 79
46 s.add_global_callback('q', |a| a.quit()); 80 s.add_global_callback('q', |a| a.quit());
47 let app = App::new() 81 let app = App::new()
48 .add_habit(gym_view) 82 .add_habit(Box::new(gymming))
49 .add_habit(read_view) 83 .add_habit(Box::new(reading))
50 .add_habit(walk_view) 84 .add_habit(Box::new(walking))
51 .set_mode(ViewMode::Month); 85 .set_mode(ViewMode::Month);
52 86
53 s.add_layer(app); 87 s.add_layer(app);