aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
blob: 7d94fe9f4c3a8f9dbceccbf36f554fbb18310a44 (plain) (blame)
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
mod checks;
mod display;
mod table;
mod ynab;

fn main() {
    let key = std::env::args().nth(1).unwrap();
    let client = ynab::Client::new(&key);
    let budget = client.default_budget();

    checks::run_checks(&budget);

    let mut app = cursive::Cursive::default();
    app.set_theme(display::theme());
    app.add_global_callback('q', |s| s.quit());

    let mut layout = cursive::views::LinearLayout::vertical();
    layout.add_child(cursive::views::TextView::new(format!(
        "Budget: {} ({})",
        budget.name(),
        budget.id()
    )));

    let inflows_table = table::inflows_table(&budget);
    layout.add_child(cursive::views::CircularFocus::wrap_arrows(
        cursive::views::BoxView::with_min_height(
            std::cmp::min(std::cmp::max(inflows_table.len(), 1), 5) + 2,
            cursive::views::BoxView::with_full_width(inflows_table),
        ),
    ));

    let outflows_table = table::outflows_table(&budget);
    layout.add_child(cursive::views::CircularFocus::wrap_arrows(
        cursive::views::BoxView::with_full_screen(outflows_table),
    ));

    app.add_fullscreen_layer(layout);
    app.run();
}