print, register, balance: fix layout with mixed-commodity amounts
This commit is contained in:
		
							parent
							
								
									7e161bbebf
								
							
						
					
					
						commit
						b5d1ebba30
					
				| @ -150,7 +150,7 @@ showPostingsWithBalance (p:ps) pprev bal = this ++ showPostingsWithBalance ps p | |||||||
| 
 | 
 | ||||||
| -- | Show one posting and running balance, with or without transaction info. | -- | Show one posting and running balance, with or without transaction info. | ||||||
| showPostingWithBalance :: Bool -> Posting -> MixedAmount -> String | showPostingWithBalance :: Bool -> Posting -> MixedAmount -> String | ||||||
| showPostingWithBalance withtxninfo p b = concatBottomPadded [txninfo ++ pstr ++ " ", bal] ++ "\n" | showPostingWithBalance withtxninfo p b = concatTopPadded [txninfo, pstr, " ", bal] ++ "\n" | ||||||
|     where |     where | ||||||
|       ledger3ishlayout = False |       ledger3ishlayout = False | ||||||
|       datedescwidth = if ledger3ishlayout then 34 else 32 |       datedescwidth = if ledger3ishlayout then 34 else 32 | ||||||
|  | |||||||
| @ -78,13 +78,18 @@ showTransaction' elide effective t = | |||||||
|               = map showposting (init ps) ++ [showpostingnoamt (last ps)] |               = map showposting (init ps) ++ [showpostingnoamt (last ps)] | ||||||
|           | otherwise = map showposting ps |           | otherwise = map showposting ps | ||||||
|           where |           where | ||||||
|             showposting p = showacct p ++ "  " ++ showamount (pamount p) ++ showcomment (pcomment p) |  | ||||||
|             showpostingnoamt p = rstrip $ showacct p ++ "              " ++ showcomment (pcomment p) |             showpostingnoamt p = rstrip $ showacct p ++ "              " ++ showcomment (pcomment p) | ||||||
|  |             showposting p = concatTopPadded [showacct p | ||||||
|  |                                             ,"  " | ||||||
|  |                                             ,showamt (pamount p) | ||||||
|  |                                             ,showcomment (pcomment p) | ||||||
|  |                                             ] | ||||||
|             showacct p = "    " ++ showstatus p ++ printf (printf "%%-%ds" w) (showAccountName Nothing (ptype p) (paccount p)) |             showacct p = "    " ++ showstatus p ++ printf (printf "%%-%ds" w) (showAccountName Nothing (ptype p) (paccount p)) | ||||||
|             w = maximum $ map (length . paccount) ps |                 where w = maximum $ map (length . paccount) ps | ||||||
|             showamount = printf "%12s" . showMixedAmountOrZero |                       showstatus p = if pstatus p then "* " else "" | ||||||
|  |             showamt = | ||||||
|  |                 padleft 12 . showMixedAmountOrZero | ||||||
|             showcomment s = if null s then "" else "  ; "++s |             showcomment s = if null s then "" else "  ; "++s | ||||||
|             showstatus p = if pstatus p then "* " else "" |  | ||||||
| 
 | 
 | ||||||
| -- | 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. | ||||||
|  | |||||||
							
								
								
									
										41
									
								
								tests/amount-layout-vertical.test
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								tests/amount-layout-vertical.test
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,41 @@ | |||||||
|  | # test mixed amount layout with various commands | ||||||
|  | bin/hledger -f - print | ||||||
|  | <<< | ||||||
|  | 2010/1/1 | ||||||
|  |     a  EUR 1  ; a euro | ||||||
|  |     b  USD 1  ; a dollar | ||||||
|  |     c         ; a euro and a dollar | ||||||
|  | >>> | ||||||
|  | 2010/01/01  | ||||||
|  |     a         EUR 1  ; a euro | ||||||
|  |     b         USD 1  ; a dollar | ||||||
|  |              EUR -1                        | ||||||
|  |     c        USD -1  ; a euro and a dollar | ||||||
|  | 
 | ||||||
|  | # | ||||||
|  | bin/hledger -f - register | ||||||
|  | <<< | ||||||
|  | 2010/1/1 | ||||||
|  |     a  EUR 1  ; a euro | ||||||
|  |     b  USD 1  ; a dollar | ||||||
|  |     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 | ||||||
|  | # | ||||||
|  | bin/hledger -f - balance | ||||||
|  | <<< | ||||||
|  | 2010/1/1 | ||||||
|  |     a  EUR 1  ; a euro | ||||||
|  |     b  USD 1  ; a dollar | ||||||
|  |     c         ; a euro and a dollar | ||||||
|  | >>> | ||||||
|  |                EUR 1  a | ||||||
|  |                USD 1  b | ||||||
|  |               EUR -1    | ||||||
|  |               USD -1  c | ||||||
|  | -------------------- | ||||||
|  |                EUR 0 | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user