Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor refactoring to follow the lens library. #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions src/System/Console/Terminal/Color.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,24 @@ class AsColor p f t where
-- '_Color' :: 'Iso'' 'ANSI.Color' 'Color'
-- '_Color' :: 'Prism'' 'Terminfo.Color' 'Color'
-- @
_Color :: Overloaded' p f t Color
_Color :: Optic' p f t Color

-- |
-- @
-- '_Black' :: 'Prism'' 'Color' ()
-- '_Red' :: 'Prism'' 'Color' ()
-- ...
-- @
_Black, _Red, _Green, _Yellow, _Blue, _Magenta, _Cyan, _White :: (Choice p, Applicative f) => Overloaded' p f t ()
_Black, _Red, _Green, _Yellow, _Blue, _Magenta, _Cyan, _White :: (Choice p, Applicative f) => Optic' p f t ()

_Black = _Color.eq Black
_Red = _Color.eq Red
_Green = _Color.eq Green
_Yellow = _Color.eq Yellow
_Blue = _Color.eq Blue
_Magenta = _Color.eq Magenta
_Cyan = _Color.eq Cyan
_White = _Color.eq White
_Black = _Color.only Black
_Red = _Color.only Red
_Green = _Color.only Green
_Yellow = _Color.only Yellow
_Blue = _Color.only Blue
_Magenta = _Color.only Magenta
_Cyan = _Color.only Cyan
_White = _Color.only White

instance AsColor p f Color where
_Color = id
Expand All @@ -95,14 +95,14 @@ instance (Choice p, Applicative f) => AsColor p f Terminfo.Color where
seta Terminfo.Cyan = Just Cyan
seta Terminfo.White = Just White
seta Terminfo.ColorNumber{} = Nothing
_Black = eq Terminfo.Black
_Red = eq Terminfo.Red
_Green = eq Terminfo.Green
_Yellow = eq Terminfo.Yellow
_Blue = eq Terminfo.Blue
_Magenta = eq Terminfo.Magenta
_Cyan = eq Terminfo.Cyan
_White = eq Terminfo.White
_Black = only Terminfo.Black
_Red = only Terminfo.Red
_Green = only Terminfo.Green
_Yellow = only Terminfo.Yellow
_Blue = only Terminfo.Blue
_Magenta = only Terminfo.Magenta
_Cyan = only Terminfo.Cyan
_White = only Terminfo.White
#endif

instance (Profunctor p, Functor f) => AsColor p f ANSI.Color where
Expand Down
8 changes: 4 additions & 4 deletions src/System/Console/Terminal/Intensity.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@ class AsIntensity p f t where
-- '_Intensity' :: 'Equality'' 'Intensity' 'Intensity'
-- '_Intensity' :: 'Iso'' 'ANSI.ColorIntensity' 'Intensity'
-- @
_Intensity :: Overloaded' p f t Intensity
_Intensity :: Optic' p f t Intensity

-- |
-- @
-- '_Dull' :: 'Prism'' 'Intensity' ()
-- '_Vivid' :: 'Prism'' 'Intensity' ()
-- ...
-- @
_Dull, _Vivid :: (Choice p, Applicative f) => Overloaded' p f t ()
_Dull, _Vivid :: (Choice p, Applicative f) => Optic' p f t ()

_Dull = _Intensity.eq Dull
_Vivid = _Intensity.eq Vivid
_Dull = _Intensity.only Dull
_Vivid = _Intensity.only Vivid

instance AsIntensity p f Intensity where
_Intensity = id
Expand Down
11 changes: 4 additions & 7 deletions src/System/Console/Terminal/Util.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
-----------------------------------------------------------------------------
Expand All @@ -14,15 +15,11 @@
-- This internal module provides some combinators that help write prisms.
----------------------------------------------------------------------------
module System.Console.Terminal.Util
( eq
, en
( en
) where

import Data.Function
import Control.Lens

eq :: Eq a => a -> Prism' a ()
eq a = prism' (const a) $ \b -> if a == b then Just () else Nothing

en :: Enum a => a -> Prism' a ()
en a = prism' (const a) $ \b -> if fromEnum a == fromEnum b then Just () else Nothing

en a = nearly a (((==) `on` fromEnum) a)
2 changes: 1 addition & 1 deletion terminal.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ library
base >= 4.4 && < 5,
data-default >= 0.4 && < 0.5,
ghc-prim,
lens >= 3.8,
lens >= 4,
mtl >= 2 && < 2.2,
transformers >= 0.2.2 && < 0.4

Expand Down