lib,cli: Replace concat(Top|Bottom)Padded with textConcat(Top|Bottom)Padded.
This commit is contained in:
		
							parent
							
								
									56e87f934c
								
							
						
					
					
						commit
						bf22c3efdd
					
				| @ -90,7 +90,7 @@ import Hledger.Utils | ||||
| import Hledger.Data.Types | ||||
| import Hledger.Data.Amount | ||||
| import Hledger.Data.AccountName | ||||
| import Hledger.Data.Dates (nulldate, spanContainsDate) | ||||
| import Hledger.Data.Dates (nulldate, showDate, spanContainsDate) | ||||
| import Hledger.Data.Valuation | ||||
| 
 | ||||
| 
 | ||||
| @ -163,16 +163,16 @@ originalPosting p = fromMaybe p $ poriginal p | ||||
| -- XXX once rendered user output, but just for debugging now; clean up | ||||
| showPosting :: Posting -> String | ||||
| showPosting p@Posting{paccount=a,pamount=amt,ptype=t} = | ||||
|     unlines $ [concatTopPadded [show (postingDate p) ++ " ", showaccountname a ++ " ", showamount amt, T.unpack . showComment $ pcomment p]] | ||||
|     T.unpack $ textConcatTopPadded [showDate (postingDate p) <> " ", showaccountname a <> " ", showamt, showComment $ pcomment p] | ||||
|   where | ||||
|     ledger3ishlayout = False | ||||
|     acctnamewidth = if ledger3ishlayout then 25 else 22 | ||||
|       showaccountname = T.unpack . fitText (Just acctnamewidth) Nothing False False . bracket . elideAccountName width | ||||
|     showaccountname = fitText (Just acctnamewidth) Nothing False False . bracket . elideAccountName width | ||||
|     (bracket,width) = case t of | ||||
|                         BalancedVirtualPosting -> (wrap "[" "]", acctnamewidth-2) | ||||
|                         VirtualPosting         -> (wrap "(" ")", acctnamewidth-2) | ||||
|                         _                      -> (id,acctnamewidth) | ||||
|       showamount = wbUnpack . showMixedAmountB noColour{displayMinWidth=Just 12} | ||||
|     showamt = wbToText $ showMixedAmountB noColour{displayMinWidth=Just 12} amt | ||||
| 
 | ||||
| 
 | ||||
| showComment :: Text -> Text | ||||
|  | ||||
| @ -13,22 +13,22 @@ module Hledger.Cli.Commands.Stats ( | ||||
| ) | ||||
| where | ||||
| 
 | ||||
| import Data.List | ||||
| import Data.Default (def) | ||||
| import Data.List (nub, sortOn) | ||||
| import Data.List.Extra (nubSort) | ||||
| import Data.Maybe | ||||
| import Data.Ord | ||||
| import Data.Maybe (fromMaybe) | ||||
| import Data.HashSet (size, fromList) | ||||
| -- import Data.Text (Text) | ||||
| import qualified Data.Text as T | ||||
| import Data.Time.Calendar | ||||
| import System.Console.CmdArgs.Explicit | ||||
| import Text.Printf | ||||
| import qualified Data.Text.Lazy.Builder as TB | ||||
| import Data.Time.Calendar (Day, addDays, diffDays) | ||||
| import System.Console.CmdArgs.Explicit hiding (Group) | ||||
| import Text.Printf (printf) | ||||
| import qualified Data.Map as Map | ||||
| 
 | ||||
| import Hledger | ||||
| import Hledger.Cli.CliOptions | ||||
| import Prelude hiding (putStr) | ||||
| import Hledger.Cli.Utils (writeOutput) | ||||
| import Hledger.Cli.Utils (writeOutputLazyText) | ||||
| import Text.Tabular.AsciiWide | ||||
| 
 | ||||
| 
 | ||||
| statsmode = hledgerCommandMode | ||||
| @ -49,19 +49,18 @@ stats opts@CliOpts{reportspec_=rspec} j = do | ||||
|       reportspan = ledgerDateSpan l `spanDefaultsFrom` queryDateSpan False q | ||||
|       intervalspans = splitSpan (interval_ $ rsOpts rspec) reportspan | ||||
|       showstats = showLedgerStats l d | ||||
|       s = intercalate "\n" $ map showstats intervalspans | ||||
|   writeOutput opts s | ||||
|       s = unlinesB $ map showstats intervalspans | ||||
|   writeOutputLazyText opts $ TB.toLazyText s | ||||
| 
 | ||||
| showLedgerStats :: Ledger -> Day -> DateSpan -> String | ||||
| showLedgerStats :: Ledger -> Day -> DateSpan -> TB.Builder | ||||
| showLedgerStats l today span = | ||||
|     unlines $ map (\(label,value) -> concatBottomPadded [printf fmt1 label, value]) stats | ||||
|     unlinesB $ map (renderRowB def{tableBorders=False, borderSpaces=False} . showRow) stats | ||||
|   where | ||||
|       fmt1 = "%-" ++ show w1 ++ "s: " | ||||
|       -- fmt2 = "%-" ++ show w2 ++ "s" | ||||
|       w1 = maximum $ map (length . fst) stats | ||||
|       -- w2 = maximum $ map (length . show . snd) stats | ||||
|     showRow (label, value) = Group NoLine $ map (Header . textCell TopLeft) | ||||
|       [fitText (Just w1) (Just w1) False True label `T.append` ": ", T.pack value] | ||||
|     w1 = maximum $ map (T.length . fst) stats | ||||
|     stats = [ | ||||
|          ("Main file" :: String, path) -- ++ " (from " ++ source ++ ")") | ||||
|        ("Main file", path) -- ++ " (from " ++ source ++ ")") | ||||
|       ,("Included files", unlines $ drop 1 $ journalFilePaths j) | ||||
|       ,("Transactions span", printf "%s to %s (%d days)" (start span) (end span) days) | ||||
|       ,("Last transaction", maybe "none" show lastdate ++ showelapsed lastelapsed) | ||||
| @ -82,7 +81,7 @@ showLedgerStats l today span = | ||||
|          path = journalFilePath j | ||||
|          ts = sortOn tdate $ filter (spanContainsDate span . tdate) $ jtxns j | ||||
|          as = nub $ map paccount $ concatMap tpostings ts | ||||
|              cs = either error' Map.keys . commodityStylesFromAmounts . concatMap (amountsRaw . pamount) $ concatMap tpostings ts  -- PARTIAL: | ||||
|          cs = either error' Map.keys $ commodityStylesFromAmounts $ concatMap (amountsRaw . pamount) $ concatMap tpostings ts  -- PARTIAL: | ||||
|          lastdate | null ts = Nothing | ||||
|                   | otherwise = Just $ tdate $ last ts | ||||
|          lastelapsed = fmap (diffDays today) lastdate | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user