Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
<p align="center">
<img src="https://github.com/TheRustyPickle/Rex/assets/35862475/04575a15-53f7-497f-b2e7-88a7a66d1136" width=400>
</p>

<div align="center"><h1>Rex</h1></div>
<div align="center">
<a href="https://wakatime.com/@RustyPickle"><img src="https://wakatime.com/badge/github/TheRustyPickle/Rex.svg" alt="wakatime"></a>
Expand Down Expand Up @@ -57,6 +53,7 @@ cargo run --release
**4. Install using a package manager:**

* On NetBSD a package is available from the [official repositories](https://pkgsrc.se/finance/rex). To install it simply run:

```sh
pkgin install rex
```
Expand Down
Binary file removed logo.png
Binary file not shown.
8 changes: 8 additions & 0 deletions tui/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub struct Config {
pub location: PathBuf,
pub backup_db_path: Option<Vec<PathBuf>>,
pub new_location: Option<PathBuf>,
pub theme_index: Option<usize>,
}

impl Config {
Expand All @@ -35,6 +36,7 @@ impl Config {
backup_db_path: None,
new_location: None,
location: target_dir,
theme_index: Some(0),
});
}

Expand All @@ -44,6 +46,11 @@ impl Config {
let mut config: Config = serde_json::from_str(&file_content)?;

config.location = target_dir;

if config.theme_index.is_none() {
config.theme_index = Some(0);
}

Ok(config)
}

Expand Down Expand Up @@ -157,6 +164,7 @@ pub fn migrate_config(config_path: &PathBuf) -> Result<()> {
backup_db_path: None,
new_location: None,
location: PathBuf::new(),
theme_index: Some(0),
};

let mut backup_path = config_path.to_owned();
Expand Down
1 change: 1 addition & 0 deletions tui/src/key_checker/activity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub fn activity_keys(handler: &mut InputKeyHandler) -> Result<Option<HandlingOut
KeyCode::Char('z') => handler.go_summary()?,
KeyCode::Char('w') => handler.go_search(),
KeyCode::Char('v') => handler.show_activity_tx_details()?,
KeyCode::Char('t') => handler.next_theme()?,
KeyCode::Right => handler.handle_right_arrow()?,
KeyCode::Left => handler.handle_left_arrow()?,
KeyCode::Up => handler.handle_up_arrow(),
Expand Down
1 change: 1 addition & 0 deletions tui/src/key_checker/add_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub fn add_tx_keys(handler: &mut InputKeyHandler) -> Result<Option<HandlingOutpu
KeyCode::Char('w') => handler.go_search(),
KeyCode::Char('c') => handler.clear_input()?,
KeyCode::Char('y') => handler.go_activity(),
KeyCode::Char('t') => handler.next_theme()?,
KeyCode::Enter => handler.select_date_field(),
KeyCode::Char(c) => {
if c.is_numeric() {
Expand Down
1 change: 1 addition & 0 deletions tui/src/key_checker/chart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub fn chart_keys(handler: &mut InputKeyHandler) -> Result<Option<HandlingOutput
KeyCode::Char('R') => handler.do_chart_lgeneds(),
KeyCode::Char('w') => handler.go_search(),
KeyCode::Char('y') => handler.go_activity(),
KeyCode::Char('t') => handler.next_theme()?,
KeyCode::Right => handler.handle_right_arrow()?,
KeyCode::Left => handler.handle_left_arrow()?,
KeyCode::Up => handler.handle_up_arrow(),
Expand Down
1 change: 1 addition & 0 deletions tui/src/key_checker/home.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub fn home_keys(handler: &mut InputKeyHandler) -> Result<Option<HandlingOutput>
KeyCode::Char(',') => handler.switch_tx_position_up()?,
KeyCode::Char('.') => handler.switch_tx_position_down()?,
KeyCode::Char('v') => handler.show_home_tx_details(),
KeyCode::Char('t') => handler.next_theme()?,
KeyCode::Right => handler.handle_right_arrow()?,
KeyCode::Left => handler.handle_left_arrow()?,
KeyCode::Up => handler.handle_up_arrow(),
Expand Down
8 changes: 8 additions & 0 deletions tui/src/key_checker/key_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,14 @@ impl<'a> InputKeyHandler<'a> {
pub fn popup_down(&mut self) {
self.popup_status.next();
}

pub fn next_theme(&mut self) -> Result<()> {
let new_index = self.theme.next();
self.config.theme_index = Some(new_index);
self.config.save_config()?;

Ok(())
}
}

impl InputKeyHandler<'_> {
Expand Down
1 change: 1 addition & 0 deletions tui/src/key_checker/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub fn search_keys(handler: &mut InputKeyHandler) -> Result<Option<HandlingOutpu
KeyCode::Char('e') => handler.search_edit_tx()?,
KeyCode::Char('d') => handler.do_deletion_popup(),
KeyCode::Char('y') => handler.go_activity(),
KeyCode::Char('t') => handler.next_theme()?,
KeyCode::Up => handler.handle_up_arrow(),
KeyCode::Down => handler.handle_down_arrow(),
KeyCode::Enter => handler.select_date_field(),
Expand Down
1 change: 1 addition & 0 deletions tui/src/key_checker/summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub fn summary_keys(handler: &mut InputKeyHandler) -> Result<Option<HandlingOutp
KeyCode::Char('z') => handler.do_summary_hidden_mode(),
KeyCode::Char('x') => handler.change_summary_sort(),
KeyCode::Char('y') => handler.go_activity(),
KeyCode::Char('t') => handler.next_theme()?,
KeyCode::Right => handler.handle_right_arrow()?,
KeyCode::Left => handler.handle_left_arrow()?,
KeyCode::Up => handler.handle_up_arrow(),
Expand Down
4 changes: 2 additions & 2 deletions tui/src/page_handler/ui_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::pages::{
InfoPopupState, PopupType, activity_ui, add_tx_ui, chart_ui, home_ui, initial_ui, search_ui,
summary_ui,
};
use crate::theme::{Theme, ThemeVariant};
use crate::theme::Theme;
use crate::tx_handler::TxData;
use crate::utility::LerpState;

Expand All @@ -33,7 +33,7 @@ pub fn start_app<B: Backend>(
) -> Result<HandlingOutput, UiHandlingError> {
// Setting up some default values. Let's go through all of them

let mut theme = Theme::new(ThemeVariant::Light);
let mut theme = Theme::new_index(config.theme_index.unwrap_or(0));

// Contains the homepage month list that is indexed
let mut home_months = IndexedData::new_monthly();
Expand Down
30 changes: 14 additions & 16 deletions tui/src/pages/activity_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use thousands::Separable;

use crate::page_handler::{ActivityTab, IndexedData, TableData};
use crate::theme::Theme;
use crate::utility::{LerpState, create_tab, main_block, styled_block};
use crate::utility::{LerpState, create_tab, main_block, styled_block, tab_highlight_style};

pub fn activity_ui(
f: &mut Frame,
Expand Down Expand Up @@ -147,25 +147,23 @@ pub fn activity_ui(
let mut year_tab = create_tab(years, "Years", theme);

match current_tab {
ActivityTab::Months => {
month_tab = month_tab.highlight_style(
Style::default()
.add_modifier(Modifier::BOLD)
.bg(theme.selected()),
);
}
ActivityTab::Years => {
year_tab = year_tab.highlight_style(
Style::default()
.add_modifier(Modifier::BOLD)
.bg(theme.selected()),
);
}
ActivityTab::Months => month_tab = month_tab.highlight_style(tab_highlight_style(theme)),
ActivityTab::Years => year_tab = year_tab.highlight_style(tab_highlight_style(theme)),
ActivityTab::List => {
if table_data.state.selected().is_some() {
let add_modifier = theme.add_reverse_modifier();

let mut style = Style::default();

if add_modifier {
style = style.fg(theme.selected()).add_modifier(Modifier::REVERSED);
} else {
style = style.bg(theme.selected());
}

activity_table_area = activity_table_area
.highlight_symbol(">> ")
.row_highlight_style(Style::default().bg(theme.selected()));
.row_highlight_style(style);
}
}
}
Expand Down
36 changes: 9 additions & 27 deletions tui/src/pages/chart_ui.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use chrono::{Duration, naive::NaiveDate};
use ratatui::Frame;
use ratatui::layout::{Constraint, Direction, Layout};
use ratatui::style::{Color, Modifier, Style};
use ratatui::style::{Color, Style};
use ratatui::symbols::Marker;
use ratatui::text::Span;
use ratatui::widgets::{Axis, Block, Chart, Dataset, GraphType};
Expand All @@ -11,7 +11,9 @@ use std::collections::HashMap;

use crate::page_handler::{ChartTab, IndexedData};
use crate::theme::Theme;
use crate::utility::{LerpState, create_tab, create_tab_activation, main_block};
use crate::utility::{
LerpState, create_tab, create_tab_activation, main_block, tab_highlight_style,
};

/// Creates the balance chart from the transactions
pub fn chart_ui(
Expand Down Expand Up @@ -334,34 +336,14 @@ pub fn chart_ui(
);

match current_page {
ChartTab::Months => {
month_tab = month_tab.highlight_style(
Style::default()
.add_modifier(Modifier::BOLD)
.bg(theme.selected()),
);
}

ChartTab::Years => {
year_tab = year_tab.highlight_style(
Style::default()
.add_modifier(Modifier::BOLD)
.bg(theme.selected()),
);
}
ChartTab::Months => month_tab = month_tab.highlight_style(tab_highlight_style(theme)),
ChartTab::Years => year_tab = year_tab.highlight_style(tab_highlight_style(theme)),
ChartTab::ModeSelection => {
mode_selection_tab = mode_selection_tab.highlight_style(
Style::default()
.add_modifier(Modifier::BOLD)
.bg(theme.selected()),
);
mode_selection_tab = mode_selection_tab.highlight_style(tab_highlight_style(theme));
}
ChartTab::TxMethods => {
tx_method_selection_tab = tx_method_selection_tab.highlight_style(
Style::default()
.add_modifier(Modifier::BOLD)
.bg(theme.selected()),
);
tx_method_selection_tab =
tx_method_selection_tab.highlight_style(tab_highlight_style(theme));
}
}

Expand Down
32 changes: 14 additions & 18 deletions tui/src/pages/home_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use thousands::Separable;

use crate::page_handler::{HomeRow, HomeTab, IndexedData, TableData};
use crate::theme::Theme;
use crate::utility::{LerpState, create_tab, main_block, styled_block};
use crate::utility::{LerpState, create_tab, main_block, styled_block, tab_highlight_style};

pub const BALANCE_BOLD: [&str; 7] = [
"Balance",
Expand Down Expand Up @@ -221,21 +221,8 @@ pub fn home_ui(
match current_tab {
// Previously added a black block to year and month widget if a value is not selected
// Now we will turn that black block into green if a value is selected
HomeTab::Months => {
month_tab = month_tab.highlight_style(
Style::default()
.add_modifier(Modifier::BOLD)
.bg(theme.selected()),
);
}

HomeTab::Years => {
year_tab = year_tab.highlight_style(
Style::default()
.add_modifier(Modifier::BOLD)
.bg(theme.selected()),
);
}
HomeTab::Months => month_tab = month_tab.highlight_style(tab_highlight_style(theme)),
HomeTab::Years => year_tab = year_tab.highlight_style(tab_highlight_style(theme)),
// Changes the color of row based on Expense or Income tx type on Transaction widget.
HomeTab::Table => {
if let Some(a) = home_table.state.selected() {
Expand All @@ -251,8 +238,17 @@ pub fn home_ui(
} else if income_strings.contains(target_string) {
table_area = table_area.row_highlight_style(selected_style_income);
} else if home_table.items[a][4] == "Transfer" {
table_area =
table_area.row_highlight_style(Style::default().bg(theme.selected()));
let add_modifier = theme.add_reverse_modifier();

let mut style = Style::default();

if add_modifier {
style = style.fg(theme.selected()).add_modifier(Modifier::REVERSED);
} else {
style = style.bg(theme.selected());
}

table_area = table_area.row_highlight_style(style);
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions tui/src/pages/initial_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,11 @@ pub fn initial_ui(f: &mut Frame, start_from: usize, theme: &Theme) {
Arrow Left/Right: Cycle values of a widget
H: Show help of the page the UI is currently on
X: Change sort type on summary/Change date type on Search page
Double R: Go to the Chart page and hide top widget. Press again to unhide
Double Z: Go to the Summary page and hide top widget. Press again to unhide";
T: Cycle through themes
Double r (Lowercase): Go to the Chart page and hide top widget. Press again to unhide
Double R (Upeercase): Go to the Chart page and hide chart legends. Press again to unhide
Double Z: Go to the Summary page and hide top widget. Press again to unhide
";

let unmodified_third_help = format!(
"Arrow Up/Down: Move between year/month/transaction selections and scroll
Expand Down
11 changes: 10 additions & 1 deletion tui/src/pages/popups/help_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub const Q: &str = "Q: Quit";
pub const H: &str = "H: Show help";
pub const V: &str = "V: Show selected transaction details";
pub const J: &str = "J: Configuration";
pub const T: &str = "T: Cycle through themes";

pub fn new_update_text(data: &[String]) -> String {
format!(
Expand Down Expand Up @@ -51,6 +52,7 @@ Empty tags field gets replaced with Unknown. Separate more than 1 tags with a co
Example amount: 100 + b, b + b, 5 * b, 1.2k + 1m

{F}
{T}
{R}
{Z}
{Y}
Expand All @@ -76,6 +78,7 @@ Arrow Up/Down: Cycle widgets
Arrow Left/Right: Move value of the widget

{F}
{T}
{A}
{Z}
{Y}
Expand All @@ -89,7 +92,8 @@ Arrow Left/Right: Move value of the widget

pub fn summary_help_text() -> String {
format!(
"This page shows various information based on all transactions primary tag within a given period. Transfer Transaction are not shown here
"This page shows various information based on all transactions primary tag within a given period.
Lend and borrow is based on the current outstanding amount.

Following are the supported keys here

Expand All @@ -100,6 +104,7 @@ Arrow Up/Down: Cycle widgets/table value
Arrow Left/Right: Move value of the widget

{F}
{T}
{A}
{R}
{Y}
Expand Down Expand Up @@ -128,6 +133,7 @@ Arrow Left/Right: Move value of the widget
Swapping transaction location will only work if they are on the same date.

{A}
{T}
{R}
{Z}
{Y}
Expand All @@ -147,6 +153,7 @@ pub fn search_help_text() -> String {
1: Date Example: 2022-05-12, YYYY-MM-DD
2: TX details Example: For Grocery, Salary
5: TX Type Example: Income/Expense/Transfer/I/E/T
5: New TX Type Example: Borrow/Borrow Repay/Lend/Lend Repay/b/br/l/lr
3: TX Method Example: Cash, Bank, Card
4: Amount Example: 1000, 100+50, b - 100
6: Tags Example: Food, Car. Add a Comma for a new tag
Expand Down Expand Up @@ -181,6 +188,7 @@ Amount Field: Amount field supports '>' '<' '>=' '<=' highlighting amount \
Example amount : <1000, >=10000

{F}
{T}
{A}
{R}
{Z}
Expand All @@ -205,6 +213,7 @@ Arrow Up/Down: Cycle widgets
Arrow Left/Right: Move value of the widget

{F}
{T}
{A}
{R}
{Z}
Expand Down
7 changes: 5 additions & 2 deletions tui/src/pages/popups/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,11 @@ impl PopupType {
.state
.select(Some(selected_index - 1));
}
PopupType::Info(_) | PopupType::Choice(_) => {}
_ => {}
PopupType::Info(_)
| PopupType::Choice(_)
| PopupType::Input(_)
| PopupType::NewPaths(_)
| PopupType::Nothing => {}
}
}

Expand Down
Loading
Loading