More factoring of tui-related code.
This commit is contained in:
parent
c489b92711
commit
b5ca5a0929
98
src/main.rs
98
src/main.rs
|
@ -39,8 +39,6 @@ mod skip_wizard;
|
|||
mod setup;
|
||||
mod tui;
|
||||
|
||||
use crate::tui::app::PrintWindow;
|
||||
use crate::tui::event::{Events, Event, Config};
|
||||
|
||||
|
||||
#[derive(StructOpt, Debug)]
|
||||
|
@ -218,12 +216,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||
|
||||
if present_print_menu_tui {
|
||||
|
||||
let reports = tui::app::REPORTS;
|
||||
|
||||
let events = Events::with_config(Config {
|
||||
tick_rate: Duration::from_millis(250u64),
|
||||
..Config::default()
|
||||
});
|
||||
use crate::tui::event::{Events, Event, Config};
|
||||
|
||||
let stdout = io::stdout().into_raw_mode()?;
|
||||
let stdout = MouseTerminal::from(stdout);
|
||||
|
@ -232,11 +225,16 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||
let mut terminal = Terminal::new(backend)?;
|
||||
terminal.hide_cursor()?;
|
||||
|
||||
let mut app = PrintWindow::new("Reports");
|
||||
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, reports.len() as u16)?;
|
||||
tui::ui::draw(&mut terminal, &app)?;
|
||||
|
||||
match events.next()? {
|
||||
|
||||
|
@ -251,12 +249,6 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||
Key::Down => {
|
||||
app.on_down();
|
||||
}
|
||||
Key::Left => {
|
||||
// app.on_left();
|
||||
}
|
||||
Key::Right => {
|
||||
// app.on_right();
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
_ => {}
|
||||
|
@ -271,83 +263,15 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||
std::mem::drop(terminal);
|
||||
std::thread::sleep(Duration::from_millis(10));
|
||||
|
||||
for report in app.to_print {
|
||||
println!("Exporting: {}", reports[report]);
|
||||
match report + 1 {
|
||||
1 => {
|
||||
csv_export::_1_account_sums_to_csv(
|
||||
&settings,
|
||||
&raw_acct_map,
|
||||
&account_map
|
||||
);
|
||||
}
|
||||
2 => {
|
||||
csv_export::_2_account_sums_nonzero_to_csv(
|
||||
&account_map,
|
||||
&settings,
|
||||
&raw_acct_map
|
||||
);
|
||||
}
|
||||
3 => {
|
||||
csv_export::_3_account_sums_to_csv_with_orig_basis(
|
||||
&settings,
|
||||
&raw_acct_map,
|
||||
&account_map
|
||||
);
|
||||
}
|
||||
4 => {
|
||||
csv_export::_4_transaction_mvmt_detail_to_csv(
|
||||
tui::app::export(
|
||||
&app,
|
||||
&settings,
|
||||
&action_records_map,
|
||||
&raw_acct_map,
|
||||
&account_map,
|
||||
&transactions_map
|
||||
)?;
|
||||
}
|
||||
5 => {
|
||||
csv_export::_5_transaction_mvmt_summaries_to_csv(
|
||||
&settings,
|
||||
&action_records_map,
|
||||
&raw_acct_map,
|
||||
&account_map,
|
||||
&transactions_map
|
||||
)?;
|
||||
}
|
||||
6 => {
|
||||
csv_export::_6_transaction_mvmt_detail_to_csv_w_orig(
|
||||
&settings,
|
||||
&action_records_map,
|
||||
&raw_acct_map,
|
||||
&account_map,
|
||||
&transactions_map
|
||||
)?;
|
||||
}
|
||||
7 => {
|
||||
txt_export::_1_account_lot_detail_to_txt(
|
||||
&settings,
|
||||
&raw_acct_map,
|
||||
&account_map,
|
||||
&transactions_map,
|
||||
&action_records_map
|
||||
)?;
|
||||
}
|
||||
8 => {
|
||||
txt_export::_2_account_lot_summary_to_txt(
|
||||
&settings,
|
||||
&raw_acct_map,
|
||||
&account_map,
|
||||
)?;
|
||||
}
|
||||
9 => {
|
||||
txt_export::_3_account_lot_summary_non_zero_to_txt(
|
||||
&settings,
|
||||
&raw_acct_map,
|
||||
&account_map,
|
||||
)?;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// use tests::test;
|
||||
|
|
104
src/tui/app.rs
104
src/tui/app.rs
|
@ -1,6 +1,15 @@
|
|||
// Copyright (c) 2017-2019, scoobybejesus
|
||||
// Redistributions must include the license: https://github.com/scoobybejesus/cryptools/blob/master/LEGAL.txt
|
||||
|
||||
use std::error::Error;
|
||||
use std::collections::{HashMap};
|
||||
|
||||
|
||||
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] = [
|
||||
"1. CSV: Account Sums",
|
||||
|
@ -100,3 +109,98 @@ impl<'a> PrintWindow<'a> {
|
|||
vec.dedup();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn export(
|
||||
app: &PrintWindow,
|
||||
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 reports = REPORTS.to_vec();
|
||||
|
||||
for report in app.to_print.iter() {
|
||||
|
||||
println!("Exporting: {}", reports[*report]);
|
||||
|
||||
match report + 1 {
|
||||
|
||||
1 => {
|
||||
csv_export::_1_account_sums_to_csv(
|
||||
&settings,
|
||||
&raw_acct_map,
|
||||
&account_map
|
||||
);
|
||||
}
|
||||
2 => {
|
||||
csv_export::_2_account_sums_nonzero_to_csv(
|
||||
&account_map,
|
||||
&settings,
|
||||
&raw_acct_map
|
||||
);
|
||||
}
|
||||
3 => {
|
||||
csv_export::_3_account_sums_to_csv_with_orig_basis(
|
||||
&settings,
|
||||
&raw_acct_map,
|
||||
&account_map
|
||||
);
|
||||
}
|
||||
4 => {
|
||||
csv_export::_4_transaction_mvmt_detail_to_csv(
|
||||
&settings,
|
||||
&action_records_map,
|
||||
&raw_acct_map,
|
||||
&account_map,
|
||||
&transactions_map
|
||||
)?;
|
||||
}
|
||||
5 => {
|
||||
csv_export::_5_transaction_mvmt_summaries_to_csv(
|
||||
&settings,
|
||||
&action_records_map,
|
||||
&raw_acct_map,
|
||||
&account_map,
|
||||
&transactions_map
|
||||
)?;
|
||||
}
|
||||
6 => {
|
||||
csv_export::_6_transaction_mvmt_detail_to_csv_w_orig(
|
||||
&settings,
|
||||
&action_records_map,
|
||||
&raw_acct_map,
|
||||
&account_map,
|
||||
&transactions_map
|
||||
)?;
|
||||
}
|
||||
7 => {
|
||||
txt_export::_1_account_lot_detail_to_txt(
|
||||
&settings,
|
||||
&raw_acct_map,
|
||||
&account_map,
|
||||
&transactions_map,
|
||||
&action_records_map
|
||||
)?;
|
||||
}
|
||||
8 => {
|
||||
txt_export::_2_account_lot_summary_to_txt(
|
||||
&settings,
|
||||
&raw_acct_map,
|
||||
&account_map,
|
||||
)?;
|
||||
}
|
||||
9 => {
|
||||
txt_export::_3_account_lot_summary_non_zero_to_txt(
|
||||
&settings,
|
||||
&raw_acct_map,
|
||||
&account_map,
|
||||
)?;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
|
@ -10,13 +10,10 @@ use ::tui::layout::{Layout, Constraint, Direction};
|
|||
use ::tui::backend::Backend;
|
||||
|
||||
use crate::tui::app::PrintWindow;
|
||||
use crate::tui;
|
||||
|
||||
|
||||
pub fn draw<B: Backend>(
|
||||
terminal: &mut Terminal<B>,
|
||||
app: &PrintWindow,
|
||||
reports_len: u16,
|
||||
) -> Result<(), io::Error> {
|
||||
pub fn draw<B: Backend>(terminal: &mut Terminal<B>, app: &PrintWindow) -> Result<(), io::Error> {
|
||||
|
||||
terminal.draw(|mut f| {
|
||||
|
||||
|
@ -24,7 +21,7 @@ pub fn draw<B: Backend>(
|
|||
.constraints([
|
||||
Constraint::Length(1),
|
||||
Constraint::Length(8),
|
||||
Constraint::Length(reports_len + 2),
|
||||
Constraint::Length(tui::app::REPORTS.len() as u16 + 2),
|
||||
Constraint::Percentage(35)
|
||||
].as_ref())
|
||||
.split(f.size());
|
||||
|
|
Loading…
Reference in New Issue