aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2019-08-12 03:48:17 -0400
committerJesse Luehrs <doy@tozt.net>2019-08-12 03:48:17 -0400
commit16edecef23a3c8f965b9310527eb731ba0b5bf7a (patch)
tree31c4a59fb0970045efb4090fda026c0e40ae31a8
parent3d8778962b4a380efd098616ac49b6dedd2b8fbe (diff)
downloadynab-reimbursements-16edecef23a3c8f965b9310527eb731ba0b5bf7a.tar.gz
ynab-reimbursements-16edecef23a3c8f965b9310527eb731ba0b5bf7a.zip
add some more headers with information
-rw-r--r--src/main.rs6
-rw-r--r--src/views/txn_table.rs25
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<TxnColumn>
@@ -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),