applied clippy
This commit is contained in:
parent
52e46f737e
commit
057cdb02c0
10 changed files with 82 additions and 52 deletions
|
@ -97,3 +97,9 @@ impl<'a> States<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a> Default for States<'a> {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ impl DB {
|
||||||
transactions.append(&mut temp_transactions);
|
transactions.append(&mut temp_transactions);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok(());
|
Ok(())
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ impl DB {
|
||||||
transactions.append(&mut temp_transactions);
|
transactions.append(&mut temp_transactions);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok(());
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_all_buckets(&mut self) -> Result<(), Error> {
|
pub async fn get_all_buckets(&mut self) -> Result<(), Error> {
|
||||||
|
@ -85,6 +85,6 @@ impl DB {
|
||||||
transactions.append(&mut temp_transactions);
|
transactions.append(&mut temp_transactions);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok(());
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,12 @@ impl DataCache {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return None;
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for DataCache {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use core::fmt;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
||||||
use sqlx::{postgres::types::PgMoney, FromRow};
|
use sqlx::{postgres::types::PgMoney, FromRow};
|
||||||
|
@ -76,19 +77,21 @@ pub struct PartialTransaction {
|
||||||
|
|
||||||
impl Transaction {
|
impl Transaction {
|
||||||
pub fn get_header() -> String {
|
pub fn get_header() -> String {
|
||||||
return format!(" {:<7} | {:<9} | {:<10}", "Id", "Amount", "Date");
|
format!(" {:<7} | {:<9} | {:<10}", "Id", "Amount", "Date")
|
||||||
}
|
|
||||||
|
|
||||||
pub fn to_string(&self) -> String {
|
|
||||||
return format!(
|
|
||||||
" T{:0>6} | {:>9} | {:>10}",
|
|
||||||
self.trns_id,
|
|
||||||
self.trns_amount.to_decimal(2).to_string(),
|
|
||||||
self.trns_date.to_string()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_str(&self) -> Cow<str> {
|
pub fn as_str(&self) -> Cow<str> {
|
||||||
return self.to_string().into();
|
self.to_string().into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for Transaction {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
write!(f, " T{:0>6} | {:>9} | {:>10}",
|
||||||
|
self.trns_id,
|
||||||
|
self.trns_amount.to_decimal(2).to_string(),
|
||||||
|
self.trns_date.to_string()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
15
src/main.rs
15
src/main.rs
|
@ -55,29 +55,26 @@ pub fn poll_events(app: &mut App) -> AppResult<()> {
|
||||||
// 'q' needs to be handled at the top level so it can't be
|
// 'q' needs to be handled at the top level so it can't be
|
||||||
// accidentally handed to a dead end
|
// accidentally handed to a dead end
|
||||||
if let KeyCode::Char('q') = key.code {
|
if let KeyCode::Char('q') = key.code {
|
||||||
if let Some(_) = app.states.nav_state.message.clone() {
|
if app.states.nav_state.message.is_some() {
|
||||||
app.states.nav_state.message = None;
|
app.states.nav_state.message = None;
|
||||||
} else {
|
} else if let ActiveFrame::Navigation = app.states.active_frame {
|
||||||
if let ActiveFrame::Navigation = app.states.active_frame {
|
|
||||||
app.running = false;
|
app.running = false;
|
||||||
} else {
|
} else {
|
||||||
app.states.active_frame = ActiveFrame::Navigation;
|
app.states.active_frame = ActiveFrame::Navigation;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else if let KeyCode::Esc = key.code {
|
} else if let KeyCode::Esc = key.code {
|
||||||
if let Some(_) = app.states.nav_state.message.clone() {
|
if app.states.nav_state.message.is_some() {
|
||||||
app.states.nav_state.message = None;
|
app.states.nav_state.message = None;
|
||||||
} else {
|
} else if let ActiveFrame::Navigation = app.states.active_frame {
|
||||||
if let ActiveFrame::Navigation = app.states.active_frame {
|
|
||||||
app.running = false;
|
app.running = false;
|
||||||
} else {
|
} else {
|
||||||
app.states.active_frame = ActiveFrame::Navigation;
|
app.states.active_frame = ActiveFrame::Navigation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if let KeyCode::Char('r') = key.code {
|
if let KeyCode::Char('r') = key.code {
|
||||||
app.refresh();
|
app.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
match app.states.active_frame {
|
match app.states.active_frame {
|
||||||
ActiveFrame::Navigation => {
|
ActiveFrame::Navigation => {
|
||||||
NavigationState::handle_event(key, app);
|
NavigationState::handle_event(key, app);
|
||||||
|
@ -93,7 +90,7 @@ pub fn poll_events(app: &mut App) -> AppResult<()> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Ok(());
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init_logger(output_file: String) {
|
pub fn init_logger(output_file: String) {
|
||||||
|
|
12
src/ui.rs
12
src/ui.rs
|
@ -1,8 +1,5 @@
|
||||||
use crate::{
|
// use log;
|
||||||
app::{ActiveFrame, App},
|
|
||||||
uis::{render_history_tab, render_manual_transaction},
|
|
||||||
};
|
|
||||||
use log;
|
|
||||||
use ratatui::{
|
use ratatui::{
|
||||||
backend::Backend,
|
backend::Backend,
|
||||||
layout::{Constraint, Direction, Layout},
|
layout::{Constraint, Direction, Layout},
|
||||||
|
@ -11,7 +8,10 @@ use ratatui::{
|
||||||
Frame,
|
Frame,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::uis::{render_navigation_frame, render_quick_transaction};
|
use crate::{
|
||||||
|
app::{ActiveFrame, App},
|
||||||
|
uis::{render_history_tab, render_manual_transaction, render_navigation_frame, render_quick_transaction},
|
||||||
|
};
|
||||||
|
|
||||||
pub fn render<B: Backend>(f: &mut Frame<B>, app: &mut App) {
|
pub fn render<B: Backend>(f: &mut Frame<B>, app: &mut App) {
|
||||||
let size = f.size();
|
let size = f.size();
|
||||||
|
|
|
@ -55,6 +55,12 @@ impl HistoryState {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for HistoryState {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn render_history_tab<B: Backend>(f: &mut Frame<B>, body_rect: Rect, app: &mut App) {
|
pub fn render_history_tab<B: Backend>(f: &mut Frame<B>, body_rect: Rect, app: &mut App) {
|
||||||
let split_body = Layout::default()
|
let split_body = Layout::default()
|
||||||
.direction(Direction::Horizontal)
|
.direction(Direction::Horizontal)
|
||||||
|
@ -78,14 +84,14 @@ pub fn render_history_tab<B: Backend>(f: &mut Frame<B>, body_rect: Rect, app: &m
|
||||||
lines.push(Line::from(vec![
|
lines.push(Line::from(vec![
|
||||||
Span::styled("Amount: ", ident_style),
|
Span::styled("Amount: ", ident_style),
|
||||||
Span::styled(
|
Span::styled(
|
||||||
format!("{}", selected_item.trns_amount.to_decimal(2).to_string()),
|
selected_item.trns_amount.to_decimal(2).to_string(),
|
||||||
value_style,
|
value_style,
|
||||||
),
|
),
|
||||||
]));
|
]));
|
||||||
lines.push(Line::from(vec![
|
lines.push(Line::from(vec![
|
||||||
Span::styled("Transaction Date: ", ident_style),
|
Span::styled("Transaction Date: ", ident_style),
|
||||||
Span::styled(
|
Span::styled(
|
||||||
format!("{}", selected_item.trns_date.to_string()),
|
selected_item.trns_date.to_string(),
|
||||||
value_style,
|
value_style,
|
||||||
),
|
),
|
||||||
]));
|
]));
|
||||||
|
|
|
@ -14,7 +14,7 @@ use crate::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use chrono::prelude::Local;
|
use chrono::prelude::Local;
|
||||||
use crossterm::event::{KeyCode, KeyEvent, KeyEventKind};
|
use crossterm::event::{KeyCode, KeyEvent};
|
||||||
|
|
||||||
pub struct ManualTransactionState {
|
pub struct ManualTransactionState {
|
||||||
pub focus: Option<ManualDataFocus>,
|
pub focus: Option<ManualDataFocus>,
|
||||||
|
@ -95,7 +95,7 @@ impl ManualTransactionState {
|
||||||
}
|
}
|
||||||
ManualDataFocus::Date => {
|
ManualDataFocus::Date => {
|
||||||
if let Some(ref mut x) = app.states.manual_transactions.date {
|
if let Some(ref mut x) = app.states.manual_transactions.date {
|
||||||
if x.len() == 0 {
|
if x.is_empty() {
|
||||||
x.push_str(&format!("+{}", Local::now().format("%m-%d-%Y")));
|
x.push_str(&format!("+{}", Local::now().format("%m-%d-%Y")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -158,7 +158,7 @@ impl ManualTransactionState {
|
||||||
},
|
},
|
||||||
KeyCode::Char(value) => match app.states.manual_transactions.focus.unwrap() {
|
KeyCode::Char(value) => match app.states.manual_transactions.focus.unwrap() {
|
||||||
ManualDataFocus::Amount => {
|
ManualDataFocus::Amount => {
|
||||||
if value.is_digit(10) || value == '.' {
|
if value.is_ascii_digit() || value == '.' {
|
||||||
if let Some(ref mut s) = app.states.manual_transactions.amount {
|
if let Some(ref mut s) = app.states.manual_transactions.amount {
|
||||||
s.push(value);
|
s.push(value);
|
||||||
} else {
|
} else {
|
||||||
|
@ -174,7 +174,7 @@ impl ManualTransactionState {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ManualDataFocus::Date => {
|
ManualDataFocus::Date => {
|
||||||
if value.is_digit(10) {
|
if value.is_ascii_digit() {
|
||||||
if let Some(ref mut s) = app.states.manual_transactions.date {
|
if let Some(ref mut s) = app.states.manual_transactions.date {
|
||||||
if s.len() < 10 {
|
if s.len() < 10 {
|
||||||
s.push(value);
|
s.push(value);
|
||||||
|
@ -193,26 +193,26 @@ impl ManualTransactionState {
|
||||||
}
|
}
|
||||||
if let Some(ManualDataFocus::Date) = app.states.manual_transactions.focus {
|
if let Some(ManualDataFocus::Date) = app.states.manual_transactions.focus {
|
||||||
if let Some(ref mut x) = app.states.manual_transactions.date {
|
if let Some(ref mut x) = app.states.manual_transactions.date {
|
||||||
if x.starts_with("+") {
|
if x.starts_with('+') {
|
||||||
x.clear();
|
x.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else if event.code == KeyCode::Enter{
|
||||||
match event.code {
|
|
||||||
KeyCode::Enter => {
|
|
||||||
app.states.manual_transactions.focus = Some(ManualDataFocus::Account);
|
app.states.manual_transactions.focus = Some(ManualDataFocus::Account);
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for ManualTransactionState {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn render_manual_transaction<B: Backend>(f: &mut Frame<B>, body_rect: Rect, app: &App) {
|
pub fn render_manual_transaction<B: Backend>(f: &mut Frame<B>, body_rect: Rect, app: &App) {
|
||||||
// Render the custom tab bar
|
// Render the custom tab bar
|
||||||
let mut constraints: Vec<Constraint> = vec![];
|
|
||||||
|
|
||||||
let constraints: Vec<Constraint> = vec![
|
let constraints: Vec<Constraint> = vec![
|
||||||
Constraint::Length(1),
|
Constraint::Length(1),
|
||||||
Constraint::Length(1), // account
|
Constraint::Length(1), // account
|
||||||
|
|
|
@ -63,6 +63,12 @@ impl<'a> NavigationState<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a> Default for NavigationState<'a> {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn render_navigation_frame<B: Backend>(
|
pub fn render_navigation_frame<B: Backend>(
|
||||||
f: &mut Frame<B>,
|
f: &mut Frame<B>,
|
||||||
status_rect: Rect,
|
status_rect: Rect,
|
||||||
|
@ -114,7 +120,7 @@ pub fn render_navigation_frame<B: Backend>(
|
||||||
|
|
||||||
// Navbar section
|
// Navbar section
|
||||||
let navbar = {
|
let navbar = {
|
||||||
if let None = app.states.nav_state.message {
|
if app.states.nav_state.message.is_none() {
|
||||||
match app.states.active_frame {
|
match app.states.active_frame {
|
||||||
ActiveFrame::Navigation => "Navigating: q/Esc to exit".to_string(),
|
ActiveFrame::Navigation => "Navigating: q/Esc to exit".to_string(),
|
||||||
_ => "Editing Body: q/Esc to go back to navigating".to_string(),
|
_ => "Editing Body: q/Esc to go back to navigating".to_string(),
|
||||||
|
|
|
@ -27,7 +27,7 @@ impl<'a> QuickTransactionState<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_event(event: KeyEvent, app: &mut App) {
|
pub fn handle_event(event: KeyEvent, app: &mut App) {
|
||||||
let transact_state = &app.states.transactions;
|
// let transact_state = &app.states.transactions;
|
||||||
|
|
||||||
if event.kind == KeyEventKind::Press {
|
if event.kind == KeyEventKind::Press {
|
||||||
match event.code {
|
match event.code {
|
||||||
|
@ -38,6 +38,12 @@ impl<'a> QuickTransactionState<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a> Default for QuickTransactionState<'a> {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn render_quick_transaction<B: Backend>(f: &mut Frame<B>, body_rect: Rect, app: &App) {
|
pub fn render_quick_transaction<B: Backend>(f: &mut Frame<B>, body_rect: Rect, app: &App) {
|
||||||
let chunks = Layout::default()
|
let chunks = Layout::default()
|
||||||
.direction(Direction::Vertical)
|
.direction(Direction::Vertical)
|
||||||
|
|
Loading…
Reference in a new issue