mirror of
https://github.com/simonmichael/hledger.git
synced 2024-11-08 07:09:28 +03:00
register: optimise postingsReportItemAsText a bit
Avoid concatTopPadded when rendering register output, making that command faster when there's a lot of output.
This commit is contained in:
parent
101719d3cb
commit
b499ea85eb
@ -70,7 +70,12 @@ tests_postingsReportAsText = [
|
||||
-- @
|
||||
postingsReportItemAsText :: CliOpts -> PostingsReportItem -> String
|
||||
postingsReportItemAsText opts (mdate, mdesc, p, b) =
|
||||
concatTopPadded [date, " ", desc, " ", acct, " ", amt, " ", bal]
|
||||
intercalate "\n" $
|
||||
[printf ("%-"++datew++"s %-"++descw++"s %-"++acctw++"s %"++amtw++"s %"++balw++"s")
|
||||
date desc acct amtfirstline balfirstline]
|
||||
++
|
||||
[printf (spacer ++ "%"++amtw++"s %"++balw++"s") a b | (a,b) <- zip amtrest balrest ]
|
||||
|
||||
where
|
||||
totalwidth = case widthFromOpts opts of
|
||||
Left _ -> defaultWidth -- shouldn't happen
|
||||
@ -85,17 +90,24 @@ postingsReportItemAsText opts (mdate, mdesc, p, b) =
|
||||
| otherwise = (r', r'+1)
|
||||
where r = remaining - 2
|
||||
r' = r `div` 2
|
||||
date = maybe (replicate datewidth ' ') (printf ("%-"++show datewidth++"s") . showDate) mdate
|
||||
desc = maybe (replicate descwidth ' ') (printf ("%-"++show descwidth++"s") . take descwidth . elideRight descwidth) mdesc
|
||||
acct = printf ("%-"++(show acctwidth)++"s") a
|
||||
[datew,descw,acctw,amtw,balw] = map show [datewidth,descwidth,acctwidth,amtwidth,balwidth]
|
||||
|
||||
date = maybe "" showDate mdate
|
||||
desc = maybe "" (take descwidth . elideRight descwidth) mdesc
|
||||
acct = parenthesise $ elideAccountName awidth $ paccount p
|
||||
where
|
||||
a = bracket $ elideAccountName awidth $ paccount p
|
||||
(bracket, awidth) = case ptype p of
|
||||
(parenthesise, awidth) = case ptype p of
|
||||
BalancedVirtualPosting -> (\s -> "["++s++"]", acctwidth-2)
|
||||
VirtualPosting -> (\s -> "("++s++")", acctwidth-2)
|
||||
_ -> (id,acctwidth)
|
||||
amt = padleft amtwidth $ showMixedAmountWithoutPrice $ pamount p
|
||||
bal = padleft balwidth $ showMixedAmountWithoutPrice b
|
||||
amt = showMixedAmountWithoutPrice $ pamount p
|
||||
bal = showMixedAmountWithoutPrice b
|
||||
(amtlines, ballines) = (lines amt, lines bal)
|
||||
(amtlen, ballen) = (length amtlines, length ballines)
|
||||
numlines = max amtlen ballen
|
||||
(amtfirstline:amtrest) = take numlines $ amtlines ++ repeat "" -- posting amount is top-aligned
|
||||
(balfirstline:balrest) = take numlines $ replicate (numlines - ballen) "" ++ ballines -- balance amount is bottom-aligned
|
||||
spacer = replicate (totalwidth - (amtwidth + 2 + balwidth)) ' '
|
||||
|
||||
-- XXX
|
||||
-- showPostingWithBalanceForVty showtxninfo p b = postingsReportItemAsText defreportopts $ mkpostingsReportItem showtxninfo p b
|
||||
|
@ -24,10 +24,10 @@ hledgerdev -f - register
|
||||
c ; a euro and a dollar
|
||||
>>>
|
||||
2010/01/01 a EUR 1 EUR 1
|
||||
EUR 1
|
||||
b USD 1 USD 1
|
||||
EUR -1
|
||||
c USD -1 0
|
||||
b USD 1 EUR 1
|
||||
USD 1
|
||||
c EUR -1
|
||||
USD -1 0
|
||||
>>>=0
|
||||
|
||||
# 3. balance
|
||||
|
Loading…
Reference in New Issue
Block a user