From 80249c3e8a3e156cb115d5ab5213b15d988a612c Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Fri, 4 Nov 2022 09:51:25 -1000 Subject: [PATCH] dev: lib: Utils cleanups --- hledger-lib/Hledger/Utils.hs | 45 ++++++++++-------------------- hledger-lib/Hledger/Utils/Print.hs | 4 +-- 2 files changed, 16 insertions(+), 33 deletions(-) diff --git a/hledger-lib/Hledger/Utils.hs b/hledger-lib/Hledger/Utils.hs index 37005bca4..bda25c13e 100644 --- a/hledger-lib/Hledger/Utils.hs +++ b/hledger-lib/Hledger/Utils.hs @@ -1,34 +1,20 @@ {-| - -Standard imports and utilities which are useful everywhere, or needed low -in the module hierarchy. This is the bottom of hledger's module graph. - +Utilities used throughout hledger, or needed low in the module hierarchy. +This is the bottom of hledger's module graph. -} + {-# LANGUAGE LambdaCase #-} -module Hledger.Utils (---- provide these frequently used modules - or not, for clearer api: - -- module Control.Monad, - -- module Data.List, - -- module Data.Maybe, - -- module Data.Time.Calendar, - -- module Data.Time.Clock, - -- module Data.Time.LocalTime, - -- module Data.Tree, - -- module Text.RegexPR, - -- module Text.Printf, - ---- all of this one: - module Hledger.Utils, - module Hledger.Utils.Debug, - module Hledger.Utils.Parse, - module Hledger.Utils.Print, - module Hledger.Utils.Regex, - module Hledger.Utils.String, - module Hledger.Utils.Text, - module Hledger.Utils.Test, - -- Debug.Trace.trace, - -- module Data.PPrint, - -- the rest need to be done in each module I think - ) +module Hledger.Utils ( + module Hledger.Utils, + module Hledger.Utils.Debug, + module Hledger.Utils.Parse, + module Hledger.Utils.Print, + module Hledger.Utils.Regex, + module Hledger.Utils.String, + module Hledger.Utils.Text, + module Hledger.Utils.Test, +) where import Control.Monad (when) @@ -42,8 +28,8 @@ import qualified Data.Text.Lazy.Builder as TB import Data.Time.Clock (getCurrentTime) import Data.Time.LocalTime (LocalTime, ZonedTime, getCurrentTimeZone, utcToLocalTime, utcToZonedTime) +import Data.Tree (foldTree, Tree (Node, subForest)) import Language.Haskell.TH (DecsQ, Name, mkName, nameBase) --- import Language.Haskell.TH.Quote (QuasiQuoter(..)) import Language.Haskell.TH.Syntax (Q, Exp) import Lens.Micro ((&), (.~)) import Lens.Micro.TH (DefName(TopName), lensClass, lensField, makeLensesWith, classyRules) @@ -61,7 +47,6 @@ import Hledger.Utils.Regex import Hledger.Utils.String import Hledger.Utils.Text import Hledger.Utils.Test -import Data.Tree (foldTree, Tree (Node, subForest)) -- tuples @@ -128,8 +113,6 @@ treeLeaves :: Show a => Tree a -> [a] treeLeaves Node{subForest=[]} = [] treeLeaves t = foldTree (\a bs -> (if null bs then (a:) else id) $ concat bs) t --- text - -- time getCurrentLocalTime :: IO LocalTime diff --git a/hledger-lib/Hledger/Utils/Print.hs b/hledger-lib/Hledger/Utils/Print.hs index f5c46d692..1701a8c66 100644 --- a/hledger-lib/Hledger/Utils/Print.hs +++ b/hledger-lib/Hledger/Utils/Print.hs @@ -108,12 +108,12 @@ colorOption = -- or ( -- the program was not started with --color=no|never -- and a NO_COLOR environment variable is not defined --- and stdout supports ANSI color and -o/--output-file was not used or is "-" +-- and stdout supports ANSI color +-- and -o/--output-file was not used, or its value is "-" -- ). useColorOnStdout :: Bool useColorOnStdout = not hasOutputFile && useColorOnHandle stdout --- Avoid using dbg*, pshow etc. in this function (infinite loop). -- | Like useColorOnStdout, but checks for ANSI color support on stderr, -- and is not affected by -o/--output-file. useColorOnStderr :: Bool