lib: fix alignment in budget report

This commit is contained in:
Dmitry Astapov 2019-01-17 00:26:34 +00:00 committed by Simon Michael
parent d094138910
commit 92e7370f1f

View File

@ -262,18 +262,24 @@ budgetReportSpan (PeriodicReport (spans, _, _)) = DateSpan (spanStart $ head spa
-- | Render a budget report as plain text suitable for console output. -- | Render a budget report as plain text suitable for console output.
budgetReportAsText :: ReportOpts -> BudgetReport -> String budgetReportAsText :: ReportOpts -> BudgetReport -> String
budgetReportAsText ropts budgetr = budgetReportAsText ropts budgetr@(PeriodicReport ( _, rows, _)) =
printf "Budget performance in %s:\n\n" (showDateSpan $ budgetReportSpan budgetr) printf "Budget performance in %s:\n\n" (showDateSpan $ budgetReportSpan budgetr)
++ ++
tableAsText ropts showcell (budgetReportAsTable ropts budgetr) tableAsText ropts showcell (budgetReportAsTable ropts budgetr)
where where
actualwidth =
maximum [ maybe 0 (length . showMixedAmountOneLineWithoutPrice) amt
| (_, _, _, amtandgoals, _, _) <- rows
, (amt, _) <- amtandgoals ]
budgetwidth =
maximum [ maybe 0 (length . showMixedAmountOneLineWithoutPrice) goal
| (_, _, _, amtandgoals, _, _) <- rows
, (_, goal) <- amtandgoals ]
-- XXX lay out actual, percentage and/or goal in the single table cell for now, should probably use separate cells -- XXX lay out actual, percentage and/or goal in the single table cell for now, should probably use separate cells
showcell :: (Maybe Change, Maybe BudgetGoal) -> String showcell :: (Maybe Change, Maybe BudgetGoal) -> String
showcell (mactual, mbudget) = actualstr ++ " " ++ budgetstr showcell (mactual, mbudget) = actualstr ++ " " ++ budgetstr
where where
actualwidth = 7
percentwidth = 4 percentwidth = 4
budgetwidth = 5
actual = fromMaybe 0 mactual actual = fromMaybe 0 mactual
actualstr = printf ("%"++show actualwidth++"s") (showamt actual) actualstr = printf ("%"++show actualwidth++"s") (showamt actual)
budgetstr = case mbudget of budgetstr = case mbudget of