diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 22 | ||||
-rw-r--r-- | src/views.rs | 18 | ||||
-rw-r--r-- | src/views/txn_table.rs (renamed from src/table.rs) | 12 |
3 files changed, 37 insertions, 15 deletions
diff --git a/src/main.rs b/src/main.rs index 7d94fe9..358a842 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ mod checks; mod display; -mod table; +mod views; mod ynab; fn main() { @@ -21,17 +21,21 @@ fn main() { 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 inflows_table = views::inflows_table(&budget); + layout.add_child(views::vi_view( + 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), + let outflows_table = views::outflows_table(&budget); + layout.add_child(views::vi_view( + cursive::views::CircularFocus::wrap_arrows( + cursive::views::BoxView::with_full_screen(outflows_table), + ), )); app.add_fullscreen_layer(layout); diff --git a/src/views.rs b/src/views.rs new file mode 100644 index 0000000..b6846b8 --- /dev/null +++ b/src/views.rs @@ -0,0 +1,18 @@ +mod txn_table; +pub use txn_table::{inflows_table, outflows_table}; + +pub fn vi_view<V: cursive::view::View>(v: V) -> impl cursive::view::View { + cursive::views::OnEventView::new(v) + .on_event('h', |s| { + s.on_event(cursive::event::Event::Key(cursive::event::Key::Left)) + }) + .on_event('j', |s| { + s.on_event(cursive::event::Event::Key(cursive::event::Key::Down)) + }) + .on_event('k', |s| { + s.on_event(cursive::event::Event::Key(cursive::event::Key::Up)) + }) + .on_event('l', |s| { + s.on_event(cursive::event::Event::Key(cursive::event::Key::Right)) + }) +} diff --git a/src/table.rs b/src/views/txn_table.rs index 531d1e8..7773e30 100644 --- a/src/table.rs +++ b/src/views/txn_table.rs @@ -6,16 +6,16 @@ pub enum TxnColumn { } type TableView = - cursive_table_view::TableView<super::ynab::Transaction, TxnColumn>; + cursive_table_view::TableView<crate::ynab::Transaction, TxnColumn>; impl cursive_table_view::TableViewItem<TxnColumn> - for super::ynab::Transaction + for crate::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), + TxnColumn::Amount => crate::ynab::format_amount(self.amount), } } @@ -31,7 +31,7 @@ impl cursive_table_view::TableViewItem<TxnColumn> } } -pub fn inflows_table(budget: &super::ynab::Budget) -> TableView { +pub fn inflows_table(budget: &crate::ynab::Budget) -> TableView { let inflows = budget .reimbursables() .iter() @@ -41,7 +41,7 @@ pub fn inflows_table(budget: &super::ynab::Budget) -> TableView { txn_table(inflows) } -pub fn outflows_table(budget: &super::ynab::Budget) -> TableView { +pub fn outflows_table(budget: &crate::ynab::Budget) -> TableView { let outflows = budget .reimbursables() .iter() @@ -51,7 +51,7 @@ pub fn outflows_table(budget: &super::ynab::Budget) -> TableView { txn_table(outflows) } -fn txn_table(txns: Vec<super::ynab::Transaction>) -> TableView { +fn txn_table(txns: Vec<crate::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) |