;print: differentiate posting indent (4spc) and pre-comment space (2spc)
Co-authored-by: Simon Michael <simon@joyful.com>
This commit is contained in:
		
							parent
							
								
									1fa4419cd1
								
							
						
					
					
						commit
						8f3e5f9d3b
					
				| @ -169,11 +169,16 @@ showTransactionHelper elide onelineamounts t = | |||||||
|                                                 c:cs -> (c,cs) |                                                 c:cs -> (c,cs) | ||||||
| 
 | 
 | ||||||
| -- | Render a transaction or posting's comment as indented, semicolon-prefixed comment lines. | -- | Render a transaction or posting's comment as indented, semicolon-prefixed comment lines. | ||||||
|  | -- The first line (unless empty) will have leading space, subsequent lines will have a larger indent. | ||||||
| renderCommentLines :: Text -> [String] | renderCommentLines :: Text -> [String] | ||||||
| renderCommentLines t  = case lines $ T.unpack t of ("":ls) -> "":map commentprefix ls | renderCommentLines t = | ||||||
|                                                    ls      -> map commentprefix ls |   case lines $ T.unpack t of | ||||||
|     where |     []      -> [] | ||||||
|       commentprefix = indent . ("; "++) |     [l]     -> [(commentSpace . comment) l]        -- single-line comment | ||||||
|  |     ("":ls) -> "" : map (lineIndent . comment) ls  -- multi-line comment with empty first line | ||||||
|  |     (l:ls)  -> (commentSpace . comment) l : map (lineIndent . comment) ls | ||||||
|  |   where | ||||||
|  |     comment = ("; "++) | ||||||
| 
 | 
 | ||||||
| -- | Given a transaction and its postings, render the postings, suitable | -- | Given a transaction and its postings, render the postings, suitable | ||||||
| -- for `print` output. Normally this output will be valid journal syntax which | -- for `print` output. Normally this output will be valid journal syntax which | ||||||
| @ -230,7 +235,7 @@ postingAsLines elideamount onelineamounts pstoalignwith p = concat [ | |||||||
|   where |   where | ||||||
|     postingblocks = [map rstrip $ lines $ concatTopPadded [statusandaccount, "  ", amount, assertion, samelinecomment] | amount <- shownAmounts] |     postingblocks = [map rstrip $ lines $ concatTopPadded [statusandaccount, "  ", amount, assertion, samelinecomment] | amount <- shownAmounts] | ||||||
|     assertion = maybe "" ((' ':).showBalanceAssertion) $ pbalanceassertion p  |     assertion = maybe "" ((' ':).showBalanceAssertion) $ pbalanceassertion p  | ||||||
|     statusandaccount = indent $ fitString (Just $ minwidth) Nothing False True $ pstatusandacct p |     statusandaccount = lineIndent $ fitString (Just $ minwidth) Nothing False True $ pstatusandacct p | ||||||
|         where |         where | ||||||
|           -- pad to the maximum account name width, plus 2 to leave room for status flags, to keep amounts aligned   |           -- pad to the maximum account name width, plus 2 to leave room for status flags, to keep amounts aligned   | ||||||
|           minwidth = maximum $ map ((2+) . textWidth . T.pack . pacctstr) pstoalignwith |           minwidth = maximum $ map ((2+) . textWidth . T.pack . pacctstr) pstoalignwith | ||||||
| @ -259,7 +264,7 @@ showBalanceAssertion BalanceAssertion{..} = | |||||||
| 
 | 
 | ||||||
| -- | Render a posting, simply. Used in balance assertion errors. | -- | Render a posting, simply. Used in balance assertion errors. | ||||||
| -- showPostingLine p = | -- showPostingLine p = | ||||||
| --   indent $ | --   lineIndent $ | ||||||
| --   if pstatus p == Cleared then "* " else "" ++  -- XXX show ! | --   if pstatus p == Cleared then "* " else "" ++  -- XXX show ! | ||||||
| --   showAccountName Nothing (ptype p) (paccount p) ++ | --   showAccountName Nothing (ptype p) (paccount p) ++ | ||||||
| --   "    " ++ | --   "    " ++ | ||||||
| @ -276,8 +281,13 @@ showPostingLines p = postingAsLines False False ps p where | |||||||
|     ps | Just t <- ptransaction p = tpostings t |     ps | Just t <- ptransaction p = tpostings t | ||||||
|        | otherwise = [p] |        | otherwise = [p] | ||||||
| 
 | 
 | ||||||
| indent :: String -> String | -- | Prepend a suitable indent for a posting (or transaction/posting comment) line. | ||||||
| indent = ("    "++) | lineIndent :: String -> String | ||||||
|  | lineIndent = ("    "++) | ||||||
|  | 
 | ||||||
|  | -- | Prepend the space required before a same-line comment. | ||||||
|  | commentSpace :: String -> String | ||||||
|  | commentSpace = ("  "++) | ||||||
| 
 | 
 | ||||||
| -- | Show an account name, clipped to the given width if any, and | -- | Show an account name, clipped to the given width if any, and | ||||||
| -- appropriately bracketed/parenthesised for the given posting type. | -- appropriately bracketed/parenthesised for the given posting type. | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user