Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions src/Ghcid.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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) <-
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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) =
Expand Down
14 changes: 11 additions & 3 deletions src/Language/Haskell/Ghcid/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Language.Haskell.Ghcid.Util(
takeRemainder,
outStr, outStrLn,
ignored,
allGoodMessage,
allGoodMessage, errorMessage, warningMessage,
getModTime, getModTimeResolution, getShortTime
) where

Expand Down Expand Up @@ -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)
Expand Down