on master help sign in
API: remove dependency on data-default

This change removes Data.Default instances for Attr and Config. Use 'defAttr' and 'defaultConfig' (or 'mempty') instead of 'def'.

commit9809a42189d91164788b581d5e3c30cf50c22bfd authorJonathan Daugherty <cygnus@foobox.com> dateSun 22 Jan 2017, 12:00 (10 years ago) parente621e59
7 files changed+19−34
src/Graphics/Vty/Attributes.hs−4 src/Graphics/Vty/Config.hs+11−11 src/Graphics/Vty/Inline/Unsafe.hs+1−2 test/VerifyConfig.hs+1−2 test/VerifyOutput.hs+1−3 test/VerifyUsingMockInput.hs+5−6 vty.cabal−6
src/Graphics/Vty/Attributes.hs−4
@@ -36,7 +36,6 @@ module Graphics.Vty.Attributes
3636where
3737
3838import Data.Bits
39−import Data.Default
4039import Data.Word
4140
4241import Graphics.Vty.Attributes.Color
@@ -211,9 +210,6 @@ withStyle attr styleFlag = attr { attrStyle = SetTo $ styleMask attr .|. styleFl
211210defAttr :: Attr
212211defAttr = Attr Default Default Default
213212
214−instance Default Attr where
215− def = defAttr
216−
217213-- | Keeps the style, background color and foreground color that was
218214-- previously set. Used to override some part of the previous style.
219215--
src/Graphics/Vty/Config.hs+11−11
@@ -76,6 +76,7 @@ module Graphics.Vty.Config
7676 , standardIOConfig
7777 , runParseConfig
7878 , parseConfigFile
79+ , defaultConfig
7980 )
8081where
8182
@@ -87,7 +88,6 @@ import Control.Exception (catch, IOException, Exception(..), throwIO)
8788import Control.Monad (liftM, guard, void)
8889
8990import qualified Data.ByteString as BS
90−import Data.Default
9191import Data.Monoid
9292import Data.Typeable (Typeable)
9393
@@ -146,8 +146,8 @@ data Config = Config
146146 , termName :: Maybe String
147147 } deriving (Show, Eq)
148148
149−instance Default Config where
150− def = mempty
149+defaultConfig :: Config
150+defaultConfig = mempty
151151
152152instance Monoid Config where
153153 mempty = Config
@@ -179,14 +179,14 @@ instance Monoid Config where
179179userConfig :: IO Config
180180userConfig = do
181181 configFile <- (mappend <$> getAppUserDataDirectory "vty" <*> pure "/config") >>= parseConfigFile
182− overrideConfig <- maybe (return def) parseConfigFile =<< getEnv "VTY_CONFIG_FILE"
182+ overrideConfig <- maybe (return defaultConfig) parseConfigFile =<< getEnv "VTY_CONFIG_FILE"
183183 let base = configFile <> overrideConfig
184184 mappend base <$> overrideEnvConfig
185185
186186overrideEnvConfig :: IO Config
187187overrideEnvConfig = do
188188 d <- getEnv "VTY_DEBUG_LOG"
189− return $ def { debugLog = d }
189+ return $ defaultConfig { debugLog = d }
190190
191191-- | Configures VTY using defaults suitable for terminals. This action
192192-- can raise 'VtyConfigurationError'.
@@ -196,7 +196,7 @@ standardIOConfig = do
196196 case mb of
197197 Nothing -> throwIO VtyMissingTermEnvVar
198198 Just t ->
199− return def
199+ return defaultConfig
200200 { vmin = Just 1
201201 , mouseMode = Just False
202202 , bracketedPasteMode = Just False
@@ -209,13 +209,13 @@ standardIOConfig = do
209209parseConfigFile :: FilePath -> IO Config
210210parseConfigFile path = do
211211 catch (runParseConfig path <$> BS.readFile path)
212− (\(_ :: IOException) -> return def)
212+ (\(_ :: IOException) -> return defaultConfig)
213213
214214runParseConfig :: String -> BS.ByteString -> Config
215215runParseConfig name cfgTxt =
216216 case runParser parseConfig () name cfgTxt of
217217 Right cfg -> cfg
218− Left{} -> def
218+ Left{} -> defaultConfig
219219
220220------------------------------------------------------------------------
221221
@@ -249,13 +249,13 @@ mapDecl = do
249249 bytes <- P.stringLiteral configLexer
250250 key <- parseValue
251251 modifiers <- parseValue
252− return def { inputMap = [(termIdent, bytes, EvKey key modifiers)] }
252+ return defaultConfig { inputMap = [(termIdent, bytes, EvKey key modifiers)] }
253253
254254debugLogDecl :: Parser Config
255255debugLogDecl = do
256256 "debugLog" <- P.identifier configLexer
257257 path <- P.stringLiteral configLexer
258− return def { debugLog = Just path }
258+ return defaultConfig { debugLog = Just path }
259259
260260ignoreLine :: Parser ()
261261ignoreLine = void $ manyTill anyChar newline
@@ -264,7 +264,7 @@ parseConfig :: Parser Config
264264parseConfig = liftM mconcat $ many $ do
265265 P.whiteSpace configLexer
266266 let directives = [try mapDecl, try debugLogDecl]
267− choice directives <|> (ignoreLine >> return def)
267+ choice directives <|> (ignoreLine >> return defaultConfig)
268268
269269class Parse a where parseValue :: Parser a
270270instance Parse Char where parseValue = P.charLiteral configLexer
src/Graphics/Vty/Inline/Unsafe.hs+1−2
@@ -4,7 +4,6 @@ module Graphics.Vty.Inline.Unsafe where
44
55import Graphics.Vty
66
7−import Data.Default
87import Data.IORef
98
109import GHC.IO.Handle (hDuplicate)
@@ -29,7 +28,7 @@ mkDupeConfig = do
2928 hSetBuffering stdin NoBuffering
3029 stdinDupe <- hDuplicate stdin >>= handleToFd
3130 stdoutDupe <- hDuplicate stdout >>= handleToFd
32− return $ def { inputFd = Just stdinDupe, outputFd = Just stdoutDupe }
31+ return $ defaultConfig { inputFd = Just stdinDupe, outputFd = Just stdoutDupe }
3332
3433-- | This will create a Vty instance using 'mkVty' and execute an IO
3534-- action provided that instance. The created Vty instance will be
test/VerifyConfig.hs+1−2
@@ -4,7 +4,6 @@ module Main where
44import Graphics.Vty.Config
55import Graphics.Vty.Input.Events
66
7−import Data.Default
87import Data.String.QQ
98import qualified Data.ByteString.Char8 as B
109
@@ -24,7 +23,7 @@ debugLog "/tmp/vty-debug.txt"
2423|]
2524
2625exampleConfigConfig :: Config
27−exampleConfigConfig = def
26+exampleConfigConfig = defaultConfig
2827 { debugLog = Just "/tmp/vty-debug.txt"
2928 , inputMap = [ (Nothing, "\ESC[B", EvKey KUp [])
3029 , (Nothing, "\ESC[1;3B", EvKey KDown [MAlt])
test/VerifyOutput.hs+1−3
@@ -12,8 +12,6 @@ import Verify.Graphics.Vty.Output
1212
1313import Control.Monad
1414
15−import Data.Default
16−
1715import qualified System.Console.Terminfo as Terminfo
1816import System.Posix.Env
1917import System.Posix.IO
@@ -37,7 +35,7 @@ smokeTestTermNonMac termName i = liftIOResult $ do
3735smokeTestTerm :: String -> Image -> IO Result
3836smokeTestTerm termName i = do
3937 nullOut <- openFd "/dev/null" WriteOnly Nothing defaultFileFlags
40− t <- outputForConfig $ def { outputFd = Just nullOut, termName = Just termName }
38+ t <- outputForConfig $ defaultConfig { outputFd = Just nullOut, termName = Just termName }
4139 -- putStrLn $ "context color count: " ++ show (contextColorCount t)
4240 reserveDisplay t
4341 dc <- displayContext t (100,100)
test/VerifyUsingMockInput.hs+5−6
@@ -17,7 +17,6 @@ import Control.Exception
1717import Lens.Micro ((^.))
1818import Control.Monad
1919
20−import Data.Default
2120import Data.IORef
2221import Data.List (intersperse, reverse, nubBy)
2322
@@ -113,11 +112,11 @@ assertEventsFromSynInput table inputSpec expectedEvents = do
113112 (writeFd, readFd) <- openPseudoTerminal
114113 (setTermAttr,_) <- attributeControl readFd
115114 setTermAttr
116− let testConfig = def { inputFd = Just readFd
117− , termName = Just "dummy"
118− , vmin = Just 1
119− , vtime = Just 100
120− }
115+ let testConfig = defaultConfig { inputFd = Just readFd
116+ , termName = Just "dummy"
117+ , vmin = Just 1
118+ , vtime = Just 100
119+ }
121120 input <- initInput testConfig table
122121 eventsRef <- newIORef []
123122 let writeWaitClose = do
vty.cabal−6
@@ -43,7 +43,6 @@ library
4343 blaze-builder >= 0.3.3.2 && < 0.5,
4444 bytestring,
4545 containers,
46− data-default >= 0.5.3,
4746 deepseq >= 1.1 && < 1.5,
4847 directory,
4948 filepath >= 1.0 && < 2.0,
@@ -129,7 +128,6 @@ executable vty-mode-demo
129128 build-depends: vty,
130129 base >= 4.6 && < 5,
131130 containers,
132− data-default >= 0.5.3,
133131 microlens,
134132 microlens-mtl,
135133 mtl >= 1.1.1.0 && < 2.3
@@ -145,7 +143,6 @@ executable vty-demo
145143 build-depends: vty,
146144 base >= 4.6 && < 5,
147145 containers,
148− data-default >= 0.5.3,
149146 microlens,
150147 microlens-mtl,
151148 mtl >= 1.1.1.0 && < 2.3
@@ -228,7 +225,6 @@ test-suite verify-terminal
228225 base >= 4.6 && < 5,
229226 bytestring,
230227 containers,
231− data-default >= 0.5.3,
232228 deepseq >= 1.1 && < 1.5,
233229 mtl >= 1.1.1.0 && < 2.3,
234230 terminfo >= 0.3 && < 0.5,
@@ -569,7 +565,6 @@ test-suite verify-using-mock-input
569565
570566 build-depends: vty,
571567 Cabal >= 1.20,
572− data-default >= 0.5.3,
573568 QuickCheck >= 2.7,
574569 smallcheck == 1.*,
575570 quickcheck-assertions >= 0.1.1,
@@ -604,7 +599,6 @@ test-suite verify-config
604599
605600 build-depends: vty,
606601 Cabal >= 1.20,
607− data-default >= 0.5.3,
608602 HUnit,
609603 QuickCheck >= 2.7,
610604 smallcheck == 1.*,