diff options
author | Jesse Luehrs <doy@tozt.net> | 2019-08-12 00:27:25 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2019-08-12 00:27:25 -0400 |
commit | 7d2e68156630af27539448a05347d6c55555c6ba (patch) | |
tree | 96334dd0bc345efef5b8243c8423dcada7f1b67c /src/table.rs | |
parent | ca12c28f744c34b27c57dd832ac5f713eff61ab4 (diff) | |
download | ynab-reimbursements-7d2e68156630af27539448a05347d6c55555c6ba.tar.gz ynab-reimbursements-7d2e68156630af27539448a05347d6c55555c6ba.zip |
add vi key bindings
Diffstat (limited to 'src/table.rs')
-rw-r--r-- | src/table.rs | 64 |
1 files changed, 0 insertions, 64 deletions
diff --git a/src/table.rs b/src/table.rs deleted file mode 100644 index 531d1e8..0000000 --- a/src/table.rs +++ /dev/null @@ -1,64 +0,0 @@ -#[derive(Clone, Copy, Eq, Hash, PartialEq)] -pub enum TxnColumn { - Date, - Payee, - Amount, -} - -type TableView = - cursive_table_view::TableView<super::ynab::Transaction, TxnColumn>; - -impl cursive_table_view::TableViewItem<TxnColumn> - for super::ynab::Transaction -{ - fn to_column(&self, column: TxnColumn) -> String { - match column { - TxnColumn::Date => self.date.clone(), - TxnColumn::Payee => self.payee.clone(), - TxnColumn::Amount => super::ynab::format_amount(self.amount), - } - } - - fn cmp(&self, other: &Self, column: TxnColumn) -> std::cmp::Ordering - where - Self: Sized, - { - match column { - TxnColumn::Date => self.date.cmp(&other.date), - TxnColumn::Payee => self.payee.cmp(&other.payee), - TxnColumn::Amount => self.amount.cmp(&other.amount), - } - } -} - -pub fn inflows_table(budget: &super::ynab::Budget) -> TableView { - let inflows = budget - .reimbursables() - .iter() - .filter(|t| !t.reimbursed && t.amount > 0) - .cloned() - .collect(); - txn_table(inflows) -} - -pub fn outflows_table(budget: &super::ynab::Budget) -> TableView { - let outflows = budget - .reimbursables() - .iter() - .filter(|t| !t.reimbursed && t.amount <= 0) - .cloned() - .collect(); - txn_table(outflows) -} - -fn txn_table(txns: Vec<super::ynab::Transaction>) -> TableView { - let mut table = cursive_table_view::TableView::new() - .column(TxnColumn::Date, "Date", |c| c.width(10)) - .column(TxnColumn::Payee, "Payee", |c| c) - .column(TxnColumn::Amount, "Amount", |c| { - c.align(cursive::align::HAlign::Right).width(10) - }) - .default_column(TxnColumn::Date); - table.set_items(txns); - table -} |