Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add target to status output #343

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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 =
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My concern is that if you have only a handful of lines (e.g. 5) then in the case where you have errors/warnings, you've added 1 header line and decreased the amount of error/warning to display - potentially by a meaningful amount.

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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If target is blank, as it often will be, this will look really odd - i suspect you need to hide the "in " in that case.


-- | 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