register: refactor layout code

This commit is contained in:
Simon Michael 2009-11-25 06:13:35 +00:00
parent 73bc81cd7e
commit 37f08a35c0
2 changed files with 12 additions and 6 deletions

View File

@ -106,9 +106,13 @@ showtxns (t:ts) tprev bal = this ++ showtxns ts t bal'
showtxn :: Bool -> Transaction -> MixedAmount -> String
showtxn omitdesc t b = concatBottomPadded [entrydesc ++ p ++ " ", bal] ++ "\n"
where
entrydesc = if omitdesc then replicate 32 ' ' else printf "%s %s " date desc
ledger3ishlayout = False
datedescwidth = if ledger3ishlayout then 34 else 32
entrydesc = if omitdesc then replicate datedescwidth ' ' else printf "%s %s " date desc
date = showDate da
desc = printf "%-20s" $ elideRight 20 de :: String
datewidth = 10
descwidth = datedescwidth - datewidth - 2
desc = printf ("%-"++(show descwidth)++"s") $ elideRight descwidth de :: String
p = showPostingWithoutPrice $ Posting s a amt "" tt
bal = padleft 12 (showMixedAmountOrZeroWithoutPrice b)
Transaction{tstatus=s,tdate=da,tdescription=de,taccount=a,tamount=amt,ttype=tt} = t

View File

@ -25,11 +25,13 @@ showPosting :: Posting -> String
showPosting (Posting _ a amt com ttype) =
concatTopPadded [showaccountname a ++ " ", showamount amt, comment]
where
showaccountname = printf "%-22s" . bracket . elideAccountName width
ledger3ishlayout = False
acctnamewidth = if ledger3ishlayout then 25 else 22
showaccountname = printf ("%-"++(show acctnamewidth)++"s") . bracket . elideAccountName width
(bracket,width) = case ttype of
BalancedVirtualPosting -> (\s -> "["++s++"]", 20)
VirtualPosting -> (\s -> "("++s++")", 20)
_ -> (id,22)
BalancedVirtualPosting -> (\s -> "["++s++"]", acctnamewidth-2)
VirtualPosting -> (\s -> "("++s++")", acctnamewidth-2)
_ -> (id,acctnamewidth)
showamount = padleft 12 . showMixedAmountOrZero
comment = if null com then "" else " ; " ++ com
-- XXX refactor