Extract error printing to separate function

This commit is contained in:
Joshua Clayton 2016-05-01 06:20:47 -04:00
parent 8f5446a414
commit 6ee18cf1c9
2 changed files with 22 additions and 17 deletions

View File

@ -2,7 +2,7 @@ module Main where
import System.Console.ANSI import System.Console.ANSI
import Unused.TermSearch (search) import Unused.TermSearch (search)
import Unused.Parser (parseLines) import Unused.Parser (parseLines, ParseError)
import Unused.Types import Unused.Types
main :: IO () main :: IO ()
@ -14,22 +14,8 @@ main = do
case withOneOccurrence $ withOneFile response of case withOneOccurrence $ withOneFile response of
Right termMatchSet -> Right termMatchSet ->
mapM_ printMatchPair $ listFromMatchSet termMatchSet mapM_ printMatchPair $ listFromMatchSet termMatchSet
Left e -> do Left e ->
setSGR [SetColor Background Vivid Red] printParseError e
setSGR [SetColor Foreground Vivid White]
setSGR [SetConsoleIntensity BoldIntensity]
putStrLn "\nThere was a problem parsing the data:\n"
setSGR [Reset]
setSGR [SetColor Foreground Vivid Red]
setSGR [SetConsoleIntensity BoldIntensity]
print e
putStr "\n"
setSGR [Reset]
return () return ()
@ -53,3 +39,21 @@ printMatches matches = do
putStr $ " " ++ (show . occurrences) m ++ " " putStr $ " " ++ (show . occurrences) m ++ " "
setSGR [Reset] setSGR [Reset]
putStr "\n" putStr "\n"
printParseError :: ParseError -> IO ()
printParseError e = do
setSGR [SetColor Background Vivid Red]
setSGR [SetColor Foreground Vivid White]
setSGR [SetConsoleIntensity BoldIntensity]
putStrLn "\nThere was a problem parsing the data:\n"
setSGR [Reset]
setSGR [SetColor Foreground Vivid Red]
setSGR [SetConsoleIntensity BoldIntensity]
print e
putStr "\n"
setSGR [Reset]

View File

@ -1,5 +1,6 @@
module Unused.Parser module Unused.Parser
( parseLines ( parseLines
, ParseError
) where ) where
import Control.Monad (void) import Control.Monad (void)