pkg!: Remove Hledger.Utils.Color module.

This module was only used in one place in Hledger.Data.Amount. The code
has been moved directly into Hledger.Utils.
This commit is contained in:
Stephen Morgan 2021-08-30 17:43:14 +10:00 committed by Simon Michael
parent f1994d5aa8
commit a0f9d7560f
6 changed files with 23 additions and 40 deletions

View File

@ -158,6 +158,7 @@ import qualified Data.Text as T
import qualified Data.Text.Lazy.Builder as TB import qualified Data.Text.Lazy.Builder as TB
import Data.Word (Word8) import Data.Word (Word8)
import Safe (headDef, lastDef, lastMay) import Safe (headDef, lastDef, lastMay)
import System.Console.ANSI (Color(..),ColorIntensity(..))
import Text.Printf (printf) import Text.Printf (printf)
import Hledger.Data.Types import Hledger.Data.Types

View File

@ -24,7 +24,6 @@ module Hledger.Utils (---- provide these frequently used modules - or not, for c
module Hledger.Utils.String, module Hledger.Utils.String,
module Hledger.Utils.Text, module Hledger.Utils.Text,
module Hledger.Utils.Test, module Hledger.Utils.Test,
module Hledger.Utils.Color,
-- Debug.Trace.trace, -- Debug.Trace.trace,
-- module Data.PPrint, -- module Data.PPrint,
-- the rest need to be done in each module I think -- the rest need to be done in each module I think
@ -38,6 +37,7 @@ import Data.List.Extra (foldl', foldl1', uncons, unsnoc)
import qualified Data.Set as Set import qualified Data.Set as Set
import Data.Text (Text) import Data.Text (Text)
import qualified Data.Text.IO as T import qualified Data.Text.IO as T
import qualified Data.Text.Lazy.Builder as TB
import Data.Time.Clock (getCurrentTime) import Data.Time.Clock (getCurrentTime)
import Data.Time.LocalTime (LocalTime, ZonedTime, getCurrentTimeZone, import Data.Time.LocalTime (LocalTime, ZonedTime, getCurrentTimeZone,
utcToLocalTime, utcToZonedTime) utcToLocalTime, utcToZonedTime)
@ -46,6 +46,7 @@ import Language.Haskell.TH (DecsQ, Name, mkName, nameBase)
import Language.Haskell.TH.Syntax (Q, Exp) import Language.Haskell.TH.Syntax (Q, Exp)
import Lens.Micro ((&), (.~)) import Lens.Micro ((&), (.~))
import Lens.Micro.TH (DefName(TopName), lensClass, lensField, makeLensesWith, classyRules) import Lens.Micro.TH (DefName(TopName), lensClass, lensField, makeLensesWith, classyRules)
import System.Console.ANSI (Color,ColorIntensity,ConsoleLayer(..), SGR(..), setSGRCode)
import System.Directory (getHomeDirectory) import System.Directory (getHomeDirectory)
import System.FilePath (isRelative, (</>)) import System.FilePath (isRelative, (</>))
import System.IO import System.IO
@ -58,7 +59,6 @@ import Hledger.Utils.Regex
import Hledger.Utils.String import Hledger.Utils.String
import Hledger.Utils.Text import Hledger.Utils.Text
import Hledger.Utils.Test import Hledger.Utils.Test
import Hledger.Utils.Color
-- tuples -- tuples
@ -245,6 +245,25 @@ embedFileRelative f = makeRelativeToProject f >>= embedStringFile
-- where -- where
-- QuasiQuoter{quoteExp=hereFileExp} = hereFile -- QuasiQuoter{quoteExp=hereFileExp} = hereFile
-- | Wrap a string in ANSI codes to set and reset foreground colour.
color :: ColorIntensity -> Color -> String -> String
color int col s = setSGRCode [SetColor Foreground int col] ++ s ++ setSGRCode []
-- | Wrap a string in ANSI codes to set and reset background colour.
bgColor :: ColorIntensity -> Color -> String -> String
bgColor int col s = setSGRCode [SetColor Background int col] ++ s ++ setSGRCode []
-- | Wrap a WideBuilder in ANSI codes to set and reset foreground colour.
colorB :: ColorIntensity -> Color -> WideBuilder -> WideBuilder
colorB int col (WideBuilder s w) =
WideBuilder (TB.fromString (setSGRCode [SetColor Foreground int col]) <> s <> TB.fromString (setSGRCode [])) w
-- | Wrap a WideBuilder in ANSI codes to set and reset background colour.
bgColorB :: ColorIntensity -> Color -> WideBuilder -> WideBuilder
bgColorB int col (WideBuilder s w) =
WideBuilder (TB.fromString (setSGRCode [SetColor Background int col]) <> s <> TB.fromString (setSGRCode [])) w
-- | Make classy lenses for Hledger options fields. -- | Make classy lenses for Hledger options fields.
-- This is intended to be used with BalancingOpts, InputOpt, ReportOpts, -- This is intended to be used with BalancingOpts, InputOpt, ReportOpts,
-- ReportSpec, and CliOpts. -- ReportSpec, and CliOpts.

View File

@ -1,35 +0,0 @@
-- | Basic color helpers for prettifying console output.
module Hledger.Utils.Color
(
color,
bgColor,
colorB,
bgColorB,
Color(..),
ColorIntensity(..)
)
where
import qualified Data.Text.Lazy.Builder as TB
import System.Console.ANSI
import Hledger.Utils.Text (WideBuilder(..))
-- | Wrap a string in ANSI codes to set and reset foreground colour.
color :: ColorIntensity -> Color -> String -> String
color int col s = setSGRCode [SetColor Foreground int col] ++ s ++ setSGRCode []
-- | Wrap a string in ANSI codes to set and reset background colour.
bgColor :: ColorIntensity -> Color -> String -> String
bgColor int col s = setSGRCode [SetColor Background int col] ++ s ++ setSGRCode []
-- | Wrap a WideBuilder in ANSI codes to set and reset foreground colour.
colorB :: ColorIntensity -> Color -> WideBuilder -> WideBuilder
colorB int col (WideBuilder s w) =
WideBuilder (TB.fromString (setSGRCode [SetColor Foreground int col]) <> s <> TB.fromString (setSGRCode [])) w
-- | Wrap a WideBuilder in ANSI codes to set and reset background colour.
bgColorB :: ColorIntensity -> Color -> WideBuilder -> WideBuilder
bgColorB int col (WideBuilder s w) =
WideBuilder (TB.fromString (setSGRCode [SetColor Background int col]) <> s <> TB.fromString (setSGRCode [])) w

View File

@ -78,7 +78,6 @@ library
Hledger.Reports.MultiBalanceReport Hledger.Reports.MultiBalanceReport
Hledger.Reports.PostingsReport Hledger.Reports.PostingsReport
Hledger.Utils Hledger.Utils
Hledger.Utils.Color
Hledger.Utils.Debug Hledger.Utils.Debug
Hledger.Utils.Parse Hledger.Utils.Parse
Hledger.Utils.Regex Hledger.Utils.Regex

View File

@ -130,7 +130,6 @@ library:
- Hledger.Reports.MultiBalanceReport - Hledger.Reports.MultiBalanceReport
- Hledger.Reports.PostingsReport - Hledger.Reports.PostingsReport
- Hledger.Utils - Hledger.Utils
- Hledger.Utils.Color
- Hledger.Utils.Debug - Hledger.Utils.Debug
- Hledger.Utils.Parse - Hledger.Utils.Parse
- Hledger.Utils.Regex - Hledger.Utils.Regex

View File

@ -45,7 +45,7 @@ import Graphics.Vty
) )
import Lens.Micro.Platform import Lens.Micro.Platform
import Hledger hiding (Color) import Hledger
import Hledger.Cli (CliOpts) import Hledger.Cli (CliOpts)
import Hledger.Cli.DocFiles import Hledger.Cli.DocFiles
import Hledger.UI.UITypes import Hledger.UI.UITypes