mirror of
https://github.com/joshuaclayton/unused.git
synced 2024-08-15 15:50:26 +03:00
Extract error printing to separate function
This commit is contained in:
parent
8f5446a414
commit
6ee18cf1c9
38
app/Main.hs
38
app/Main.hs
@ -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]
|
||||
|
@ -1,5 +1,6 @@
|
||||
module Unused.Parser
|
||||
( parseLines
|
||||
, ParseError
|
||||
) where
|
||||
|
||||
import Control.Monad (void)
|
||||
|
Loading…
Reference in New Issue
Block a user