highlighting + 'Summe' padding
This commit is contained in:
parent
fd706bfa57
commit
5ebe2bc69e
54
src/main.rs
54
src/main.rs
|
@ -4,12 +4,29 @@ mod simple_enums;
|
|||
mod transaction;
|
||||
|
||||
fn main() {
|
||||
let mut args: Vec<_> = std::env::args().skip(1).collect();
|
||||
|
||||
if args.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
use chrono::Datelike;
|
||||
use encoding::types::Encoding;
|
||||
use prettytable::{cell, format, row, Cell, Row, Table};
|
||||
use std::collections::BTreeMap;
|
||||
use prettytable::{cell, format, row, Table};
|
||||
use std::collections::{BTreeMap, HashSet};
|
||||
|
||||
for i in std::env::args().skip(1) {
|
||||
let mut highlight = HashSet::new();
|
||||
|
||||
if args[0] == "--highlight" {
|
||||
args.remove(0);
|
||||
let eo_selst = args.iter().take_while(|i| *i != ";").count();
|
||||
highlight = args
|
||||
.drain(..std::cmp::min(eo_selst + 1, args.len()))
|
||||
.collect();
|
||||
highlight.remove(";");
|
||||
}
|
||||
|
||||
for i in args {
|
||||
println!("F = {}", i);
|
||||
|
||||
let fh = readfilez::read_from_file(std::fs::File::open(i)).expect("unable to open file");
|
||||
|
@ -66,7 +83,7 @@ fn main() {
|
|||
|
||||
let mut accu = BTreeMap::<
|
||||
(i32, bool, string_cache::DefaultAtom),
|
||||
(usize, transaction::TransactionValue),
|
||||
(usize, transaction::TransactionValue, String, usize),
|
||||
>::new();
|
||||
|
||||
let mut i_skipped = 0usize;
|
||||
|
@ -95,6 +112,14 @@ fn main() {
|
|||
if accu.is_empty() {
|
||||
continue;
|
||||
}
|
||||
|
||||
let mut pdsp = 0;
|
||||
for i in accu.values_mut() {
|
||||
i.2 = i.1.to_string();
|
||||
i.3 = i.2.find('.').map(|x| i.2.len() - x).unwrap_or(0);
|
||||
pdsp = std::cmp::max(pdsp, i.3);
|
||||
}
|
||||
|
||||
let mut table = Table::new();
|
||||
table.set_format(
|
||||
format::FormatBuilder::new()
|
||||
|
@ -104,6 +129,10 @@ fn main() {
|
|||
format::LinePosition::Top,
|
||||
format::LineSeparator::new('─', '┬', '┌', '┐'),
|
||||
)
|
||||
.separator(
|
||||
format::LinePosition::Title,
|
||||
format::LineSeparator::new('─', '┼', '├', '┤'),
|
||||
)
|
||||
.separator(
|
||||
format::LinePosition::Bottom,
|
||||
format::LineSeparator::new('─', '┴', '└', '┘'),
|
||||
|
@ -112,14 +141,15 @@ fn main() {
|
|||
.build(),
|
||||
);
|
||||
|
||||
table.add_row(row!["Jahr", "Einzahler", "Zahlungen", "Summe"]);
|
||||
for (k, v) in accu {
|
||||
table.add_row(Row::new(vec![
|
||||
Cell::new(&format!("{} {}.", k.0, if k.1 { 2 } else { 1 })),
|
||||
Cell::new(&k.2),
|
||||
Cell::new(&v.0.to_string()),
|
||||
Cell::new(&v.1.to_string()),
|
||||
]));
|
||||
table.set_titles(row!["Jahr", "Einzahler", "Zahlungen", "Summe"]);
|
||||
for (k, v) in accu.iter_mut() {
|
||||
let yearuhj = format!("{} {}", k.0, if k.1 { "II" } else { "I" });
|
||||
v.2 += &std::iter::repeat(' ').take(pdsp - v.3).collect::<String>();
|
||||
table.add_row(if highlight.contains(&*k.2) {
|
||||
row![&yearuhj, FYBdb-> &k.2, r-> &v.0.to_string(), Fgbr-> &v.2]
|
||||
} else {
|
||||
row![&yearuhj, &k.2, r-> &v.0.to_string(), r-> &v.2]
|
||||
});
|
||||
}
|
||||
|
||||
table.printstd();
|
||||
|
|
Loading…
Reference in a new issue