From 6970a4c6e88c75494c9a71336291aed35f1a27bf Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Wed, 21 Mar 2018 17:01:03 +0000 Subject: [PATCH] budget: more regular layout, simple fixed-width columns old: Balance changes in 2018/03/19w12: || 2018/03/19w12 ===================++================= :aaa || 0 bbb || 1.33 [0] bbb:bbbbbbbbbbbbb || 1.25 [42% of 3] ccc || 0 [0% of 0] ddd || 0 [0% of 0] eee || 0.75 [75% of 1] fff || 3.50 [50% of 7] ggg || 1.25 [0] hhh || 0 [0% of 6] iii || 0 [0% of 0] -------------------++----------------- || 8.08 new: || 2018/03/19w12 ===================++======================== :aaa || 0 bbb || 1.33 [ 0] bbb:bbbbbbbbbbbbb || 1.25 [ 42% of 3] ccc || 0 [ 0% of 0] ddd || 0 [ 0% of 0] eee || 0.75 [ 75% of 1] fff || 3.50 [ 50% of 7] ggg || 1.25 [ 0] hhh || 0 [ 0% of 6] iii || 0 [ 0% of 0] -------------------++------------------------ || 8.08 --- hledger/Hledger/Cli/Commands/Balance.hs | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/hledger/Hledger/Cli/Commands/Balance.hs b/hledger/Hledger/Cli/Commands/Balance.hs index a0cc4d863..477736864 100644 --- a/hledger/Hledger/Cli/Commands/Balance.hs +++ b/hledger/Hledger/Cli/Commands/Balance.hs @@ -667,11 +667,22 @@ multiBalanceReportWithBudgetAsText opts budgetr actualr = actualandbudgetamts = combine (balanceReportAsTable opts actualr) (balanceReportAsTable opts budgetr) showcell :: (ActualAmount, Maybe BudgetAmount) -> String - showcell (actual, Nothing) = showamt actual - showcell (actual, Just budget) = - case percentage actual budget of - Just pct -> printf "%s [%s%% of %s]" (showamt actual) (show $ roundTo 0 pct) (showamt budget) - Nothing -> printf "%s [%s]" (showamt actual) (showamt budget) + showcell (actual, mbudget) = + case (actual, mbudget) of + (actual, Nothing) -> + printf ("%"++show actualwidth++"s " ++ replicate (percentwidth + 7 + budgetwidth) ' ') (showamt actual) + (actual, Just budget) -> + case percentage actual budget of + Just pct -> + printf ("%"++show actualwidth++"s [%"++show percentwidth++"s%% of %"++show budgetwidth++"s]") + (showamt actual) (show $ roundTo 0 pct) (showamt budget) + Nothing -> + printf ("%"++show actualwidth++"s ["++replicate (percentwidth+5) ' '++"%"++show budgetwidth++"s]") + (showamt actual) (showamt budget) + where + actualwidth = 7 + percentwidth = 3 + budgetwidth = 4 percentage :: ActualAmount -> BudgetAmount -> Maybe Percentage percentage actual budget =