From 6ee18cf1c93791b85fed485a91043bfc7e4ba1b2 Mon Sep 17 00:00:00 2001 From: Joshua Clayton Date: Sun, 1 May 2016 06:20:47 -0400 Subject: [PATCH] Extract error printing to separate function --- app/Main.hs | 38 +++++++++++++++++++++----------------- src/Unused/Parser.hs | 1 + 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index 598db32..1eb36bc 100644 --- a/app/Main.hs +++ b/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] diff --git a/src/Unused/Parser.hs b/src/Unused/Parser.hs index 9288856..5f51219 100644 --- a/src/Unused/Parser.hs +++ b/src/Unused/Parser.hs @@ -1,5 +1,6 @@ module Unused.Parser ( parseLines + , ParseError ) where import Control.Monad (void)