aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
blob: bec4536ab2fd09494222f7e34b1cba919cc6d9bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#![allow(unused_must_use)]

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::{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 = 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(Box::new(gymming))
        .add_habit(Box::new(reading))
        .add_habit(Box::new(walking))
        .set_mode(ViewMode::Month);

    s.add_layer(app);

    s.set_theme(theme::theme_gen());
    s.run();
}