on master help sign in
API: remove dependency on data-default
9809a42Jonathan Daugherty
src/Graphics/Vty/Attributes.hs−4
@@ -36,7 +36,6 @@ module Graphics.Vty.Attributes
36where
36where
37
37
38import Data.Bits
38import Data.Bits
39−import Data.Default
40import Data.Word
39import Data.Word
41
40
42import Graphics.Vty.Attributes.Color
41import Graphics.Vty.Attributes.Color
@@ -211,9 +210,6 @@ withStyle attr styleFlag = attr { attrStyle = SetTo $ styleMask attr .|. styleFl
211defAttr :: Attr
210defAttr :: Attr
212defAttr = Attr Default Default Default
211defAttr = Attr Default Default Default
213
212
214−instance Default Attr where
215− def = defAttr
216−
217-- | Keeps the style, background color and foreground color that was
213-- | Keeps the style, background color and foreground color that was
218-- previously set. Used to override some part of the previous style.
214-- previously set. Used to override some part of the previous style.
219--
215--
src/Graphics/Vty/Config.hs+11−11
@@ -76,6 +76,7 @@ module Graphics.Vty.Config
76 , standardIOConfig
76 , standardIOConfig
77 , runParseConfig
77 , runParseConfig
78 , parseConfigFile
78 , parseConfigFile
79+ , defaultConfig
79 )
80 )
80where
81where
81
82
@@ -87,7 +88,6 @@ import Control.Exception (catch, IOException, Exception(..), throwIO)
87import Control.Monad (liftM, guard, void)
88import Control.Monad (liftM, guard, void)
88
89
89import qualified Data.ByteString as BS
90import qualified Data.ByteString as BS
90−import Data.Default
91import Data.Monoid
91import Data.Monoid
92import Data.Typeable (Typeable)
92import Data.Typeable (Typeable)
93
93
@@ -146,8 +146,8 @@ data Config = Config
146 , termName :: Maybe String
146 , termName :: Maybe String
147 } deriving (Show, Eq)
147 } deriving (Show, Eq)
148
148
149−instance Default Config where
149+defaultConfig :: Config
150− def = mempty
150+defaultConfig = mempty
151
151
152instance Monoid Config where
152instance Monoid Config where
153 mempty = Config
153 mempty = Config
@@ -179,14 +179,14 @@ instance Monoid Config where
179userConfig :: IO Config
179userConfig :: IO Config
180userConfig = do
180userConfig = do
181 configFile <- (mappend <$> getAppUserDataDirectory "vty" <*> pure "/config") >>= parseConfigFile
181 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"
183 let base = configFile <> overrideConfig
183 let base = configFile <> overrideConfig
184 mappend base <$> overrideEnvConfig
184 mappend base <$> overrideEnvConfig
185
185
186overrideEnvConfig :: IO Config
186overrideEnvConfig :: IO Config
187overrideEnvConfig = do
187overrideEnvConfig = do
188 d <- getEnv "VTY_DEBUG_LOG"
188 d <- getEnv "VTY_DEBUG_LOG"
189− return $ def { debugLog = d }
189+ return $ defaultConfig { debugLog = d }
190
190
191-- | Configures VTY using defaults suitable for terminals. This action
191-- | Configures VTY using defaults suitable for terminals. This action
192-- can raise 'VtyConfigurationError'.
192-- can raise 'VtyConfigurationError'.
@@ -196,7 +196,7 @@ standardIOConfig = do
196 case mb of
196 case mb of
197 Nothing -> throwIO VtyMissingTermEnvVar
197 Nothing -> throwIO VtyMissingTermEnvVar
198 Just t ->
198 Just t ->
199− return def
199+ return defaultConfig
200 { vmin = Just 1
200 { vmin = Just 1
201 , mouseMode = Just False
201 , mouseMode = Just False
202 , bracketedPasteMode = Just False
202 , bracketedPasteMode = Just False
@@ -209,13 +209,13 @@ standardIOConfig = do
209parseConfigFile :: FilePath -> IO Config
209parseConfigFile :: FilePath -> IO Config
210parseConfigFile path = do
210parseConfigFile path = do
211 catch (runParseConfig path <$> BS.readFile path)
211 catch (runParseConfig path <$> BS.readFile path)
212− (\(_ :: IOException) -> return def)
212+ (\(_ :: IOException) -> return defaultConfig)
213
213
214runParseConfig :: String -> BS.ByteString -> Config
214runParseConfig :: String -> BS.ByteString -> Config
215runParseConfig name cfgTxt =
215runParseConfig name cfgTxt =
216 case runParser parseConfig () name cfgTxt of
216 case runParser parseConfig () name cfgTxt of
217 Right cfg -> cfg
217 Right cfg -> cfg
218− Left{} -> def
218+ Left{} -> defaultConfig
219
219
220------------------------------------------------------------------------
220------------------------------------------------------------------------
221
221
@@ -249,13 +249,13 @@ mapDecl = do
249 bytes <- P.stringLiteral configLexer
249 bytes <- P.stringLiteral configLexer
250 key <- parseValue
250 key <- parseValue
251 modifiers <- parseValue
251 modifiers <- parseValue
252− return def { inputMap = [(termIdent, bytes, EvKey key modifiers)] }
252+ return defaultConfig { inputMap = [(termIdent, bytes, EvKey key modifiers)] }
253
253
254debugLogDecl :: Parser Config
254debugLogDecl :: Parser Config
255debugLogDecl = do
255debugLogDecl = do
256 "debugLog" <- P.identifier configLexer
256 "debugLog" <- P.identifier configLexer
257 path <- P.stringLiteral configLexer
257 path <- P.stringLiteral configLexer
258− return def { debugLog = Just path }
258+ return defaultConfig { debugLog = Just path }
259
259
260ignoreLine :: Parser ()
260ignoreLine :: Parser ()
261ignoreLine = void $ manyTill anyChar newline
261ignoreLine = void $ manyTill anyChar newline
@@ -264,7 +264,7 @@ parseConfig :: Parser Config
264parseConfig = liftM mconcat $ many $ do
264parseConfig = liftM mconcat $ many $ do
265 P.whiteSpace configLexer
265 P.whiteSpace configLexer
266 let directives = [try mapDecl, try debugLogDecl]
266 let directives = [try mapDecl, try debugLogDecl]
267− choice directives <|> (ignoreLine >> return def)
267+ choice directives <|> (ignoreLine >> return defaultConfig)
268
268
269class Parse a where parseValue :: Parser a
269class Parse a where parseValue :: Parser a
270instance Parse Char where parseValue = P.charLiteral configLexer
270instance 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
4
4
5import Graphics.Vty
5import Graphics.Vty
6
6
7−import Data.Default
8import Data.IORef
7import Data.IORef
9
8
10import GHC.IO.Handle (hDuplicate)
9import GHC.IO.Handle (hDuplicate)
@@ -29,7 +28,7 @@ mkDupeConfig = do
29 hSetBuffering stdin NoBuffering
28 hSetBuffering stdin NoBuffering
30 stdinDupe <- hDuplicate stdin >>= handleToFd
29 stdinDupe <- hDuplicate stdin >>= handleToFd
31 stdoutDupe <- hDuplicate stdout >>= handleToFd
30 stdoutDupe <- hDuplicate stdout >>= handleToFd
32− return $ def { inputFd = Just stdinDupe, outputFd = Just stdoutDupe }
31+ return $ defaultConfig { inputFd = Just stdinDupe, outputFd = Just stdoutDupe }
33
32
34-- | This will create a Vty instance using 'mkVty' and execute an IO
33-- | This will create a Vty instance using 'mkVty' and execute an IO
35-- action provided that instance. The created Vty instance will be
34-- action provided that instance. The created Vty instance will be
test/VerifyConfig.hs+1−2
@@ -4,7 +4,6 @@ module Main where
4import Graphics.Vty.Config
4import Graphics.Vty.Config
5import Graphics.Vty.Input.Events
5import Graphics.Vty.Input.Events
6
6
7−import Data.Default
8import Data.String.QQ
7import Data.String.QQ
9import qualified Data.ByteString.Char8 as B
8import qualified Data.ByteString.Char8 as B
10
9
@@ -24,7 +23,7 @@ debugLog "/tmp/vty-debug.txt"
24|]
23|]
25
24
26exampleConfigConfig :: Config
25exampleConfigConfig :: Config
27−exampleConfigConfig = def
26+exampleConfigConfig = defaultConfig
28 { debugLog = Just "/tmp/vty-debug.txt"
27 { debugLog = Just "/tmp/vty-debug.txt"
29 , inputMap = [ (Nothing, "\ESC[B", EvKey KUp [])
28 , inputMap = [ (Nothing, "\ESC[B", EvKey KUp [])
30 , (Nothing, "\ESC[1;3B", EvKey KDown [MAlt])
29 , (Nothing, "\ESC[1;3B", EvKey KDown [MAlt])
test/VerifyOutput.hs+1−3
@@ -12,8 +12,6 @@ import Verify.Graphics.Vty.Output
12
12
13import Control.Monad
13import Control.Monad
14
14
15−import Data.Default
16−
17import qualified System.Console.Terminfo as Terminfo
15import qualified System.Console.Terminfo as Terminfo
18import System.Posix.Env
16import System.Posix.Env
19import System.Posix.IO
17import System.Posix.IO
@@ -37,7 +35,7 @@ smokeTestTermNonMac termName i = liftIOResult $ do
37smokeTestTerm :: String -> Image -> IO Result
35smokeTestTerm :: String -> Image -> IO Result
38smokeTestTerm termName i = do
36smokeTestTerm termName i = do
39 nullOut <- openFd "/dev/null" WriteOnly Nothing defaultFileFlags
37 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 }
41 -- putStrLn $ "context color count: " ++ show (contextColorCount t)
39 -- putStrLn $ "context color count: " ++ show (contextColorCount t)
42 reserveDisplay t
40 reserveDisplay t
43 dc <- displayContext t (100,100)
41 dc <- displayContext t (100,100)
test/VerifyUsingMockInput.hs+5−6
@@ -17,7 +17,6 @@ import Control.Exception
17import Lens.Micro ((^.))
17import Lens.Micro ((^.))
18import Control.Monad
18import Control.Monad
19
19
20−import Data.Default
21import Data.IORef
20import Data.IORef
22import Data.List (intersperse, reverse, nubBy)
21import Data.List (intersperse, reverse, nubBy)
23
22
@@ -113,11 +112,11 @@ assertEventsFromSynInput table inputSpec expectedEvents = do
113 (writeFd, readFd) <- openPseudoTerminal
112 (writeFd, readFd) <- openPseudoTerminal
114 (setTermAttr,_) <- attributeControl readFd
113 (setTermAttr,_) <- attributeControl readFd
115 setTermAttr
114 setTermAttr
116− let testConfig = def { inputFd = Just readFd
115+ let testConfig = defaultConfig { inputFd = Just readFd
117− , termName = Just "dummy"
116+ , termName = Just "dummy"
118− , vmin = Just 1
117+ , vmin = Just 1
119− , vtime = Just 100
118+ , vtime = Just 100
120− }
119+ }
121 input <- initInput testConfig table
120 input <- initInput testConfig table
122 eventsRef <- newIORef []
121 eventsRef <- newIORef []
123 let writeWaitClose = do
122 let writeWaitClose = do
vty.cabal−6
@@ -43,7 +43,6 @@ library
43 blaze-builder >= 0.3.3.2 && < 0.5,
43 blaze-builder >= 0.3.3.2 && < 0.5,
44 bytestring,
44 bytestring,
45 containers,
45 containers,
46− data-default >= 0.5.3,
47 deepseq >= 1.1 && < 1.5,
46 deepseq >= 1.1 && < 1.5,
48 directory,
47 directory,
49 filepath >= 1.0 && < 2.0,
48 filepath >= 1.0 && < 2.0,
@@ -129,7 +128,6 @@ executable vty-mode-demo
129 build-depends: vty,
128 build-depends: vty,
130 base >= 4.6 && < 5,
129 base >= 4.6 && < 5,
131 containers,
130 containers,
132− data-default >= 0.5.3,
133 microlens,
131 microlens,
134 microlens-mtl,
132 microlens-mtl,
135 mtl >= 1.1.1.0 && < 2.3
133 mtl >= 1.1.1.0 && < 2.3
@@ -145,7 +143,6 @@ executable vty-demo
145 build-depends: vty,
143 build-depends: vty,
146 base >= 4.6 && < 5,
144 base >= 4.6 && < 5,
147 containers,
145 containers,
148− data-default >= 0.5.3,
149 microlens,
146 microlens,
150 microlens-mtl,
147 microlens-mtl,
151 mtl >= 1.1.1.0 && < 2.3
148 mtl >= 1.1.1.0 && < 2.3
@@ -228,7 +225,6 @@ test-suite verify-terminal
228 base >= 4.6 && < 5,
225 base >= 4.6 && < 5,
229 bytestring,
226 bytestring,
230 containers,
227 containers,
231− data-default >= 0.5.3,
232 deepseq >= 1.1 && < 1.5,
228 deepseq >= 1.1 && < 1.5,
233 mtl >= 1.1.1.0 && < 2.3,
229 mtl >= 1.1.1.0 && < 2.3,
234 terminfo >= 0.3 && < 0.5,
230 terminfo >= 0.3 && < 0.5,
@@ -569,7 +565,6 @@ test-suite verify-using-mock-input
569
565
570 build-depends: vty,
566 build-depends: vty,
571 Cabal >= 1.20,
567 Cabal >= 1.20,
572− data-default >= 0.5.3,
573 QuickCheck >= 2.7,
568 QuickCheck >= 2.7,
574 smallcheck == 1.*,
569 smallcheck == 1.*,
575 quickcheck-assertions >= 0.1.1,
570 quickcheck-assertions >= 0.1.1,
@@ -604,7 +599,6 @@ test-suite verify-config
604
599
605 build-depends: vty,
600 build-depends: vty,
606 Cabal >= 1.20,
601 Cabal >= 1.20,
607− data-default >= 0.5.3,
608 HUnit,
602 HUnit,
609 QuickCheck >= 2.7,
603 QuickCheck >= 2.7,
610 smallcheck == 1.*,
604 smallcheck == 1.*,