Version bump. Added/separated lib. Some renaming.

This commit is contained in:
scoobybejesus 2019-10-27 21:25:23 -04:00
parent b5a5c8ec62
commit 3696908aac
28 changed files with 292 additions and 221 deletions

View File

@ -1,9 +1,17 @@
[package] [package]
name = "cryptools" name = "cryptools"
version = "0.6.0" version = "0.7.0"
authors = ["scoobybejesus <scoobybejesus@users.noreply.github.com>"] authors = ["scoobybejesus <scoobybejesus@users.noreply.github.com>"]
edition = "2018" edition = "2018"
description = "This is a command-line utility for processing cryptocurrency transactions into 'lots' and 'movements'." description = "Command-line utility for processing cryptocurrency transactions into 'lots' and 'movements'."
[lib]
name = "crptls"
path = "src/lib.rs"
[[bin]]
name = "main"
path = "src/main.rs"
[dependencies] [dependencies]
csv = "1.0.0" csv = "1.0.0"
@ -19,5 +27,4 @@ tui = "0.5"
termion = "1.5" termion = "1.5"
[profile.release] [profile.release]
lto = true lto = true

View File

@ -2,7 +2,7 @@
### Accounting library for cryptocurrency transaction activity. ### Accounting library for cryptocurrency transaction activity.
###### (Currently runs as a binary) ###### (The package produces a binary that makes use of the library)
This software calculates income, expenses, realized gains, and realized losses from cryptocurrency activity This software calculates income, expenses, realized gains, and realized losses from cryptocurrency activity
and denominates the results in the user's home currency. and denominates the results in the user's home currency.
@ -49,7 +49,7 @@ when appreciated cryptocurrency was used to make a tax-deductible charitable con
2. `cd cryptools` 2. `cd cryptools`
3. `cargo build` (include `--release` for a non-debug build) 3. `cargo build` (include `--release` for a non-debug build)
This will build `./target/debug/cryptools` (or `./target/rls/cryptools` for a non-debug build). This will build `./target/debug/cryptools` (or `./target/release/cryptools` for a non-debug build).
## Usage ## Usage

View File

@ -3,7 +3,9 @@
The sample input files and the resulting reports are in the `/examples/resources/` directory. The sample input files and the resulting reports are in the `/examples/resources/` directory.
(Note: new reports have been added since the write-up below was written. (Note: new reports have been added since the write-up below was written.
Nevertheless, evaluating the reports should mostly be self-explanatory.) Nevertheless, evaluating the reports should mostly be self-explanatory.
Pass a -p flag from the command line to see the full list of available
reports - and select from them - once the import has taken place.)
## 1. Using the wizard ## 1. Using the wizard
@ -39,7 +41,7 @@ Then tab-complete your way through `/Users/<your-username>/Documents`*, for exam
##### Now the program has ended, and you should have reports in the directory you provided. ##### Now the program has ended, and you should have reports in the directory you provided.
The reports should match those in the `examples/resources` directory. The reports should generally match those in the `examples/resources` directory.
(Additional reports are created too, but you can generally match the existing reports by title.) (Additional reports are created too, but you can generally match the existing reports by title.)
@ -77,6 +79,8 @@ Or maybe you may want to apply like-kind exchange treatment through a particular
These parameters can all be set via command line options. These parameters can all be set via command line options.
See the `--help` screen for all the options. See the `--help` screen for all the options.
As mentioned above, pass the -p flag to be presented with a list of available reports.
## Notes on the reports ## Notes on the reports
There are two style of reports: Accounts and Transactions. There are two style of reports: Accounts and Transactions.

View File

@ -15,8 +15,8 @@ use rustyline::hint::{Hinter};
use rustyline::error::ReadlineError; use rustyline::error::ReadlineError;
use rustyline::highlight::{Highlighter}; use rustyline::highlight::{Highlighter};
use crate::core_functions::InventoryCostingMethod; use crptls::costing_method::InventoryCostingMethod;
use crate::string_utils; use crptls::string_utils;
pub fn choose_file_for_import(flag_to_accept_cli_args: bool) -> Result<PathBuf, Box<dyn Error>> { pub fn choose_file_for_import(flag_to_accept_cli_args: bool) -> Result<PathBuf, Box<dyn Error>> {

View File

@ -12,7 +12,7 @@ use chrono_tz::US::Eastern;
use decimal::d128; use decimal::d128;
use serde_derive::{Serialize, Deserialize}; use serde_derive::{Serialize, Deserialize};
use crate::transaction::{Transaction, ActionRecord, Polarity, TxType}; use crate::crptls_lib::transaction::{Transaction, ActionRecord, Polarity, TxType};
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)] #[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub struct RawAccount { pub struct RawAccount {

View File

@ -5,42 +5,16 @@ use std::path::PathBuf;
use std::error::Error; use std::error::Error;
use std::fs::File; use std::fs::File;
use std::collections::{HashMap}; use std::collections::{HashMap};
use std::fmt;
use chrono::NaiveDate; use chrono::NaiveDate;
use structopt::StructOpt;
use crate::account::{Account, RawAccount, Lot}; use crate::crptls_lib::account::{Account, RawAccount, Lot};
use crate::transaction::{Transaction, ActionRecord}; use crate::crptls_lib::transaction::{Transaction, ActionRecord};
use crate::csv_import_accts_txns; use crate::crptls_lib::csv_import_accts_txns;
use crate::import_cost_proceeds_etc; use crate::crptls_lib::import_cost_proceeds_etc;
use crate::create_lots_mvmts; use crate::crptls_lib::create_lots_mvmts;
use crate::crptls_lib::costing_method::InventoryCostingMethod;
/// An `InventoryMethod` determines the order in which a `Lot` is chosen when posting
/// `ActionRecord` amounts as individual `Movement`s.
#[derive(Clone, Debug, PartialEq, StructOpt)]
pub enum InventoryCostingMethod {
/// 1. LIFO according to the order the lot was created.
LIFObyLotCreationDate,
/// 2. LIFO according to the basis date of the lot.
LIFObyLotBasisDate,
/// 3. FIFO according to the order the lot was created.
FIFObyLotCreationDate,
/// 4. FIFO according to the basis date of the lot.
FIFObyLotBasisDate,
}
impl fmt::Display for InventoryCostingMethod {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
InventoryCostingMethod::LIFObyLotCreationDate => write!(f, "LIFO by lot creation date"),
InventoryCostingMethod::LIFObyLotBasisDate => write!(f, "LIFO by lot basis date"),
InventoryCostingMethod::FIFObyLotCreationDate => write!(f, "FIFO by lot creation date"),
InventoryCostingMethod::FIFObyLotBasisDate => write!(f, "FIFO by lot basis date"),
}
}
}
/// `ImportProcessParameters` are determined from command-line args and/or wizard input from the user. /// `ImportProcessParameters` are determined from command-line args and/or wizard input from the user.
/// They are the settings that allow the software to carry out the importing-from-csv of /// They are the settings that allow the software to carry out the importing-from-csv of
@ -60,7 +34,7 @@ pub struct ImportProcessParameters {
pub print_menu: bool, pub print_menu: bool,
} }
pub(crate) fn import_and_process_final( pub fn import_and_process_final(
input_file_path: PathBuf, input_file_path: PathBuf,
settings: &ImportProcessParameters, settings: &ImportProcessParameters,
) -> Result<( ) -> Result<(

View File

@ -0,0 +1,32 @@
// Copyright (c) 2017-2019, scoobybejesus
// Redistributions must include the license: https://github.com/scoobybejesus/cryptools/blob/master/LEGAL.txt
use std::fmt;
use structopt::StructOpt;
/// An `InventoryMethod` determines the order in which a `Lot` is chosen when posting
/// `ActionRecord` amounts as individual `Movement`s.
#[derive(Clone, Debug, PartialEq, StructOpt)]
pub enum InventoryCostingMethod {
/// 1. LIFO according to the order the lot was created.
LIFObyLotCreationDate,
/// 2. LIFO according to the basis date of the lot.
LIFObyLotBasisDate,
/// 3. FIFO according to the order the lot was created.
FIFObyLotCreationDate,
/// 4. FIFO according to the basis date of the lot.
FIFObyLotBasisDate,
}
impl fmt::Display for InventoryCostingMethod {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
InventoryCostingMethod::LIFObyLotCreationDate => write!(f, "LIFO by lot creation date"),
InventoryCostingMethod::LIFObyLotBasisDate => write!(f, "LIFO by lot basis date"),
InventoryCostingMethod::FIFObyLotCreationDate => write!(f, "FIFO by lot creation date"),
InventoryCostingMethod::FIFObyLotBasisDate => write!(f, "FIFO by lot basis date"),
}
}
}

View File

@ -9,10 +9,10 @@ use std::error::Error;
use decimal::d128; use decimal::d128;
use chrono::NaiveDate; use chrono::NaiveDate;
use crate::transaction::{Transaction, ActionRecord, TxType, Polarity, TxHasMargin}; use crate::crptls_lib::transaction::{Transaction, ActionRecord, TxType, Polarity, TxHasMargin};
use crate::account::{Account, RawAccount, Lot, Movement}; use crate::crptls_lib::account::{Account, RawAccount, Lot, Movement};
use crate::core_functions::{InventoryCostingMethod}; use crate::crptls_lib::costing_method::{InventoryCostingMethod};
use crate::decimal_utils::{round_d128_1e8}; use crate::crptls_lib::decimal_utils::{round_d128_1e8};
pub(crate) fn create_lots_and_movements( pub(crate) fn create_lots_and_movements(
txns_map: HashMap<u32, Transaction>, txns_map: HashMap<u32, Transaction>,

View File

@ -10,9 +10,9 @@ use std::collections::{HashMap};
use chrono::NaiveDate; use chrono::NaiveDate;
use decimal::d128; use decimal::d128;
use crate::transaction::{Transaction, ActionRecord}; use crate::crptls_lib::transaction::{Transaction, ActionRecord};
use crate::account::{Account, RawAccount}; use crate::crptls_lib::account::{Account, RawAccount};
use crate::decimal_utils::{round_d128_1e8}; use crate::crptls_lib::decimal_utils::{round_d128_1e8};
pub(crate) fn import_accounts( pub(crate) fn import_accounts(

View File

@ -6,10 +6,10 @@ use std::error::Error;
use decimal::d128; use decimal::d128;
use crate::transaction::{Transaction, TxType, ActionRecord, Polarity}; use crate::crptls_lib::transaction::{Transaction, TxType, ActionRecord, Polarity};
use crate::account::{Account, RawAccount}; use crate::crptls_lib::account::{Account, RawAccount};
use crate::decimal_utils::{round_d128_1e2}; use crate::crptls_lib::decimal_utils::{round_d128_1e2};
use crate::core_functions::{ImportProcessParameters}; use crate::crptls_lib::core_functions::{ImportProcessParameters};
pub(crate) fn add_cost_basis_to_movements( pub(crate) fn add_cost_basis_to_movements(
settings: &ImportProcessParameters, settings: &ImportProcessParameters,

17
src/crptls_lib/mod.rs Normal file
View File

@ -0,0 +1,17 @@
// Copyright (c) 2017-2019, scoobybejesus
// Redistributions must include the license: https://github.com/scoobybejesus/cryptools/blob/master/LEGAL.txt
#![allow(dead_code)]
#![allow(unused_variables)]
#![allow(unused_assignments)]
pub mod account;
pub mod transaction;
pub mod core_functions;
pub mod string_utils;
pub mod decimal_utils;
pub mod costing_method;
mod csv_import_accts_txns;
mod create_lots_mvmts;
mod import_cost_proceeds_etc;

View File

@ -12,7 +12,7 @@ use decimal::d128;
use chrono::NaiveDate; use chrono::NaiveDate;
use serde_derive::{Serialize, Deserialize}; use serde_derive::{Serialize, Deserialize};
use crate::account::{Account, Movement, RawAccount}; use crate::crptls_lib::account::{Account, Movement, RawAccount};
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Transaction { pub struct Transaction {

View File

@ -4,11 +4,11 @@
use std::error::Error; use std::error::Error;
use std::collections::{HashMap}; use std::collections::{HashMap};
use crate::transaction::{Transaction, ActionRecord}; use crptls::transaction::{Transaction, ActionRecord};
use crate::account::{Account, RawAccount}; use crptls::account::{Account, RawAccount};
use crate::core_functions::{ImportProcessParameters}; use crptls::core_functions::{ImportProcessParameters};
use crate::csv_export; use crate::export_csv;
use crate::txt_export; use crate::export_txt;
pub fn export( pub fn export(
@ -21,25 +21,25 @@ pub fn export(
println!("Creating all reports now."); println!("Creating all reports now.");
csv_export::_1_account_sums_to_csv( export_csv::_1_account_sums_to_csv(
&settings, &settings,
&raw_acct_map, &raw_acct_map,
&account_map &account_map
); );
csv_export::_2_account_sums_nonzero_to_csv( export_csv::_2_account_sums_nonzero_to_csv(
&account_map, &account_map,
&settings, &settings,
&raw_acct_map &raw_acct_map
); );
csv_export::_3_account_sums_to_csv_with_orig_basis( export_csv::_3_account_sums_to_csv_with_orig_basis(
&settings, &settings,
&raw_acct_map, &raw_acct_map,
&account_map &account_map
); );
csv_export::_4_transaction_mvmt_detail_to_csv( export_csv::_4_transaction_mvmt_detail_to_csv(
&settings, &settings,
&action_records_map, &action_records_map,
&raw_acct_map, &raw_acct_map,
@ -47,7 +47,7 @@ pub fn export(
&transactions_map &transactions_map
)?; )?;
csv_export::_5_transaction_mvmt_summaries_to_csv( export_csv::_5_transaction_mvmt_summaries_to_csv(
&settings, &settings,
&action_records_map, &action_records_map,
&raw_acct_map, &raw_acct_map,
@ -55,7 +55,7 @@ pub fn export(
&transactions_map &transactions_map
)?; )?;
csv_export::_6_transaction_mvmt_detail_to_csv_w_orig( export_csv::_6_transaction_mvmt_detail_to_csv_w_orig(
&settings, &settings,
&action_records_map, &action_records_map,
&raw_acct_map, &raw_acct_map,
@ -63,7 +63,7 @@ pub fn export(
&transactions_map &transactions_map
)?; )?;
txt_export::_1_account_lot_detail_to_txt( export_txt::_1_account_lot_detail_to_txt(
&settings, &settings,
&raw_acct_map, &raw_acct_map,
&account_map, &account_map,
@ -71,13 +71,13 @@ pub fn export(
&action_records_map &action_records_map
)?; )?;
txt_export::_2_account_lot_summary_to_txt( export_txt::_2_account_lot_summary_to_txt(
&settings, &settings,
&raw_acct_map, &raw_acct_map,
&account_map, &account_map,
)?; )?;
txt_export::_3_account_lot_summary_non_zero_to_txt( export_txt::_3_account_lot_summary_non_zero_to_txt(
&settings, &settings,
&raw_acct_map, &raw_acct_map,
&account_map, &account_map,

View File

@ -8,9 +8,9 @@ use std::error::Error;
use decimal::d128; use decimal::d128;
use crate::transaction::{Transaction, ActionRecord, Polarity, TxType}; use crptls::transaction::{Transaction, ActionRecord, Polarity, TxType};
use crate::account::{Account, RawAccount, Term}; use crptls::account::{Account, RawAccount, Term};
use crate::core_functions::{ImportProcessParameters}; use crptls::core_functions::{ImportProcessParameters};
pub fn _1_account_sums_to_csv( pub fn _1_account_sums_to_csv(

View File

@ -9,9 +9,9 @@ use std::io::prelude::Write;
use decimal::d128; use decimal::d128;
use crate::transaction::{Transaction, ActionRecord}; use crptls::transaction::{Transaction, ActionRecord};
use crate::account::{Account, RawAccount}; use crptls::account::{Account, RawAccount};
use crate::core_functions::{ImportProcessParameters}; use crptls::core_functions::{ImportProcessParameters};
pub fn _1_account_lot_detail_to_txt( pub fn _1_account_lot_detail_to_txt(

11
src/lib.rs Normal file
View File

@ -0,0 +1,11 @@
// Copyright (c) 2017-2019, scoobybejesus
// Redistributions must include the license: https://github.com/scoobybejesus/cryptools/blob/master/LEGAL.txt
pub use self::crptls_lib::account;
pub use self::crptls_lib::transaction;
pub use self::crptls_lib::core_functions;
pub use self::crptls_lib::string_utils;
pub use self::crptls_lib::decimal_utils;
pub use self::crptls_lib::costing_method;
pub mod crptls_lib;

View File

@ -11,40 +11,23 @@
use std::ffi::OsString; use std::ffi::OsString;
use std::path::PathBuf; use std::path::PathBuf;
use std::error::Error; use std::error::Error;
use std::io;
use std::time::Duration;
use ::tui::Terminal;
use ::tui::backend::TermionBackend;
use termion::raw::IntoRawMode;
use termion::screen::AlternateScreen;
use termion::input::MouseTerminal;
use termion::event::Key;
use structopt::StructOpt; use structopt::StructOpt;
mod account; mod setup;
mod transaction;
mod core_functions;
mod csv_import_accts_txns;
mod create_lots_mvmts;
mod import_cost_proceeds_etc;
mod cli_user_choices; mod cli_user_choices;
mod csv_export;
mod txt_export;
mod string_utils;
mod decimal_utils;
mod tests;
mod wizard; mod wizard;
mod skip_wizard; mod skip_wizard;
mod setup; mod mytui;
mod tui; mod export_csv;
mod export_txt;
mod export_all; mod export_all;
mod tests;
#[derive(StructOpt, Debug)] #[derive(StructOpt, Debug)]
#[structopt(name = "cryptools")] #[structopt(name = "cryptools")]
pub(crate) struct Cli { pub struct Cli {
#[structopt(flatten)] #[structopt(flatten)]
flags: Flags, flags: Flags,
@ -58,7 +41,7 @@ pub(crate) struct Cli {
} }
#[derive(StructOpt, Debug)] #[derive(StructOpt, Debug)]
pub(crate) struct Flags { pub struct Flags {
/// User is instructing the program to skip the data entry wizard. /// User is instructing the program to skip the data entry wizard.
/// When set, program will error without required command-line args. /// When set, program will error without required command-line args.
@ -84,7 +67,7 @@ pub(crate) struct Flags {
} }
#[derive(StructOpt, Debug)] #[derive(StructOpt, Debug)]
pub(crate) struct Options { pub struct Options {
/// Choose "h", "s", or "p" for hyphen, slash, or period (i.e., "-", "/", or ".") to indicate the separator /// Choose "h", "s", or "p" for hyphen, slash, or period (i.e., "-", "/", or ".") to indicate the separator
/// character used in the file_to_import txDate column (i.e. 2017/12/31, 2017-12-31, or 2017.12.31). /// character used in the file_to_import txDate column (i.e. 2017/12/31, 2017-12-31, or 2017.12.31).
@ -117,7 +100,6 @@ pub(crate) struct Options {
} }
fn main() -> Result<(), Box<dyn Error>> { fn main() -> Result<(), Box<dyn Error>> {
let args = Cli::from_args(); let args = Cli::from_args();
@ -140,7 +122,7 @@ fn main() -> Result<(), Box<dyn Error>> {
raw_acct_map, raw_acct_map,
action_records_map, action_records_map,
transactions_map, transactions_map,
) = core_functions::import_and_process_final(input_file_path, &settings)?; ) = crptls::core_functions::import_and_process_final(input_file_path, &settings)?;
let mut should_export_all = settings.should_export; let mut should_export_all = settings.should_export;
let present_print_menu_tui = settings.print_menu; let present_print_menu_tui = settings.print_menu;
@ -160,62 +142,13 @@ fn main() -> Result<(), Box<dyn Error>> {
if present_print_menu_tui { if present_print_menu_tui {
use crate::tui::event::{Events, Event, Config}; mytui::print_menu_tui::print_menu_tui(
let stdout = io::stdout().into_raw_mode()?;
let stdout = MouseTerminal::from(stdout);
let stdout = AlternateScreen::from(stdout);
let backend = TermionBackend::new(stdout);
let mut terminal = Terminal::new(backend)?;
terminal.hide_cursor()?;
let mut app = tui::app::PrintWindow::new("Reports");
let events = Events::with_config(Config {
tick_rate: Duration::from_millis(250u64),
..Config::default()
});
loop {
tui::ui::draw(&mut terminal, &app)?;
match events.next()? {
Event::Input(key) => match key {
Key::Char(c) => {
app.on_key(c);
}
Key::Up => {
app.on_up();
}
Key::Down => {
app.on_down();
}
_ => {}
},
_ => {}
}
if app.should_quit {
break;
}
}
// Seem to need both of these for the native terminal to be available for println!()'s below
std::mem::drop(terminal);
std::thread::sleep(Duration::from_millis(10));
tui::app::export(
&app,
&settings, &settings,
&action_records_map, &action_records_map,
&raw_acct_map, &raw_acct_map,
&account_map, &account_map,
&transactions_map &transactions_map
)?; )?;
} }
// use tests::test; // use tests::test;

View File

@ -4,12 +4,13 @@
use std::error::Error; use std::error::Error;
use std::collections::{HashMap}; use std::collections::{HashMap};
use crptls::transaction::{Transaction, ActionRecord};
use crptls::account::{Account, RawAccount};
use crptls::core_functions::{ImportProcessParameters};
use crate::export_csv;
use crate::export_txt;
use crate::transaction::{Transaction, ActionRecord};
use crate::account::{Account, RawAccount};
use crate::core_functions::{ImportProcessParameters};
use crate::csv_export;
use crate::txt_export;
pub (crate) const REPORTS: [&'static str; 9] = [ pub (crate) const REPORTS: [&'static str; 9] = [
"1. CSV: Account Sums", "1. CSV: Account Sums",
@ -128,28 +129,28 @@ pub fn export(
match report + 1 { match report + 1 {
1 => { 1 => {
csv_export::_1_account_sums_to_csv( export_csv::_1_account_sums_to_csv(
&settings, &settings,
&raw_acct_map, &raw_acct_map,
&account_map &account_map
); );
} }
2 => { 2 => {
csv_export::_2_account_sums_nonzero_to_csv( export_csv::_2_account_sums_nonzero_to_csv(
&account_map, &account_map,
&settings, &settings,
&raw_acct_map &raw_acct_map
); );
} }
3 => { 3 => {
csv_export::_3_account_sums_to_csv_with_orig_basis( export_csv::_3_account_sums_to_csv_with_orig_basis(
&settings, &settings,
&raw_acct_map, &raw_acct_map,
&account_map &account_map
); );
} }
4 => { 4 => {
csv_export::_4_transaction_mvmt_detail_to_csv( export_csv::_4_transaction_mvmt_detail_to_csv(
&settings, &settings,
&action_records_map, &action_records_map,
&raw_acct_map, &raw_acct_map,
@ -158,7 +159,7 @@ pub fn export(
)?; )?;
} }
5 => { 5 => {
csv_export::_5_transaction_mvmt_summaries_to_csv( export_csv::_5_transaction_mvmt_summaries_to_csv(
&settings, &settings,
&action_records_map, &action_records_map,
&raw_acct_map, &raw_acct_map,
@ -167,7 +168,7 @@ pub fn export(
)?; )?;
} }
6 => { 6 => {
csv_export::_6_transaction_mvmt_detail_to_csv_w_orig( export_csv::_6_transaction_mvmt_detail_to_csv_w_orig(
&settings, &settings,
&action_records_map, &action_records_map,
&raw_acct_map, &raw_acct_map,
@ -176,7 +177,7 @@ pub fn export(
)?; )?;
} }
7 => { 7 => {
txt_export::_1_account_lot_detail_to_txt( export_txt::_1_account_lot_detail_to_txt(
&settings, &settings,
&raw_acct_map, &raw_acct_map,
&account_map, &account_map,
@ -185,14 +186,14 @@ pub fn export(
)?; )?;
} }
8 => { 8 => {
txt_export::_2_account_lot_summary_to_txt( export_txt::_2_account_lot_summary_to_txt(
&settings, &settings,
&raw_acct_map, &raw_acct_map,
&account_map, &account_map,
)?; )?;
} }
9 => { 9 => {
txt_export::_3_account_lot_summary_non_zero_to_txt( export_txt::_3_account_lot_summary_non_zero_to_txt(
&settings, &settings,
&raw_acct_map, &raw_acct_map,
&account_map, &account_map,

View File

@ -1,8 +1,7 @@
// Copyright (c) 2017-2019, scoobybejesus // Copyright (c) 2017-2019, scoobybejesus
// Redistributions must include the license: https://github.com/scoobybejesus/cryptools/blob/master/LEGAL.txt // Redistributions must include the license: https://github.com/scoobybejesus/cryptools/blob/master/LEGAL.txt
pub use main; pub mod print_menu_tui;
mod app;
pub mod app; mod ui;
pub mod ui; mod event;
pub mod event;

View File

@ -0,0 +1,88 @@
// Copyright (c) 2017-2019, scoobybejesus
// Redistributions must include the license: https://github.com/scoobybejesus/cryptools/blob/master/LEGAL.txt
use std::io;
use std::time::Duration;
use std::collections::{HashMap};
use std::error::Error;
use tui::Terminal;
use tui::backend::TermionBackend;
use termion::raw::IntoRawMode;
use termion::screen::AlternateScreen;
use termion::input::MouseTerminal;
use termion::event::Key;
use crptls::transaction::{Transaction, ActionRecord};
use crptls::account::{Account, RawAccount};
use crptls::core_functions::{ImportProcessParameters};
use crate::mytui::event::{Events, Event, Config};
use crate::mytui::ui as ui;
use crate::mytui::app as app;
pub (crate) fn print_menu_tui(
settings: &ImportProcessParameters,
action_records_map: &HashMap<u32, ActionRecord>,
raw_acct_map: &HashMap<u16, RawAccount>,
account_map: &HashMap<u16, Account>,
transactions_map: &HashMap<u32, Transaction>,
) -> Result<(), Box<dyn Error>> {
let stdout = io::stdout().into_raw_mode()?;
let stdout = MouseTerminal::from(stdout);
let stdout = AlternateScreen::from(stdout);
let backend = TermionBackend::new(stdout);
let mut terminal = Terminal::new(backend)?;
terminal.hide_cursor()?;
let mut app = app::PrintWindow::new("Reports");
let events = Events::with_config(Config {
tick_rate: Duration::from_millis(250u64),
..Config::default()
});
loop {
ui::draw(&mut terminal, &app)?;
match events.next()? {
Event::Input(key) => match key {
Key::Char(c) => {
app.on_key(c);
}
Key::Up => {
app.on_up();
}
Key::Down => {
app.on_down();
}
_ => {}
},
_ => {}
}
if app.should_quit {
break;
}
}
// Seem to need both of these for the native terminal to be available for println!()'s below
std::mem::drop(terminal);
std::thread::sleep(Duration::from_millis(10));
app::export(
&app,
&settings,
&action_records_map,
&raw_acct_map,
&account_map,
&transactions_map
)?;
Ok(())
}

View File

@ -9,8 +9,7 @@ use ::tui::widgets::{Widget, Block, Borders, SelectableList, Text, Paragraph};
use ::tui::layout::{Layout, Constraint, Direction}; use ::tui::layout::{Layout, Constraint, Direction};
use ::tui::backend::Backend; use ::tui::backend::Backend;
use crate::tui::app::PrintWindow; use crate::mytui::app::{PrintWindow, REPORTS};
use crate::tui;
pub fn draw<B: Backend>(terminal: &mut Terminal<B>, app: &PrintWindow) -> Result<(), io::Error> { pub fn draw<B: Backend>(terminal: &mut Terminal<B>, app: &PrintWindow) -> Result<(), io::Error> {
@ -21,7 +20,7 @@ pub fn draw<B: Backend>(terminal: &mut Terminal<B>, app: &PrintWindow) -> Result
.constraints([ .constraints([
Constraint::Length(1), Constraint::Length(1),
Constraint::Length(8), Constraint::Length(8),
Constraint::Length(tui::app::REPORTS.len() as u16 + 2), Constraint::Length(REPORTS.len() as u16 + 2),
Constraint::Percentage(35) Constraint::Percentage(35)
].as_ref()) ].as_ref())
.split(f.size()); .split(f.size());

View File

@ -8,8 +8,10 @@ use std::process;
use chrono::NaiveDate; use chrono::NaiveDate;
use crptls::core_functions::ImportProcessParameters;
use crptls::costing_method::InventoryCostingMethod;
use crate::cli_user_choices; use crate::cli_user_choices;
use crate::core_functions::{ImportProcessParameters, InventoryCostingMethod};
use crate::skip_wizard; use crate::skip_wizard;
use crate::wizard; use crate::wizard;
@ -77,52 +79,52 @@ pub (crate) fn run_setup(args: super::Cli) -> Result<(PathBuf, ImportProcessPara
} }
fn wizard_or_not(accept_args: bool, args: ArgsForImportVarsTBD) -> Result<( fn wizard_or_not(accept_args: bool, args: ArgsForImportVarsTBD) -> Result<(
InventoryCostingMethod, InventoryCostingMethod,
bool, bool,
String, String,
bool, bool,
PathBuf, PathBuf,
), Box<dyn Error>> { ), Box<dyn Error>> {
let costing_method_choice; let costing_method_choice;
let like_kind_election; let like_kind_election;
let like_kind_cutoff_date_string; let like_kind_cutoff_date_string;
let should_export; let should_export;
let output_dir_path; let output_dir_path;
if !accept_args { if !accept_args {
let ( let (
costing_method_choice1, costing_method_choice1,
like_kind_election1, like_kind_election1,
like_kind_cutoff_date_string1, like_kind_cutoff_date_string1,
should_export1, should_export1,
output_dir_path1, output_dir_path1,
) = wizard::wizard(args)?; ) = wizard::wizard(args)?;
costing_method_choice = costing_method_choice1; costing_method_choice = costing_method_choice1;
like_kind_election = like_kind_election1; like_kind_election = like_kind_election1;
like_kind_cutoff_date_string = like_kind_cutoff_date_string1; like_kind_cutoff_date_string = like_kind_cutoff_date_string1;
should_export = should_export1; should_export = should_export1;
output_dir_path = output_dir_path1; output_dir_path = output_dir_path1;
} else { } else {
let ( let (
costing_method_choice1, costing_method_choice1,
like_kind_election1, like_kind_election1,
like_kind_cutoff_date_string1, like_kind_cutoff_date_string1,
should_export1, should_export1,
output_dir_path1, output_dir_path1,
) = skip_wizard::skip_wizard(args)?; ) = skip_wizard::skip_wizard(args)?;
costing_method_choice = costing_method_choice1; costing_method_choice = costing_method_choice1;
like_kind_election = like_kind_election1; like_kind_election = like_kind_election1;
like_kind_cutoff_date_string = like_kind_cutoff_date_string1; like_kind_cutoff_date_string = like_kind_cutoff_date_string1;
should_export = should_export1; should_export = should_export1;
output_dir_path = output_dir_path1; output_dir_path = output_dir_path1;
} }
Ok((costing_method_choice, like_kind_election, like_kind_cutoff_date_string, should_export, output_dir_path)) Ok((costing_method_choice, like_kind_election, like_kind_cutoff_date_string, should_export, output_dir_path))
} }

View File

@ -4,10 +4,12 @@
use std::path::PathBuf; use std::path::PathBuf;
use std::error::Error; use std::error::Error;
use crptls::costing_method::InventoryCostingMethod;
use crate::cli_user_choices; use crate::cli_user_choices;
use crate::core_functions::{InventoryCostingMethod};
use crate::setup::{ArgsForImportVarsTBD}; use crate::setup::{ArgsForImportVarsTBD};
pub(crate) fn skip_wizard(args: ArgsForImportVarsTBD) -> Result<( pub(crate) fn skip_wizard(args: ArgsForImportVarsTBD) -> Result<(
InventoryCostingMethod, InventoryCostingMethod,
bool, bool,

View File

@ -6,9 +6,9 @@ use std::collections::{HashMap};
use decimal::d128; use decimal::d128;
use crate::account::{Account}; use crptls::account::{Account};
use crate::transaction::{Transaction, ActionRecord}; use crptls::transaction::{Transaction, ActionRecord};
use crate::decimal_utils::*; use crptls::decimal_utils::*;
pub fn run_tests( pub fn run_tests(
transactions_map: &HashMap<u32, Transaction>, transactions_map: &HashMap<u32, Transaction>,

View File

@ -6,10 +6,12 @@ use std::process;
use std::io::{self, BufRead}; use std::io::{self, BufRead};
use std::path::PathBuf; use std::path::PathBuf;
use crptls::costing_method::InventoryCostingMethod;
use crate::cli_user_choices; use crate::cli_user_choices;
use crate::core_functions::{InventoryCostingMethod};
use crate::setup::{ArgsForImportVarsTBD}; use crate::setup::{ArgsForImportVarsTBD};
pub(crate) fn wizard(args: ArgsForImportVarsTBD) -> Result<( pub(crate) fn wizard(args: ArgsForImportVarsTBD) -> Result<(
InventoryCostingMethod, InventoryCostingMethod,
bool, bool,