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 Unused.TermSearch (search)
import Unused.Parser (parseLines)
import Unused.Parser (parseLines, ParseError)
import Unused.Types
main :: IO ()
@ -14,22 +14,8 @@ main = do
case withOneOccurrence $ withOneFile response of
Right termMatchSet ->
mapM_ printMatchPair $ listFromMatchSet termMatchSet
Left 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]
Left e ->
printParseError e
return ()
@ -53,3 +39,21 @@ printMatches matches = do
putStr $ " " ++ (show . occurrences) m ++ " "
setSGR [Reset]
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
( parseLines
, ParseError
) where
import Control.Monad (void)