lib: Remove some uses of pad(Left|Right)Wide to ensure we're using the
width provided by showMixed. Also refactor renderTable to be a bit clearer, and to avoid duplicate calculations.
This commit is contained in:
		
							parent
							
								
									e9a16edb58
								
							
						
					
					
						commit
						7e47c11fda
					
				| @ -168,7 +168,7 @@ showPosting p@Posting{paccount=a,pamount=amt,ptype=t} = | ||||
|                           BalancedVirtualPosting -> (\s -> "["++s++"]", acctnamewidth-2) | ||||
|                           VirtualPosting -> (\s -> "("++s++")", acctnamewidth-2) | ||||
|                           _ -> (id,acctnamewidth) | ||||
|       showamount = padLeftWide 12 . showMixedAmount | ||||
|       showamount = fst . showMixed showAmount (Just 12) Nothing False | ||||
| 
 | ||||
| 
 | ||||
| showComment :: Text -> String | ||||
|  | ||||
| @ -22,27 +22,32 @@ renderTable :: Bool              -- ^ Whether to display the outer borders | ||||
|             -> String | ||||
| renderTable borders pretty fr fc f (Table rh ch cells) = | ||||
|   unlines . addBorders $ | ||||
|     [ renderColumns borders pretty sizes ch2 | ||||
|     , bar VM DoubleLine   -- +======================================+ | ||||
|     ] ++ | ||||
|     (renderRs $ fmap renderR $ zipHeader [] cells $ fmap fr rh) | ||||
|     renderColumns borders pretty sizes ch2 | ||||
|     : bar VM DoubleLine   -- +======================================+ | ||||
|     : renderRs (fmap renderR $ zipHeader [] cellContents rowHeaders) | ||||
|  where | ||||
|   bar vpos prop = concat $ renderHLine vpos borders pretty sizes ch2 prop | ||||
|   -- ch2 and cell2 include the row and column labels | ||||
|   ch2 = Group DoubleLine [Header emptyCell, fmap fc ch] | ||||
|   cells2 = headerContents ch2 | ||||
|          : zipWith (\h cs -> h : map f cs) rhStrings cells | ||||
|   -- | ||||
|   renderR (cs,h) = renderColumns borders pretty sizes $ Group DoubleLine | ||||
|                     [ Header h | ||||
|                     , fmap fst $ zipHeader emptyCell (map f cs) ch] | ||||
|   rhStrings = map fr $ headerContents rh | ||||
|                      [ Header h | ||||
|                      , fmap fst $ zipHeader emptyCell cs colHeaders | ||||
|                      ] | ||||
| 
 | ||||
|   rowHeaders   = fmap fr rh | ||||
|   colHeaders   = fmap fc ch | ||||
|   cellContents = map (map f) cells | ||||
| 
 | ||||
|   -- ch2 and cell2 include the row and column labels | ||||
|   ch2 = Group DoubleLine [Header emptyCell, colHeaders] | ||||
|   cells2 = headerContents ch2 : zipWith (:) (headerContents rowHeaders) cellContents | ||||
| 
 | ||||
|   -- maximum width for each column | ||||
|   sizes   = map (maximum . map csWidth) $ transpose cells2 | ||||
|   renderRs (Header s)   = [s] | ||||
|   renderRs (Group p hs) = concat . intersperse sep $ map renderRs hs | ||||
|     where sep = renderHLine VM borders pretty sizes ch2 p | ||||
| 
 | ||||
|   -- borders and bars | ||||
|   addBorders xs = if borders then bar VT SingleLine : xs ++ [bar VB SingleLine] else xs | ||||
|   bar vpos prop = concat $ renderHLine vpos borders pretty sizes ch2 prop | ||||
| 
 | ||||
| 
 | ||||
| data CellSpec = CellSpec | ||||
| @ -90,8 +95,8 @@ renderColumns borders pretty is h = addBorders coreLine | ||||
|   addBorders xs = if borders then leftBar pretty ++ xs ++ rightBar pretty else ' ' : xs ++ " " | ||||
|   coreLine = concatMap helper $ flattenHeader $ zipHeader 0 is h | ||||
|   helper = either hsep (\(w, cs) -> case csAlign cs of | ||||
|                             AlignLeft  -> padRightWide w (csString cs) | ||||
|                             AlignRight -> padLeftWide  w (csString cs) | ||||
|                             AlignLeft  -> csString cs ++ replicate (w - csWidth cs) ' ' | ||||
|                             AlignRight -> replicate (w - csWidth cs) ' ' ++ csString cs | ||||
|                         ) | ||||
|   hsep :: Properties -> String | ||||
|   hsep NoLine     = "  " | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user