From 16edecef23a3c8f965b9310527eb731ba0b5bf7a Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Mon, 12 Aug 2019 03:48:17 -0400 Subject: add some more headers with information --- src/main.rs | 6 ++++-- src/views/txn_table.rs | 25 +++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 7d19af4..bd9bc07 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,14 +11,16 @@ fn main() { checks::run_checks(&budget); let mut app = cursive::Cursive::default(); + let cursive::XY { x: term_width, .. } = app.screen_size(); 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: {} ({})\n{}", budget.name(), - budget.id() + budget.id(), + "=".repeat(term_width), ))); layout.add_child(views::txn_tables(&budget)); diff --git a/src/views/txn_table.rs b/src/views/txn_table.rs index ef72ac7..e1ecfa6 100644 --- a/src/views/txn_table.rs +++ b/src/views/txn_table.rs @@ -25,6 +25,17 @@ impl TableView { pub fn len(&self) -> usize { self.view.get_inner().with_view(|v| v.len()).unwrap() } + + // XXX why does borrow_items require &mut self? + pub fn amount(&mut self) -> i64 { + self.view + .get_inner_mut() + .get_mut() + .borrow_items() + .iter() + .map(|t| t.amount) + .sum() + } } impl cursive_table_view::TableViewItem @@ -138,7 +149,12 @@ fn txn_table( pub fn txn_tables(budget: &crate::ynab::Budget) -> impl cursive::view::View { let mut layout = cursive::views::LinearLayout::vertical(); - let inflows_table = inflows_table(&budget); + let mut inflows_table = inflows_table(&budget); + layout.add_child(cursive::views::TextView::new(format!( + "\nInflows: {} ({} transactions)", + crate::ynab::format_amount(inflows_table.amount()), + inflows_table.len() + ))); layout.add_child(crate::views::vi_view( cursive::views::CircularFocus::wrap_arrows( cursive::views::BoxView::with_min_height( @@ -148,7 +164,12 @@ pub fn txn_tables(budget: &crate::ynab::Budget) -> impl cursive::view::View { ), )); - let outflows_table = outflows_table(&budget); + let mut outflows_table = outflows_table(&budget); + layout.add_child(cursive::views::TextView::new(format!( + "\nOutflows: {} ({} transactions)", + crate::ynab::format_amount(outflows_table.amount()), + outflows_table.len() + ))); layout.add_child(crate::views::vi_view( cursive::views::CircularFocus::wrap_arrows( cursive::views::BoxView::with_full_screen(outflows_table), -- cgit v1.2.3-54-g00ecf