Skip to content

Commit cdb078b

Browse files
authored
Merge pull request #66 from lotz84/colored-output
SUCCESS, FAILを色付きで表示する
2 parents f42e7a8 + 77fe1a1 commit cdb078b

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

package.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ library:
4040
dependencies:
4141
- base >=4.7 && <5
4242
# TODO: Decide version
43+
- ansi-terminal
4344
- QuickCheck
4445
- bytestring
4546
- cmark

src/Education/MakeMistakesToLearnHaskell.hs

+8-7
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import Education.MakeMistakesToLearnHaskell.Error
1414
import Education.MakeMistakesToLearnHaskell.Text
1515

1616
import qualified Options.Applicative as Opt
17+
import System.Console.ANSI
1718

1819
main :: IO ()
1920
main = do
@@ -83,17 +84,15 @@ verifySource e (file : _) = do
8384
case result of
8485
Exercise.Success details -> do
8586
Text.putStrLn details
86-
putStrLn "\n\nSUCCESS: Congratulations! Your solution got compiled and ran correctly!"
87+
withSGR [SetColor Foreground Vivid Green] $
88+
putStrLn "\n\nSUCCESS: Congratulations! Your solution got compiled and ran correctly!"
8789
putStrLn "Here's an example solution of this exercise:\n"
8890
Text.putStr =<< Exercise.loadExampleSolution currentExercise
8991
Exit.exitSuccess
9092
Exercise.Fail details -> do
91-
mapM_ Text.putStrLn
92-
[ details
93-
, ""
94-
, "FAIL: Your solution didn't pass. Try again!"
95-
, ""
96-
]
93+
Text.putStrLn details
94+
withSGR [SetColor Foreground Vivid Red] $
95+
putStrLn "\nFAIL: Your solution didn't pass. Try again!\n"
9796
Exit.exitFailure
9897
Exercise.Error details -> do
9998
Error.errLn $ Text.toStrict $ details <> "\n\n"
@@ -106,6 +105,8 @@ verifySource e (file : _) = do
106105
putStrLn "Here's an example solution of this exercise:\n"
107106
Text.putStr =<< Exercise.loadExampleSolution currentExercise
108107
Exit.exitSuccess
108+
where
109+
withSGR sgrs act = setSGR sgrs >> act >> setSGR [Reset]
109110

110111

111112
showExercise :: Env -> Bool -> [String] -> IO ()

0 commit comments

Comments
 (0)