{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Hledger.Cli.Utils
(
unsupportedOutputFormatError,
withJournal,
withJournalDo,
withPossibleJournal,
writeOutput,
writeOutputLazyText,
warnIfLargeMultiPeriodReport,
withTitle,
writeOutputWithTitle,
journalTransform,
journalPrepareLotDetail,
journalReload,
journalCheckChange,
journalReloadIfChanged,
journalFileIsNewer,
maybeFileModificationTime,
openBrowserOn,
writeFileWithBackup,
writeFileWithBackupIfChanged,
journalSimilarTransaction,
postingsOrTransactionsReportAsText,
tests_Cli_Utils,
)
where
import Control.Exception (IOException, evaluate, try)
import Control.Monad.Except (ExceptT)
import Control.Monad.IO.Class (liftIO)
import Data.List
import Data.List.NonEmpty qualified as NE (head, toList)
import Data.Map qualified as M
import Data.Maybe
import Data.Set qualified as S
import Data.Text qualified as T
import Data.Text.IO qualified as T
import Data.Text.Lazy qualified as TL
import Data.Text.Lazy.Builder qualified as TB
import Data.Text.Lazy.IO qualified as TL
import Data.Time (Day)
import Data.Time.Clock.POSIX (POSIXTime, utcTimeToPOSIXSeconds)
import Lens.Micro ((^.))
import Safe (readMay, headMay)
import System.Console.CmdArgs
import System.Directory (canonicalizePath, getModificationTime, getDirectoryContents, copyFile, createDirectoryIfMissing, doesFileExist, getXdgDirectory, renameFile, XdgDirectory(..))
import System.Exit
import System.FilePath ((</>), splitFileName, takeDirectory)
import System.Info (os)
import System.IO (hClose, openTempFile, hPutStrLn, stderr)
import System.Process (readProcessWithExitCode)
import Text.Printf
import Text.Regex.TDFA ((=~))
import Web.Browser (openBrowser)
import Hledger.Cli.CliOptions
import Hledger.Cli.Anon
import Hledger.Data
import Hledger.Read
import Hledger.Reports
import Hledger.Utils
import Control.Monad (when)
import Data.Functor ((<&>))
unsupportedOutputFormatError :: String -> String
unsupportedOutputFormatError :: [Char] -> [Char]
unsupportedOutputFormatError [Char]
fmt =
[Char]
"Sorry, output format \""[Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++[Char]
fmt[Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++[Char]
"\" is unrecognised or not yet supported for this kind of report."
[Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ if Char
'.' Char -> [Char] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Char]
fmt Bool -> Bool -> Bool
&& [Char] -> [Char]
filePathExtension [Char]
fmt [Char] -> [[Char]] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [[Char]]
outputFormats
then [Char]
"\nTo write to a file named " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
fmt [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
", use -o (--output-file), not -O (--output-format)."
else [Char]
""
warnIfLargeMultiPeriodReport :: ReportSpec -> Journal -> IO ()
warnIfLargeMultiPeriodReport :: ReportSpec -> Journal -> IO ()
warnIfLargeMultiPeriodReport rspec :: ReportSpec
rspec@ReportSpec{_rsReportOpts :: ReportSpec -> ReportOpts
_rsReportOpts=ReportOpts
ropts} Journal
j =
Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (ReportOpts -> Interval
interval_ ReportOpts
ropts Interval -> Interval -> Bool
forall a. Eq a => a -> a -> Bool
/= Interval
NoInterval Bool -> Bool -> Bool
&& Int
nperiods Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
maxExpectedPeriods) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ [Char] -> IO ()
forall (m :: * -> *). MonadIO m => [Char] -> m ()
warnIO ([Char] -> IO ()) -> [Char] -> IO ()
forall a b. (a -> b) -> a -> b
$ [Char] -> Int -> Text -> [Char]
forall r. PrintfType r => [Char] -> r
printf
([Char]
"this report has %d periods (%s), and may use a lot of memory.\n"
[Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> [Char]
"If not intended, press control-C now, and check for a mistyped date, or narrow the report.")
Int
nperiods (DateSpan -> Text
showDateSpan DateSpan
rspan)
where
(DateSpan
rspan, [DateSpan]
spans) = Journal -> ReportSpec -> (DateSpan, [DateSpan])
reportSpanLazy Journal
j ReportSpec
rspec
nperiods :: Int
nperiods = [DateSpan] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [DateSpan]
spans
maxExpectedPeriods :: Int
maxExpectedPeriods = Int
10000 :: Int
withJournal :: CliOpts -> (Journal -> IO a) -> IO a
withJournal :: forall a. CliOpts -> (Journal -> IO a) -> IO a
withJournal CliOpts
opts Journal -> IO a
cmd = do
journalpaths <- CliOpts -> IO (NonEmpty [Char])
journalFilePathFromOpts CliOpts
opts
let iopts = (CliOpts -> InputOpts
inputopts_ CliOpts
opts){_journaldir = Just (takeDirectory (NE.head journalpaths))}
ej <- runExceptT $ journalTransform opts <$> readJournalFiles iopts (NE.toList journalpaths)
case ej of
Left [Char]
e -> [Char] -> IO a
forall a. [Char] -> a
error' [Char]
e
Right Journal
j -> do
CliOpts -> Journal -> IO ()
maybeWarnUnknownValuationCommodity CliOpts
opts Journal
j
Journal -> IO a
cmd Journal
j
maybeWarnUnknownValuationCommodity :: CliOpts -> Journal -> IO ()
maybeWarnUnknownValuationCommodity :: CliOpts -> Journal -> IO ()
maybeWarnUnknownValuationCommodity CliOpts
opts Journal
j =
case ValuationType -> Maybe Text
valuationTypeValuationCommodity (ValuationType -> Maybe Text) -> Maybe ValuationType -> Maybe Text
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< ReportOpts -> Maybe ValuationType
value_ (ReportSpec -> ReportOpts
_rsReportOpts (ReportSpec -> ReportOpts) -> ReportSpec -> ReportOpts
forall a b. (a -> b) -> a -> b
$ CliOpts -> ReportSpec
reportspec_ CliOpts
opts) of
Just Text
c
| Text
c Text -> Set Text -> Bool
forall a. Ord a => a -> Set a -> Bool
`S.notMember` Journal -> Set Text
journalCommoditiesFromPriceDirectives Journal
j
, Text
c Text -> Set Text -> Bool
forall a. Ord a => a -> Set a -> Bool
`S.notMember` Journal -> Set Text
journalCommoditiesFromTransactions Journal
j
, Text
c Text -> [Text] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` (Commodity -> [Text]) -> Map Text Commodity -> [Text]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap Commodity -> [Text]
commodityAliases (Journal -> Map Text Commodity
jdeclaredcommodities Journal
j) ->
[Char] -> IO ()
forall (m :: * -> *). MonadIO m => [Char] -> m ()
warnIO ([Char] -> IO ()) -> [Char] -> IO ()
forall a b. (a -> b) -> a -> b
$ [Char]
"no conversion prices to \"" [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> Text -> [Char]
T.unpack Text
c [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> [Char]
"\" can be found." [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> Text -> [Char]
suggestion Text
c
Maybe Text
_ -> () -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
where
suggestion :: Text -> [Char]
suggestion Text
c = case [Text
s | Text
s <- Set Text -> [Text]
forall a. Set a -> [a]
S.toList (Journal -> Set Text
journalCommodities Journal
j), Text
s Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
/= Text
c, Text -> Text
toCurrencyCode Text
s Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text -> Text
toCurrencyCode Text
c] of
(Text
s:[Text]
_) -> [Char]
" Did you mean \"" [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> Text -> [Char]
T.unpack Text
s [Char] -> [Char] -> [Char]
forall a. Semigroup a => a -> a -> a
<> [Char]
"\" ?"
[] -> [Char]
""
{-# DEPRECATED withJournalDo "renamed, please use withJournal instead" #-}
withJournalDo :: CliOpts -> (Journal -> IO a) -> IO a
withJournalDo = CliOpts -> (Journal -> IO a) -> IO a
forall a. CliOpts -> (Journal -> IO a) -> IO a
withJournal
withPossibleJournal :: CliOpts -> (Journal -> IO a) -> IO a
withPossibleJournal :: forall a. CliOpts -> (Journal -> IO a) -> IO a
withPossibleJournal CliOpts
opts Journal -> IO a
cmd = do
journalpaths <- CliOpts -> IO (Maybe (NonEmpty [Char]))
journalFilePathFromOptsNoDefault CliOpts
opts
fs <- case journalpaths of
Just NonEmpty [Char]
paths -> [[Char]] -> IO [[Char]]
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ([[Char]] -> IO [[Char]]) -> [[Char]] -> IO [[Char]]
forall a b. (a -> b) -> a -> b
$ NonEmpty [Char] -> [[Char]]
forall a. NonEmpty a -> [a]
NE.toList NonEmpty [Char]
paths
Maybe (NonEmpty [Char])
Nothing -> ([Char] -> [[Char]] -> [[Char]]
forall a. a -> [a] -> [a]
:[]) ([Char] -> [[Char]]) -> IO [Char] -> IO [[Char]]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IO [Char]
defaultJournalPath
let iopts = (CliOpts -> InputOpts
inputopts_ CliOpts
opts){_journaldir = takeDirectory <$> headMay fs}
j <- runExceptT $ journalTransform opts <$> readPossibleJournalFiles iopts fs
either error' cmd j
journalTransform :: CliOpts -> Journal -> Journal
journalTransform :: CliOpts -> Journal -> Journal
journalTransform CliOpts
opts =
CliOpts -> Journal -> Journal
maybePivot CliOpts
opts
(Journal -> Journal) -> (Journal -> Journal) -> Journal -> Journal
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> CliOpts -> Journal -> Journal
maybeWarnAboutAnon CliOpts
opts
(Journal -> Journal) -> (Journal -> Journal) -> Journal -> Journal
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> CliOpts -> Journal -> Journal
maybeObfuscate CliOpts
opts
(Journal -> Journal) -> (Journal -> Journal) -> Journal -> Journal
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> CliOpts -> Journal -> Journal
maybePrepareLotDetail CliOpts
opts
maybePrepareLotDetail :: CliOpts -> Journal -> Journal
maybePrepareLotDetail :: CliOpts -> Journal -> Journal
maybePrepareLotDetail CliOpts
opts
| CliOpts -> [Char]
command_ CliOpts
opts [Char] -> [Char] -> Bool
forall a. Eq a => a -> a -> Bool
== [Char]
"holdings" = Journal -> Journal
forall a. a -> a
id
| Bool
otherwise = ReportOpts -> Bool -> Journal -> Journal
journalPrepareLotDetail (ReportSpec -> ReportOpts
_rsReportOpts (ReportSpec -> ReportOpts) -> ReportSpec -> ReportOpts
forall a b. (a -> b) -> a -> b
$ CliOpts -> ReportSpec
reportspec_ CliOpts
opts) Bool
keeplots
where
rawopts :: RawOpts
rawopts = CliOpts -> RawOpts
rawopts_ CliOpts
opts
keeplots :: Bool
keeplots = [Char] -> RawOpts -> Bool
boolopt [Char]
"lots" RawOpts
rawopts
Bool -> Bool -> Bool
|| [Char] -> RawOpts -> Bool
boolopt [Char]
"ignore-lots" RawOpts
rawopts
journalPrepareLotDetail :: ReportOpts -> Bool -> Journal -> Journal
journalPrepareLotDetail :: ReportOpts -> Bool -> Journal -> Journal
journalPrepareLotDetail ReportOpts
ropts Bool
keeplots
| Bool
keeplots = Journal -> Journal
setCostsToBasisForGain
| Bool
otherwise = Journal -> Journal
journalCollapseLotDetail (Journal -> Journal) -> (Journal -> Journal) -> Journal -> Journal
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Journal -> Journal
setCostsToBasisForGain (Journal -> Journal) -> (Journal -> Journal) -> Journal -> Journal
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Journal -> Journal
convertFragmentsToCostBasis
where
convertFragmentsToCostBasis :: Journal -> Journal
convertFragmentsToCostBasis
| ReportOpts -> Maybe ConversionOp
conversionop_ ReportOpts
ropts Maybe ConversionOp -> Maybe ConversionOp -> Bool
forall a. Eq a => a -> a -> Bool
== ConversionOp -> Maybe ConversionOp
forall a. a -> Maybe a
Just ConversionOp
ToCost = \Journal
j -> Journal
j{jtxns = map convertTxn $ jtxns j}
| Bool
otherwise = Journal -> Journal
forall a. a -> a
id
convertTxn :: Transaction -> Transaction
convertTxn Transaction
t
| (Posting -> Bool) -> [Posting] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any Posting -> Bool
isfragment (Transaction -> [Posting]
tpostings Transaction
t) = Transaction
t{tpostings = mapMaybe (\Posting
p -> if Posting -> Bool
isfragment Posting
p then ConversionOp -> Posting -> Maybe Posting
postingToCost ConversionOp
ToCost Posting
p else Posting -> Maybe Posting
forall a. a -> Maybe a
Just Posting
p) $ tpostings t}
| Bool
otherwise = Transaction
t
isfragment :: Posting -> Bool
isfragment = Text -> Posting -> Bool
postingHasTag Text
lotsplitPostingTagName
setCostsToBasisForGain :: Journal -> Journal
setCostsToBasisForGain
| ReportOpts -> BalanceCalculation
balancecalc_ ReportOpts
ropts BalanceCalculation -> BalanceCalculation -> Bool
forall a. Eq a => a -> a -> Bool
== BalanceCalculation
CalcGain = (MixedAmount -> MixedAmount) -> Journal -> Journal
journalMapPostingAmounts ((Amount -> Amount) -> MixedAmount -> MixedAmount
mapMixedAmount Amount -> Amount
amountSetCostToBasis)
| Bool
otherwise = Journal -> Journal
forall a. a -> a
id
maybePivot :: CliOpts -> Journal -> Journal
maybePivot :: CliOpts -> Journal -> Journal
maybePivot CliOpts
opts =
case [Char] -> RawOpts -> Maybe [Char]
maybestringopt [Char]
"pivot" (RawOpts -> Maybe [Char])
-> (CliOpts -> RawOpts) -> CliOpts -> Maybe [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CliOpts -> RawOpts
rawopts_ (CliOpts -> Maybe [Char]) -> CliOpts -> Maybe [Char]
forall a b. (a -> b) -> a -> b
$ CliOpts
opts of
Just [Char]
tag -> Text -> Journal -> Journal
journalPivot (Text -> Journal -> Journal) -> Text -> Journal -> Journal
forall a b. (a -> b) -> a -> b
$ [Char] -> Text
T.pack [Char]
tag
Maybe [Char]
Nothing -> Journal -> Journal
forall a. a -> a
id
maybeWarnAboutAnon :: CliOpts -> Journal -> Journal
maybeWarnAboutAnon :: CliOpts -> Journal -> Journal
maybeWarnAboutAnon CliOpts
opts =
if [Char] -> RawOpts -> Bool
boolopt [Char]
"anon" (RawOpts -> Bool) -> RawOpts -> Bool
forall a b. (a -> b) -> a -> b
$ CliOpts -> RawOpts
rawopts_ CliOpts
opts
then [Char] -> Journal -> Journal
forall a. [Char] -> a
error' ([Char] -> Journal -> Journal) -> [Char] -> Journal -> Journal
forall a b. (a -> b) -> a -> b
$ [[Char]] -> [Char]
unlines [
[Char]
"--anon does not give privacy, and perhaps should be avoided;"
,[Char]
"please see https://github.com/hledgerorg/hledger/issues/2133 ."
,[Char]
"For now it has been renamed to --obfuscate (a hidden flag)."
]
else Journal -> Journal
forall a. a -> a
id
maybeObfuscate :: CliOpts -> Journal -> Journal
maybeObfuscate :: CliOpts -> Journal -> Journal
maybeObfuscate CliOpts
opts =
if InputOpts -> Bool
anon_ (InputOpts -> Bool) -> (CliOpts -> InputOpts) -> CliOpts -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CliOpts -> InputOpts
inputopts_ (CliOpts -> Bool) -> CliOpts -> Bool
forall a b. (a -> b) -> a -> b
$ CliOpts
opts
then Journal -> Journal
forall a. Anon a => a -> a
anon
else Journal -> Journal
forall a. a -> a
id
writeOutput :: CliOpts -> String -> IO ()
writeOutput :: CliOpts -> [Char] -> IO ()
writeOutput CliOpts
opts [Char]
s = do
mf <- CliOpts -> IO (Maybe [Char])
outputFileOrViewFile CliOpts
opts
case mf of
Maybe [Char]
Nothing -> [Char] -> IO ()
putStr [Char]
s
Just [Char]
f -> Int -> IO Int
forall a. a -> IO a
evaluate ([Char] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Char]
s) IO Int -> IO () -> IO ()
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [Char] -> [Char] -> IO ()
writeFile [Char]
f [Char]
s IO () -> IO () -> IO ()
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> CliOpts -> [Char] -> IO ()
viewIfRequested CliOpts
opts [Char]
f
writeOutputLazyText :: CliOpts -> TL.Text -> IO ()
writeOutputLazyText :: CliOpts -> Text -> IO ()
writeOutputLazyText CliOpts
opts Text
s = do
mf <- CliOpts -> IO (Maybe [Char])
outputFileOrViewFile CliOpts
opts
case mf of
Maybe [Char]
Nothing -> [Char] -> IO ()
runPager ([Char] -> IO ()) -> [Char] -> IO ()
forall a b. (a -> b) -> a -> b
$ Text -> [Char]
TL.unpack Text
s
Just [Char]
f -> Int64 -> IO Int64
forall a. a -> IO a
evaluate (Text -> Int64
TL.length Text
s) IO Int64 -> IO () -> IO ()
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [Char] -> Text -> IO ()
TL.writeFile [Char]
f Text
s IO () -> IO () -> IO ()
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> CliOpts -> [Char] -> IO ()
viewIfRequested CliOpts
opts [Char]
f
outputFileOrViewFile :: CliOpts -> IO (Maybe FilePath)
outputFileOrViewFile :: CliOpts -> IO (Maybe [Char])
outputFileOrViewFile CliOpts
opts = do
mf <- CliOpts -> IO (Maybe [Char])
outputFileFromOpts CliOpts
opts
case mf of
Maybe [Char]
Nothing | CliOpts -> Bool
viewRequested CliOpts
opts -> [Char] -> Maybe [Char]
forall a. a -> Maybe a
Just ([Char] -> Maybe [Char]) -> IO [Char] -> IO (Maybe [Char])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> CliOpts -> IO [Char]
viewFile CliOpts
opts
Maybe [Char]
_ -> Maybe [Char] -> IO (Maybe [Char])
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe [Char]
mf
viewFile :: CliOpts -> IO FilePath
viewFile :: CliOpts -> IO [Char]
viewFile CliOpts
opts = do
d <- XdgDirectory -> [Char] -> IO [Char]
getXdgDirectory XdgDirectory
XdgCache [Char]
"hledger"
createDirectoryIfMissing True d
let f = [Char]
d [Char] -> [Char] -> [Char]
</> [Char]
"view." [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ CliOpts -> [Char]
outputFormatFromOpts CliOpts
opts
hPutStrLn stderr $ "writing " ++ f ++ " (if it's sensitive, delete it after viewing)"
(tmp, h) <- openTempFile d "view.tmp"
hClose h
renameFile tmp f
return f
viewIfRequested :: CliOpts -> FilePath -> IO ()
viewIfRequested :: CliOpts -> [Char] -> IO ()
viewIfRequested CliOpts
opts [Char]
f = Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (CliOpts -> Bool
viewRequested CliOpts
opts) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$
[Char] -> IO (Either [[Char]] ())
launch [Char]
f IO (Either [[Char]] ()) -> (Either [[Char]] () -> IO ()) -> IO ()
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ([[Char]] -> IO ()) -> (() -> IO ()) -> Either [[Char]] () -> IO ()
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either [[Char]] -> IO ()
forall {m :: * -> *}. MonadIO m => [[Char]] -> m ()
couldnotopen () -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return
where
couldnotopen :: [[Char]] -> m ()
couldnotopen [[Char]]
tried = [Char] -> m ()
forall (m :: * -> *). MonadIO m => [Char] -> m ()
warnIO ([Char] -> m ()) -> [Char] -> m ()
forall a b. (a -> b) -> a -> b
$ [Char] -> [Char] -> [Char]
forall r. PrintfType r => [Char] -> r
printf [Char]
"could not open a viewer (tried: %s)" ([Char] -> [[Char]] -> [Char]
forall a. [a] -> [[a]] -> [a]
intercalate [Char]
", " [[Char]]
tried)
withTitle :: ReportOpts -> TL.Text -> TL.Text
withTitle :: ReportOpts -> Text -> Text
withTitle ReportOpts
ropts Text
body =
let h :: Text
h = ReportOpts -> Text -> Text
effectiveTitle ReportOpts
ropts Text
""
in if Text -> Bool
T.null Text
h then Text
body
else Text -> Text
TL.fromStrict Text
h Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"\n\n" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
body
writeOutputWithTitle :: CliOpts -> T.Text -> IO ()
writeOutputWithTitle :: CliOpts -> Text -> IO ()
writeOutputWithTitle CliOpts
opts =
CliOpts -> [Char] -> IO ()
writeOutput CliOpts
opts ([Char] -> IO ()) -> (Text -> [Char]) -> Text -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> [Char]
TL.unpack (Text -> [Char]) -> (Text -> Text) -> Text -> [Char]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ReportOpts -> Text -> Text
withTitle (ReportSpec -> ReportOpts
_rsReportOpts (ReportSpec -> ReportOpts) -> ReportSpec -> ReportOpts
forall a b. (a -> b) -> a -> b
$ CliOpts -> ReportSpec
reportspec_ CliOpts
opts) (Text -> Text) -> (Text -> Text) -> Text -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
TL.fromStrict
journalReloadIfChanged :: CliOpts -> Day -> Journal -> ExceptT String IO (Journal, Bool)
journalReloadIfChanged :: CliOpts -> Day -> Journal -> ExceptT [Char] IO (Journal, Bool)
journalReloadIfChanged CliOpts
opts Day
_d Journal
j = do
let maybeChangedFilename :: [Char] -> IO (Maybe [Char])
maybeChangedFilename [Char]
f = do newer <- Journal -> [Char] -> IO Bool
journalFileIsNewer Journal
j [Char]
f
return $ if newer then Just f else Nothing
changedfiles <- IO [[Char]] -> ExceptT [Char] IO [[Char]]
forall a. IO a -> ExceptT [Char] IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO [[Char]] -> ExceptT [Char] IO [[Char]])
-> IO [[Char]] -> ExceptT [Char] IO [[Char]]
forall a b. (a -> b) -> a -> b
$ [Maybe [Char]] -> [[Char]]
forall a. [Maybe a] -> [a]
catMaybes ([Maybe [Char]] -> [[Char]]) -> IO [Maybe [Char]] -> IO [[Char]]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ([Char] -> IO (Maybe [Char])) -> [[Char]] -> IO [Maybe [Char]]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM [Char] -> IO (Maybe [Char])
maybeChangedFilename (Journal -> [[Char]]
journalAllFilePaths Journal
j)
case changedfiles of
[] -> (Journal, Bool) -> ExceptT [Char] IO (Journal, Bool)
forall a. a -> ExceptT [Char] IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Journal
j, Bool
False)
[Char]
f:[[Char]]
_ -> do
verbose <- IO Bool -> ExceptT [Char] IO Bool
forall a. IO a -> ExceptT [Char] IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO Bool
isLoud
when (verbose || debugLevel >= 6) . liftIO $ printf "%s has changed, reloading\n" f
newj <- journalReload opts
return (newj, True)
journalReload :: CliOpts -> ExceptT String IO Journal
journalReload :: CliOpts -> ExceptT [Char] IO Journal
journalReload CliOpts
opts = CliOpts -> Map [Char] Text -> ExceptT [Char] IO Journal
journalReloadWithOverrides CliOpts
opts Map [Char] Text
forall k a. Map k a
M.empty
journalCheckChange :: CliOpts -> FilePath -> T.Text -> ExceptT String IO Journal
journalCheckChange :: CliOpts -> [Char] -> Text -> ExceptT [Char] IO Journal
journalCheckChange CliOpts
opts [Char]
f Text
t = do
cf <- IO [Char] -> ExceptT [Char] IO [Char]
forall a. IO a -> ExceptT [Char] IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO [Char] -> ExceptT [Char] IO [Char])
-> IO [Char] -> ExceptT [Char] IO [Char]
forall a b. (a -> b) -> a -> b
$ [Char] -> IO [Char]
canonicalizePath [Char]
f
journalReloadWithOverrides opts $ M.singleton cf t
journalReloadWithOverrides :: CliOpts -> M.Map FilePath T.Text -> ExceptT String IO Journal
journalReloadWithOverrides :: CliOpts -> Map [Char] Text -> ExceptT [Char] IO Journal
journalReloadWithOverrides CliOpts
opts Map [Char] Text
overrides = do
journalpaths <- IO (NonEmpty [Char]) -> ExceptT [Char] IO (NonEmpty [Char])
forall a. IO a -> ExceptT [Char] IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (NonEmpty [Char]) -> ExceptT [Char] IO (NonEmpty [Char]))
-> IO (NonEmpty [Char]) -> ExceptT [Char] IO (NonEmpty [Char])
forall a b. (a -> b) -> a -> b
$ [Char] -> NonEmpty [Char] -> NonEmpty [Char]
forall a. Show a => [Char] -> a -> a
dbg6 [Char]
"reloading files" (NonEmpty [Char] -> NonEmpty [Char])
-> IO (NonEmpty [Char]) -> IO (NonEmpty [Char])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> CliOpts -> IO (NonEmpty [Char])
journalFilePathFromOpts CliOpts
opts
let iopts = (CliOpts -> InputOpts
inputopts_ CliOpts
opts){_journaldir = Just (takeDirectory (NE.head journalpaths)), _fileoverrides = overrides}
journalTransform opts <$> readJournalFiles iopts (NE.toList journalpaths)
journalFileIsNewer :: Journal -> FilePath -> IO Bool
journalFileIsNewer :: Journal -> [Char] -> IO Bool
journalFileIsNewer Journal{jlastreadtime :: Journal -> POSIXTime
jlastreadtime=POSIXTime
tread} [Char]
f = do
mtmod <- [Char] -> IO (Maybe POSIXTime)
maybeFileModificationTime [Char]
f
return $
case mtmod of
Just POSIXTime
tmod -> POSIXTime
tmod POSIXTime -> POSIXTime -> Bool
forall a. Ord a => a -> a -> Bool
> POSIXTime
tread
Maybe POSIXTime
Nothing -> Bool
False
maybeFileModificationTime :: FilePath -> IO (Maybe POSIXTime)
maybeFileModificationTime :: [Char] -> IO (Maybe POSIXTime)
maybeFileModificationTime [Char]
f = do
exists <- [Char] -> IO Bool
doesFileExist [Char]
f
if exists
then do
utc <- getModificationTime f
return . Just $ utcTimeToPOSIXSeconds utc
else
return Nothing
openBrowserOn :: String -> IO ExitCode
openBrowserOn :: [Char] -> IO ExitCode
openBrowserOn [Char]
u = [Char] -> IO (Either [[Char]] ())
launch [Char]
u IO (Either [[Char]] ())
-> (Either [[Char]] () -> IO ExitCode) -> IO ExitCode
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ([[Char]] -> IO ExitCode)
-> (() -> IO ExitCode) -> Either [[Char]] () -> IO ExitCode
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either [[Char]] -> IO ExitCode
couldnotstart (IO ExitCode -> () -> IO ExitCode
forall a b. a -> b -> a
const (IO ExitCode -> () -> IO ExitCode)
-> IO ExitCode -> () -> IO ExitCode
forall a b. (a -> b) -> a -> b
$ ExitCode -> IO ExitCode
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ExitCode
ExitSuccess)
where
couldnotstart :: [[Char]] -> IO ExitCode
couldnotstart [[Char]]
tried = do
[Char] -> IO ()
putStrLn ([Char] -> IO ()) -> [Char] -> IO ()
forall a b. (a -> b) -> a -> b
$ [Char] -> [Char] -> [Char]
forall r. PrintfType r => [Char] -> r
printf [Char]
"Could not start a web browser (tried: %s)" ([Char] -> [Char]) -> [Char] -> [Char]
forall a b. (a -> b) -> a -> b
$ [Char] -> [[Char]] -> [Char]
forall a. [a] -> [[a]] -> [a]
intercalate [Char]
", " [[Char]]
tried
[Char] -> IO ()
putStrLn ([Char] -> IO ()) -> [Char] -> IO ()
forall a b. (a -> b) -> a -> b
$ [Char] -> [Char] -> [Char]
forall r. PrintfType r => [Char] -> r
printf [Char]
"Please open your browser and visit %s" [Char]
u
ExitCode -> IO ExitCode
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (ExitCode -> IO ExitCode) -> ExitCode -> IO ExitCode
forall a b. (a -> b) -> a -> b
$ Int -> ExitCode
ExitFailure Int
127
launch :: String -> IO (Either [String] ())
launch :: [Char] -> IO (Either [[Char]] ())
launch [Char]
u
| [Char]
os [Char] -> [Char] -> Bool
forall a. Eq a => a -> a -> Bool
== [Char]
"mingw32" = do
ok <- [Char] -> IO Bool
openBrowser [Char]
u
return $ if ok then Right () else Left ["the Win32 API"]
| Bool
otherwise = [[Char]] -> IO (Either [[Char]] ())
trylaunchers [[Char]]
launchers
where
trylaunchers :: [[Char]] -> IO (Either [[Char]] ())
trylaunchers ([Char]
cmd:[[Char]]
rest) = do
r <- IO (ExitCode, [Char], [Char])
-> IO (Either IOException (ExitCode, [Char], [Char]))
forall e a. Exception e => IO a -> IO (Either e a)
try (IO (ExitCode, [Char], [Char])
-> IO (Either IOException (ExitCode, [Char], [Char])))
-> IO (ExitCode, [Char], [Char])
-> IO (Either IOException (ExitCode, [Char], [Char]))
forall a b. (a -> b) -> a -> b
$ [Char] -> [[Char]] -> [Char] -> IO (ExitCode, [Char], [Char])
readProcessWithExitCode [Char]
cmd [[Char]
u] [Char]
""
case r of
Right (ExitCode
ExitSuccess,[Char]
_,[Char]
_) -> Either [[Char]] () -> IO (Either [[Char]] ())
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Either [[Char]] () -> IO (Either [[Char]] ()))
-> Either [[Char]] () -> IO (Either [[Char]] ())
forall a b. (a -> b) -> a -> b
$ () -> Either [[Char]] ()
forall a b. b -> Either a b
Right ()
Right (ExitFailure Int
_,[Char]
_,[Char]
_) -> [[Char]] -> IO (Either [[Char]] ())
trylaunchers [[Char]]
rest
Left (IOException
_ :: IOException) -> [[Char]] -> IO (Either [[Char]] ())
trylaunchers [[Char]]
rest
trylaunchers [] = Either [[Char]] () -> IO (Either [[Char]] ())
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Either [[Char]] () -> IO (Either [[Char]] ()))
-> Either [[Char]] () -> IO (Either [[Char]] ())
forall a b. (a -> b) -> a -> b
$ [[Char]] -> Either [[Char]] ()
forall a b. a -> Either a b
Left [[Char]]
launchers
launchers :: [[Char]]
launchers | [Char]
os [Char] -> [Char] -> Bool
forall a. Eq a => a -> a -> Bool
== [Char]
"darwin" = [[Char]
"open"]
| Bool
otherwise = [[Char]
"xdg-open", [Char]
"sensible-browser", [Char]
"gnome-www-browser", [Char]
"firefox"]
writeFileWithBackupIfChanged :: FilePath -> T.Text -> IO Bool
writeFileWithBackupIfChanged :: [Char] -> Text -> IO Bool
writeFileWithBackupIfChanged [Char]
f Text
t = do
s <- [Char] -> IO Text
readFilePortably [Char]
f
if t == s then return False
else backUpFile f >> T.writeFile f t >> return True
writeFileWithBackup :: FilePath -> String -> IO ()
writeFileWithBackup :: [Char] -> [Char] -> IO ()
writeFileWithBackup [Char]
f [Char]
t = [Char] -> IO ()
backUpFile [Char]
f IO () -> IO () -> IO ()
forall a b. IO a -> IO b -> IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> [Char] -> [Char] -> IO ()
writeFile [Char]
f [Char]
t
backUpFile :: FilePath -> IO ()
backUpFile :: [Char] -> IO ()
backUpFile [Char]
fp = do
fs <- [Char] -> IO [[Char]]
safeGetDirectoryContents ([Char] -> IO [[Char]]) -> [Char] -> IO [[Char]]
forall a b. (a -> b) -> a -> b
$ [Char] -> [Char]
takeDirectory ([Char] -> [Char]) -> [Char] -> [Char]
forall a b. (a -> b) -> a -> b
$ [Char]
fp
let (d,f) = splitFileName fp
versions = ([Char] -> Maybe Int) -> [[Char]] -> [Int]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe ([Char]
f [Char] -> [Char] -> Maybe Int
`backupNumber`) [[Char]]
fs
next = [Int] -> Int
forall a. Ord a => [a] -> a
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
maximum (Int
0Int -> [Int] -> [Int]
forall a. a -> [a] -> [a]
:[Int]
versions) Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
f' = [Char] -> [Char] -> Int -> [Char]
forall r. PrintfType r => [Char] -> r
printf [Char]
"%s.%d" [Char]
f Int
next
copyFile fp (d </> f')
safeGetDirectoryContents :: FilePath -> IO [FilePath]
safeGetDirectoryContents :: [Char] -> IO [[Char]]
safeGetDirectoryContents [Char]
"" = [Char] -> IO [[Char]]
getDirectoryContents [Char]
"."
safeGetDirectoryContents [Char]
fp = [Char] -> IO [[Char]]
getDirectoryContents [Char]
fp
backupNumber :: FilePath -> FilePath -> Maybe Int
backupNumber :: [Char] -> [Char] -> Maybe Int
backupNumber [Char]
f [Char]
g = case [Char]
g [Char] -> [Char] -> ([Char], [Char], [Char], [[Char]])
forall source source1 target.
(RegexMaker Regex CompOption ExecOption source,
RegexContext Regex source1 target) =>
source1 -> source -> target
=~ ([Char]
"^" [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
f [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
"\\.([0-9]+)$") of
([Char]
_::FilePath, [Char]
_::FilePath, [Char]
_::FilePath, [[Char]
ext::FilePath]) -> [Char] -> Maybe Int
forall a. Read a => [Char] -> Maybe a
readMay [Char]
ext
([Char], [Char], [Char], [[Char]])
_ -> Maybe Int
forall a. Maybe a
Nothing
journalSimilarTransaction :: CliOpts -> Journal -> T.Text -> Maybe Transaction
journalSimilarTransaction :: CliOpts -> Journal -> Text -> Maybe Transaction
journalSimilarTransaction CliOpts
cliopts Journal
j Text
desc =
((DateWeightedSimilarityScore, Integer,
DateWeightedSimilarityScore, Transaction)
-> Transaction)
-> Maybe
(DateWeightedSimilarityScore, Integer, DateWeightedSimilarityScore,
Transaction)
-> Maybe Transaction
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (DateWeightedSimilarityScore, Integer, DateWeightedSimilarityScore,
Transaction)
-> Transaction
forall {a} {b} {c} {d}. (a, b, c, d) -> d
fourth4 (Maybe
(DateWeightedSimilarityScore, Integer, DateWeightedSimilarityScore,
Transaction)
-> Maybe Transaction)
-> Maybe
(DateWeightedSimilarityScore, Integer, DateWeightedSimilarityScore,
Transaction)
-> Maybe Transaction
forall a b. (a -> b) -> a -> b
$ [(DateWeightedSimilarityScore, Integer,
DateWeightedSimilarityScore, Transaction)]
-> Maybe
(DateWeightedSimilarityScore, Integer, DateWeightedSimilarityScore,
Transaction)
forall a. [a] -> Maybe a
headMay ([(DateWeightedSimilarityScore, Integer,
DateWeightedSimilarityScore, Transaction)]
-> Maybe
(DateWeightedSimilarityScore, Integer, DateWeightedSimilarityScore,
Transaction))
-> [(DateWeightedSimilarityScore, Integer,
DateWeightedSimilarityScore, Transaction)]
-> Maybe
(DateWeightedSimilarityScore, Integer, DateWeightedSimilarityScore,
Transaction)
forall a b. (a -> b) -> a -> b
$ Journal
-> Day
-> Text
-> Query
-> DateWeightedSimilarityScore
-> Int
-> [(DateWeightedSimilarityScore, Integer,
DateWeightedSimilarityScore, Transaction)]
journalTransactionsSimilarTo Journal
j Day
today Text
desc Query
q DateWeightedSimilarityScore
0 Int
1
where
today :: Day
today = CliOpts
cliopts CliOpts -> Getting Day CliOpts Day -> Day
forall s a. s -> Getting a s a -> a
^. Getting Day CliOpts Day
forall c. HasReportSpec c => Lens' c Day
Lens' CliOpts Day
rsDay
q :: Query
q = ReportOpts -> Query
queryFromFlags (ReportOpts -> Query) -> ReportOpts -> Query
forall a b. (a -> b) -> a -> b
$ ReportSpec -> ReportOpts
_rsReportOpts (ReportSpec -> ReportOpts) -> ReportSpec -> ReportOpts
forall a b. (a -> b) -> a -> b
$ CliOpts -> ReportSpec
reportspec_ CliOpts
cliopts
postingsOrTransactionsReportAsText
:: Bool -> CliOpts -> (Int -> Int -> (a, [WideBuilder], [WideBuilder]) -> TB.Builder)
-> (a -> MixedAmount) -> (a -> MixedAmount) -> [a] -> TB.Builder
postingsOrTransactionsReportAsText :: forall a.
Bool
-> CliOpts
-> (Int -> Int -> (a, [WideBuilder], [WideBuilder]) -> Builder)
-> (a -> MixedAmount)
-> (a -> MixedAmount)
-> [a]
-> Builder
postingsOrTransactionsReportAsText Bool
alignAll CliOpts
opts Int -> Int -> (a, [WideBuilder], [WideBuilder]) -> Builder
itemAsText a -> MixedAmount
itemamt a -> MixedAmount
itembal [a]
report =
[Builder] -> Builder
forall a. Monoid a => [a] -> a
mconcat ([Builder] -> Builder)
-> (((Int, Int), [Builder]) -> [Builder])
-> ((Int, Int), [Builder])
-> Builder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Int, Int), [Builder]) -> [Builder]
forall a b. (a, b) -> b
snd (((Int, Int), [Builder]) -> Builder)
-> ((Int, Int), [Builder]) -> Builder
forall a b. (a -> b) -> a -> b
$ ((Int, Int)
-> (a, [WideBuilder], [WideBuilder]) -> ((Int, Int), Builder))
-> (Int, Int)
-> [(a, [WideBuilder], [WideBuilder])]
-> ((Int, Int), [Builder])
forall (t :: * -> *) s a b.
Traversable t =>
(s -> a -> (s, b)) -> s -> t a -> (s, t b)
mapAccumL (Int, Int)
-> (a, [WideBuilder], [WideBuilder]) -> ((Int, Int), Builder)
renderItem (((a, [WideBuilder], [WideBuilder]) -> [WideBuilder]) -> Int
startWidth (a, [WideBuilder], [WideBuilder]) -> [WideBuilder]
forall {a} {b} {c}. (a, b, c) -> b
amt, ((a, [WideBuilder], [WideBuilder]) -> [WideBuilder]) -> Int
startWidth (a, [WideBuilder], [WideBuilder]) -> [WideBuilder]
forall {a} {b} {c}. (a, b, c) -> c
bal) [(a, [WideBuilder], [WideBuilder])]
itemsWithAmounts
where
minWidth :: Int
minWidth = Int
12
chunkSize :: Int
chunkSize = Int
1000
renderItem :: (Int, Int)
-> (a, [WideBuilder], [WideBuilder]) -> ((Int, Int), Builder)
renderItem (Int
amtWidth, Int
balWidth) item :: (a, [WideBuilder], [WideBuilder])
item@(a
_, [WideBuilder]
amt1, [WideBuilder]
bal1) = ((Int
amtWidth', Int
balWidth'), Builder
itemBuilder)
where
itemBuilder :: Builder
itemBuilder = Int -> Int -> (a, [WideBuilder], [WideBuilder]) -> Builder
itemAsText Int
amtWidth' Int
balWidth' (a, [WideBuilder], [WideBuilder])
item
amtWidth' :: Int
amtWidth' = if Bool
alignAll then Int
amtWidth else [Int] -> Int
forall a. Ord a => [a] -> a
maximumStrict ([Int] -> Int) -> [Int] -> Int
forall a b. (a -> b) -> a -> b
$ Int
amtWidth Int -> [Int] -> [Int]
forall a. a -> [a] -> [a]
: (WideBuilder -> Int) -> [WideBuilder] -> [Int]
forall a b. (a -> b) -> [a] -> [b]
map WideBuilder -> Int
wbWidth [WideBuilder]
amt1
balWidth' :: Int
balWidth' = if Bool
alignAll then Int
balWidth else [Int] -> Int
forall a. Ord a => [a] -> a
maximumStrict ([Int] -> Int) -> [Int] -> Int
forall a b. (a -> b) -> a -> b
$ Int
balWidth Int -> [Int] -> [Int]
forall a. a -> [a] -> [a]
: (WideBuilder -> Int) -> [WideBuilder] -> [Int]
forall a b. (a -> b) -> [a] -> [b]
map WideBuilder -> Int
wbWidth [WideBuilder]
bal1
startWidth :: ((a, [WideBuilder], [WideBuilder]) -> [WideBuilder]) -> Int
startWidth (a, [WideBuilder], [WideBuilder]) -> [WideBuilder]
f = [Int] -> Int
forall a. Ord a => [a] -> a
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
maximum ([Int] -> Int) -> [Int] -> Int
forall a b. (a -> b) -> a -> b
$ Int
minWidth Int -> [Int] -> [Int]
forall a. a -> [a] -> [a]
: (WideBuilder -> Int) -> [WideBuilder] -> [Int]
forall a b. (a -> b) -> [a] -> [b]
map WideBuilder -> Int
wbWidth (((a, [WideBuilder], [WideBuilder]) -> [WideBuilder])
-> [(a, [WideBuilder], [WideBuilder])] -> [WideBuilder]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (a, [WideBuilder], [WideBuilder]) -> [WideBuilder]
f [(a, [WideBuilder], [WideBuilder])]
startAlign)
where
startAlign :: [(a, [WideBuilder], [WideBuilder])]
startAlign = (if Bool
alignAll then [(a, [WideBuilder], [WideBuilder])]
-> [(a, [WideBuilder], [WideBuilder])]
forall a. a -> a
id else Int
-> [(a, [WideBuilder], [WideBuilder])]
-> [(a, [WideBuilder], [WideBuilder])]
forall a. Int -> [a] -> [a]
take Int
chunkSize) [(a, [WideBuilder], [WideBuilder])]
itemsWithAmounts
itemsWithAmounts :: [(a, [WideBuilder], [WideBuilder])]
itemsWithAmounts = (a -> (a, [WideBuilder], [WideBuilder]))
-> [a] -> [(a, [WideBuilder], [WideBuilder])]
forall a b. (a -> b) -> [a] -> [b]
map (\a
x -> (a
x, MixedAmount -> [WideBuilder]
showAmt (MixedAmount -> [WideBuilder]) -> MixedAmount -> [WideBuilder]
forall a b. (a -> b) -> a -> b
$ a -> MixedAmount
itemamt a
x, MixedAmount -> [WideBuilder]
showAmt (MixedAmount -> [WideBuilder]) -> MixedAmount -> [WideBuilder]
forall a b. (a -> b) -> a -> b
$ a -> MixedAmount
itembal a
x)) [a]
report
showAmt :: MixedAmount -> [WideBuilder]
showAmt = AmountFormat -> MixedAmount -> [WideBuilder]
showMixedAmountLinesB AmountFormat
oneLineNoCostFmt{displayColour=opts^.color__}
amt :: (a, b, c) -> b
amt = (a, b, c) -> b
forall {a} {b} {c}. (a, b, c) -> b
second3
bal :: (a, b, c) -> c
bal = (a, b, c) -> c
forall {a} {b} {c}. (a, b, c) -> c
third3
tests_Cli_Utils :: TestTree
tests_Cli_Utils = [Char] -> [TestTree] -> TestTree
testGroup [Char]
"Utils" [
]