lib: Make sure to add a newline to the end of aregister report.
This commit is contained in:
parent
b5ab5ac9bc
commit
b203822cd1
@ -812,10 +812,9 @@ parseResultToCsv = toListList . unpackFields
|
||||
unpackFields = (fmap . fmap) T.decodeUtf8
|
||||
|
||||
printCSV :: CSV -> TL.Text
|
||||
printCSV = TB.toLazyText . unlined . map printRecord
|
||||
printCSV = TB.toLazyText . unlinesB . map printRecord
|
||||
where printRecord = mconcat . map TB.fromText . intersperse "," . map printField
|
||||
printField = wrap "\"" "\"" . T.replace "\"" "\\\"\\\""
|
||||
unlined = (<> TB.fromText "\n") . mconcat . intersperse "\n"
|
||||
|
||||
-- | Return the cleaned up and validated CSV data (can be empty), or an error.
|
||||
validateCsv :: CsvRules -> Int -> Either String CSV -> Either String [CsvRecord]
|
||||
|
||||
@ -47,6 +47,7 @@ module Hledger.Utils.Text
|
||||
fitText,
|
||||
linesPrepend,
|
||||
linesPrepend2,
|
||||
unlinesB,
|
||||
-- -- * wide-character-aware layout
|
||||
WideBuilder(..),
|
||||
wbToText,
|
||||
@ -71,6 +72,7 @@ import Data.Monoid
|
||||
#endif
|
||||
import Data.Text (Text)
|
||||
import qualified Data.Text as T
|
||||
import qualified Data.Text.Lazy.Builder as TB
|
||||
-- import Text.Parsec
|
||||
-- import Text.Printf (printf)
|
||||
|
||||
@ -371,6 +373,11 @@ linesPrepend2 prefix1 prefix2 s = T.unlines $ case T.lines s of
|
||||
[] -> []
|
||||
l:ls -> (prefix1<>l) : map (prefix2<>) ls
|
||||
|
||||
-- | Concatenate a list of Text Builders with a newline between each item, and
|
||||
-- another at the end. If the list is empty, return the identity builder.
|
||||
unlinesB :: [TB.Builder] -> TB.Builder
|
||||
unlinesB [] = mempty
|
||||
unlinesB xs = mconcat (intersperse (TB.singleton '\n') xs) <> TB.singleton '\n'
|
||||
|
||||
-- | Read a decimal number from a Text. Assumes the input consists only of digit
|
||||
-- characters.
|
||||
|
||||
@ -137,7 +137,7 @@ accountTransactionsReportItemAsCsvRecord
|
||||
-- | Render a register report as plain text suitable for console output.
|
||||
accountTransactionsReportAsText :: CliOpts -> Query -> Query -> AccountTransactionsReport -> TL.Text
|
||||
accountTransactionsReportAsText copts reportq thisacctq items
|
||||
= TB.toLazyText . mconcat . intersperse (TB.fromText "\n") $
|
||||
= TB.toLazyText . unlinesB $
|
||||
title :
|
||||
map (accountTransactionsReportItemAsText copts reportq thisacctq amtwidth balwidth) items
|
||||
where
|
||||
|
||||
@ -369,9 +369,6 @@ balanceReportAsText opts ((items, total)) =
|
||||
unlinesB lines
|
||||
<> unlinesB (if no_total_ opts then [] else [overline, totalLines])
|
||||
where
|
||||
unlinesB [] = mempty
|
||||
unlinesB xs = mconcat (intersperse (TB.singleton '\n') xs) <> TB.singleton '\n'
|
||||
|
||||
(lines, sizes) = unzip $ map (balanceReportItemAsText opts) items
|
||||
-- abuse renderBalanceReportItem to render the total with similar format
|
||||
(totalLines, _) = renderBalanceReportItem opts ("",0,total)
|
||||
|
||||
@ -103,8 +103,6 @@ postingsReportAsText opts items =
|
||||
balwidth = maximumStrict $ map (wbWidth . showAmt . itembal) items
|
||||
itemamt (_,_,_,Posting{pamount=a},_) = a
|
||||
itembal (_,_,_,_,a) = a
|
||||
unlinesB [] = mempty
|
||||
unlinesB xs = mconcat (intersperse (TB.fromText "\n") xs) <> TB.fromText "\n"
|
||||
showAmt = showMixedAmountB noColour{displayMinWidth=Just 12}
|
||||
|
||||
-- | Render one register report line item as plain text. Layout is like so:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user