mirror of
https://github.com/simonmichael/hledger.git
synced 2024-11-10 05:39:31 +03:00
86fab58e6a
This patch fixes broken layout of some commands when there is Unicode text in the ledger file. I substituted System.IO functions with System.IO.UTF8. Now all strings are Unicode internally, and take's and length's work correctly. In particular, add, balance, hist, print and register commands seem to work correctly; ui is still broken for me, I didn't try web. I decode command line arguments from UTF8 forcefully, to permit searches for accounts and descriptions with Unicode (otherwise, it does not work). The patch adds an additional dependency: utf8-string. This patch does not include new test cases.
49 lines
1.5 KiB
Haskell
49 lines
1.5 KiB
Haskell
{-|
|
|
|
|
Print a histogram report.
|
|
|
|
-}
|
|
|
|
module HistogramCommand
|
|
where
|
|
import Prelude hiding (putStr)
|
|
import qualified Data.Map as Map
|
|
import Data.Map ((!))
|
|
import Ledger
|
|
import Options
|
|
import System.IO.UTF8
|
|
|
|
|
|
barchar = '*'
|
|
|
|
-- | Print a histogram of some statistic per reporting interval, such as
|
|
-- number of transactions per day.
|
|
histogram :: [Opt] -> [String] -> Ledger -> IO ()
|
|
histogram opts args l =
|
|
mapM_ (printDayWith countBar) daytxns
|
|
where
|
|
i = intervalFromOpts opts
|
|
interval | i == NoInterval = Daily
|
|
| otherwise = i
|
|
fullspan = rawLedgerDateSpan $ rawledger l
|
|
days = filter (DateSpan Nothing Nothing /=) $ splitSpan interval fullspan
|
|
daytxns = [(s, filter (isTransactionInDateSpan s) ts) | s <- days]
|
|
-- same as RegisterCommand
|
|
ts = sortBy (comparing date) $ filterempties $ filter matchapats $ filterdepth $ ledgerTransactions l
|
|
filterempties
|
|
| Empty `elem` opts = id
|
|
| otherwise = filter (not . isZeroMixedAmount . amount)
|
|
matchapats t = matchpats apats $ account t
|
|
(apats,_) = parsePatternArgs args
|
|
filterdepth | interval == NoInterval = filter (\t -> (accountNameLevel $ account t) <= depth)
|
|
| otherwise = id
|
|
depth = depthFromOpts opts
|
|
|
|
printDayWith f (DateSpan b _, ts) = putStrLn $ printf "%s %s" (show $ fromJust b) (f ts)
|
|
|
|
countBar ts = replicate (length ts) barchar
|
|
|
|
total ts = show $ sumTransactions ts
|
|
|
|
-- totalBar ts = replicate (sumTransactions ts) barchar
|