print: always right-align amounts
print now always right-aligns the amounts in an entry, even when they are wider than 12 characters. If there is a price, it's considered part of the amount for right-alignment. Maybe it would be nicer to put amounts and prices in separate columns ? That will get a little complicated, needs more discussion/design. Also some cleanup of postingAsLines.
This commit is contained in:
		
							parent
							
								
									155722d7ee
								
							
						
					
					
						commit
						eb75946e64
					
				@ -175,19 +175,25 @@ postingAsLines elideamount ps p =
 | 
				
			|||||||
    postinglines
 | 
					    postinglines
 | 
				
			||||||
    ++ newlinecomments
 | 
					    ++ newlinecomments
 | 
				
			||||||
  where
 | 
					  where
 | 
				
			||||||
    postinglines = map rstrip $ lines $ concatTopPadded [showacct p, "  ", amount, samelinecomment]
 | 
					    postinglines = map rstrip $ lines $ concatTopPadded [account, "  ", amount, samelinecomment]
 | 
				
			||||||
    amount = if elideamount then "" else showamt (pamount p)
 | 
					
 | 
				
			||||||
 | 
					    account =
 | 
				
			||||||
 | 
					      indent $
 | 
				
			||||||
 | 
					        showstatus p ++ fitString (Just acctwidth) Nothing False True (showAccountName Nothing (ptype p) (paccount p))
 | 
				
			||||||
 | 
					        where
 | 
				
			||||||
 | 
					          showstatus p = if pstatus p == Cleared then "* " else ""
 | 
				
			||||||
 | 
					          acctwidth = maximum $ map (strWidth . paccount) ps
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    -- currently prices are considered part of the amount string when right-aligning amounts
 | 
				
			||||||
 | 
					    amount
 | 
				
			||||||
 | 
					      | elideamount = ""
 | 
				
			||||||
 | 
					      | otherwise   = fitStringMulti (Just amtwidth) Nothing False False $ showMixedAmount $ pamount p
 | 
				
			||||||
 | 
					      where
 | 
				
			||||||
 | 
					        amtwidth = maximum $ 12 : map (strWidth . showMixedAmount . pamount) ps  -- min. 12 for backwards compatibility
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    (samelinecomment, newlinecomments) =
 | 
					    (samelinecomment, newlinecomments) =
 | 
				
			||||||
      case renderCommentLines (pcomment p) of []   -> ("",[])
 | 
					      case renderCommentLines (pcomment p) of []   -> ("",[])
 | 
				
			||||||
                                              c:cs -> (c,cs)
 | 
					                                              c:cs -> (c,cs)
 | 
				
			||||||
    showacct p =
 | 
					 | 
				
			||||||
      indent $
 | 
					 | 
				
			||||||
        showstatus p ++ fitString (Just w) Nothing False True (showAccountName Nothing (ptype p) (paccount p))
 | 
					 | 
				
			||||||
        where
 | 
					 | 
				
			||||||
          showstatus p = if pstatus p == Cleared then "* " else ""
 | 
					 | 
				
			||||||
          w = maximum $ map (strWidth . paccount) ps
 | 
					 | 
				
			||||||
    showamt =
 | 
					 | 
				
			||||||
        padLeftWide 12 . showMixedAmount
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
tests_postingAsLines = [
 | 
					tests_postingAsLines = [
 | 
				
			||||||
   "postingAsLines" ~: do
 | 
					   "postingAsLines" ~: do
 | 
				
			||||||
 | 
				
			|||||||
@ -1,17 +1,46 @@
 | 
				
			|||||||
# ALl output should preserve alignment etc. when showing wide characters.
 | 
					# ALl output should preserve alignment etc. when showing wide characters
 | 
				
			||||||
# XXX For a better test, the sample journals should have commodity symbols.
 | 
					# (in apps and fonts which render wide chars as exactly double width).
 | 
				
			||||||
# XXX How to test hledger-ui ?
 | 
					#
 | 
				
			||||||
 | 
					# XXX add commodity symbols and prices to the sample journals
 | 
				
			||||||
 | 
					# XXX how to test hledger-ui ?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# 1.
 | 
					# 1.
 | 
				
			||||||
hledger -f chinese.journal print
 | 
					# hledger -f chinese.journal print
 | 
				
			||||||
 | 
					# >>>
 | 
				
			||||||
 | 
					# 2014/01/01 transaction 1
 | 
				
			||||||
 | 
					#     㐀                1
 | 
				
			||||||
 | 
					#     㐀:㐁            -1
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# 2014/01/02 transaction 2
 | 
				
			||||||
 | 
					#     㐀:㐁:㐂                1
 | 
				
			||||||
 | 
					#     㐀:㐁:㐂:㐃            -1
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# 2014/01/03 transaction 3
 | 
				
			||||||
 | 
					#     㐀:㐁:㐂:㐃:㐄             1
 | 
				
			||||||
 | 
					#     㐀                        -1
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# >>>=0
 | 
				
			||||||
 | 
					hledger -f - print
 | 
				
			||||||
 | 
					<<<
 | 
				
			||||||
 | 
					2014-01-01 transaction 1
 | 
				
			||||||
 | 
					  㐀                                          㐃㐃1 @ 2 㐂㐂㐂㐂㐂㐂㐂㐂㐂㐂㐂
 | 
				
			||||||
 | 
					  㐀:㐁                                       ;㐃㐃-1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					2014-01-02 transaction 2
 | 
				
			||||||
 | 
					  㐀:㐁:㐂                                    USD 1
 | 
				
			||||||
 | 
					  㐀:㐁:㐂:㐃                                EUR -1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					2014-01-03 transaction 3
 | 
				
			||||||
 | 
					  㐀:㐁:㐂:㐃:㐄                                  1
 | 
				
			||||||
 | 
					  㐀                                            -1
 | 
				
			||||||
>>>
 | 
					>>>
 | 
				
			||||||
2014/01/01 transaction 1
 | 
					2014/01/01 transaction 1
 | 
				
			||||||
    㐀                1
 | 
					    㐀     㐃㐃1 @ 2 㐂㐂㐂㐂㐂㐂㐂㐂㐂㐂㐂
 | 
				
			||||||
    㐀:㐁            -1
 | 
					    㐀:㐁         -2 㐂㐂㐂㐂㐂㐂㐂㐂㐂㐂㐂    ; 㐃㐃-1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
2014/01/02 transaction 2
 | 
					2014/01/02 transaction 2
 | 
				
			||||||
    㐀:㐁:㐂                1
 | 
					    㐀:㐁:㐂     USD 1 @@ EUR 1
 | 
				
			||||||
    㐀:㐁:㐂:㐃            -1
 | 
					    㐀:㐁:㐂:㐃          EUR -1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
2014/01/03 transaction 3
 | 
					2014/01/03 transaction 3
 | 
				
			||||||
    㐀:㐁:㐂:㐃:㐄             1
 | 
					    㐀:㐁:㐂:㐃:㐄             1
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user