mirror of
https://github.com/simonmichael/hledger.git
synced 2024-11-08 15:14:49 +03:00
lib: Add wrap convenience function.
This commit is contained in:
parent
646ee0bce5
commit
12a6435c51
@ -165,11 +165,11 @@ showPosting p@Posting{paccount=a,pamount=amt,ptype=t} =
|
||||
where
|
||||
ledger3ishlayout = False
|
||||
acctnamewidth = if ledger3ishlayout then 25 else 22
|
||||
showaccountname = fitString (Just acctnamewidth) Nothing False False . bracket . T.unpack . elideAccountName width
|
||||
showaccountname = T.unpack . fitText (Just acctnamewidth) Nothing False False . bracket . elideAccountName width
|
||||
(bracket,width) = case t of
|
||||
BalancedVirtualPosting -> (\s -> "["++s++"]", acctnamewidth-2)
|
||||
VirtualPosting -> (\s -> "("++s++")", acctnamewidth-2)
|
||||
_ -> (id,acctnamewidth)
|
||||
BalancedVirtualPosting -> (wrap "[" "]", acctnamewidth-2)
|
||||
VirtualPosting -> (wrap "(" ")", acctnamewidth-2)
|
||||
_ -> (id,acctnamewidth)
|
||||
showamount = fst . showMixed showAmount (Just 12) Nothing False
|
||||
|
||||
|
||||
@ -274,9 +274,9 @@ accountNameWithoutPostingType a = case accountNamePostingType a of
|
||||
RegularPosting -> a
|
||||
|
||||
accountNameWithPostingType :: PostingType -> AccountName -> AccountName
|
||||
accountNameWithPostingType BalancedVirtualPosting a = "["<>accountNameWithoutPostingType a<>"]"
|
||||
accountNameWithPostingType VirtualPosting a = "("<>accountNameWithoutPostingType a<>")"
|
||||
accountNameWithPostingType RegularPosting a = accountNameWithoutPostingType a
|
||||
accountNameWithPostingType BalancedVirtualPosting = wrap "[" "]" . accountNameWithoutPostingType
|
||||
accountNameWithPostingType VirtualPosting = wrap "(" ")" . accountNameWithoutPostingType
|
||||
accountNameWithPostingType RegularPosting = accountNameWithoutPostingType
|
||||
|
||||
-- | Prefix one account name to another, preserving posting type
|
||||
-- indicators like concatAccountNames.
|
||||
|
@ -12,6 +12,7 @@ module Hledger.Utils.Text
|
||||
-- underline,
|
||||
-- stripbrackets,
|
||||
textUnbracket,
|
||||
wrap,
|
||||
-- -- quoting
|
||||
quoteIfSpaced,
|
||||
textQuoteIfNeeded,
|
||||
@ -87,6 +88,10 @@ textElideRight :: Int -> Text -> Text
|
||||
textElideRight width t =
|
||||
if T.length t > width then T.take (width - 2) t <> ".." else t
|
||||
|
||||
-- | Wrap a Text with the surrounding Text.
|
||||
wrap :: Text -> Text -> Text -> Text
|
||||
wrap start end x = start <> x <> end
|
||||
|
||||
-- -- | Clip and pad a string to a minimum & maximum width, and/or left/right justify it.
|
||||
-- -- Works on multi-line strings too (but will rewrite non-unix line endings).
|
||||
-- formatString :: Bool -> Maybe Int -> Maybe Int -> String -> String
|
||||
|
@ -81,11 +81,11 @@ postingsReportItemAsCsvRecord (_, _, _, p, b) = [idx,date,code,desc,acct,amt,bal
|
||||
date = showDate $ postingDate p -- XXX csv should show date2 with --date2
|
||||
code = maybe "" (T.unpack . tcode) $ ptransaction p
|
||||
desc = T.unpack $ maybe "" tdescription $ ptransaction p
|
||||
acct = bracket $ T.unpack $ paccount p
|
||||
acct = T.unpack . bracket $ paccount p
|
||||
where
|
||||
bracket = case ptype p of
|
||||
BalancedVirtualPosting -> (\s -> "["++s++"]")
|
||||
VirtualPosting -> (\s -> "("++s++")")
|
||||
BalancedVirtualPosting -> wrap "[" "]"
|
||||
VirtualPosting -> wrap "(" ")"
|
||||
_ -> id
|
||||
amt = showMixedAmountOneLineWithoutPrice False $ pamount p
|
||||
bal = showMixedAmountOneLineWithoutPrice False b
|
||||
|
Loading…
Reference in New Issue
Block a user