diff --git a/src/Ghcid.hs b/src/Ghcid.hs index 93f9dc2d..4d8b697a 100644 --- a/src/Ghcid.hs +++ b/src/Ghcid.hs @@ -290,7 +290,7 @@ runGhcid session waiter termSize termOutput opts@Options{..} = do outputFill currTime load evals msg = do load <- pure $ case load of Nothing -> [] - Just (loadedCount, msgs) -> prettyOutput currTime loadedCount (filter isMessage msgs) evals + Just (loadedCount, msgs) -> prettyOutput opts currTime loadedCount (filter isMessage msgs) evals TermSize{..} <- termSize let wrap = concatMap (wordWrapE termWidth (termWidth `div` 5) . Esc) (msg, load, pad) <- @@ -362,7 +362,7 @@ runGhcid session waiter termSize termOutput opts@Options{..} = do let updateTitle extra = unless no_title $ setTitle $ unescape $ let f n msg = if n == 0 then "" else show n ++ " " ++ msg ++ ['s' | n > 1] - in (if countErrors == 0 && countWarnings == 0 then allGoodMessage ++ ", at " ++ currTime else f countErrors "error" ++ + in (if countErrors == 0 && countWarnings == 0 then allGoodMessage target ++ ", at " ++ currTime else f countErrors "error" ++ (if countErrors > 0 && countWarnings > 0 then ", " else "") ++ f countWarnings "warning") ++ " " ++ extra ++ [' ' | extra /= ""] ++ "- " ++ project @@ -384,7 +384,7 @@ runGhcid session waiter termSize termOutput opts@Options{..} = do if takeExtension file == ".json" then showJSON [("loaded",map jString loaded),("messages",map jMessage $ filter isMessage messages)] else - unlines $ map unescape $ prettyOutput currTime loadedCount (limitMessages ordMessages) evals + unlines $ map unescape $ prettyOutput opts currTime loadedCount (limitMessages ordMessages) evals when (null loaded && not ignoreLoaded) $ do putStrLn "No files loaded, nothing to wait for. Fix the last error and restart." exitFailure @@ -433,11 +433,16 @@ runGhcid session waiter termSize termOutput opts@Options{..} = do -- | Given an available height, and a set of messages to display, show them as best you can. -prettyOutput :: String -> Int -> [Load] -> [EvalResult] -> [String] -prettyOutput currTime loadedCount [] evals = - (allGoodMessage ++ " (" ++ show loadedCount ++ " module" ++ ['s' | loadedCount /= 1] ++ ", at " ++ currTime ++ ")") +prettyOutput :: Options -> String -> Int -> [Load] -> [EvalResult] -> [String] +prettyOutput Options{..} currTime loadedCount [] evals = + (allGoodMessage target ++ " (" ++ show loadedCount ++ " module" ++ ['s' | loadedCount /= 1] ++ ", at " ++ currTime ++ ")") : concatMap printEval evals -prettyOutput _ _ xs evals = concatMap loadMessage xs ++ concatMap printEval evals +prettyOutput Options{..} _ _ xs evals = + heading target + : concatMap loadMessage xs ++ concatMap printEval evals + where + heading | any ((Error ==) . loadSeverity) xs = errorMessage + | otherwise = warningMessage printEval :: EvalResult -> [String] printEval (EvalResult file (line, col) msg result) = diff --git a/src/Language/Haskell/Ghcid/Util.hs b/src/Language/Haskell/Ghcid/Util.hs index 7be5c0d9..9ec8fa00 100644 --- a/src/Language/Haskell/Ghcid/Util.hs +++ b/src/Language/Haskell/Ghcid/Util.hs @@ -7,7 +7,7 @@ module Language.Haskell.Ghcid.Util( takeRemainder, outStr, outStrLn, ignored, - allGoodMessage, + allGoodMessage, errorMessage, warningMessage, getModTime, getModTimeResolution, getShortTime ) where @@ -85,8 +85,16 @@ ignored act = do waitBarrier bar -- | The message to show when no errors have been reported -allGoodMessage :: String -allGoodMessage = setSGRCode [SetColor Foreground Dull Green] ++ "All good" ++ setSGRCode [] +allGoodMessage :: [String] -> String +allGoodMessage target = setSGRCode [SetColor Foreground Dull Green] ++ "All good " ++ setSGRCode [] ++ "in " ++ concat target + +-- | The message to show when errors have been reported +errorMessage :: [String] -> String +errorMessage target = setSGRCode [SetColor Foreground Dull Red] ++ "Error " ++ setSGRCode [] ++ "in " ++ concat target + +-- | The message to show when only warnings have been reported +warningMessage :: [String] -> String +warningMessage target = setSGRCode [SetColor Foreground Dull Magenta] ++ "Warning " ++ setSGRCode [] ++ "in " ++ concat target -- | Given a 'FilePath' return either 'Nothing' (file does not exist) or 'Just' (the modification time) getModTime :: FilePath -> IO (Maybe UTCTime)