Skip to content

Commit 783bfe6

Browse files
committed
Make the user interface match the skip/show/warn better
1 parent bc425c9 commit 783bfe6

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

src/Main.hs

+23-6
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,31 @@ main = do
2525
settings <- readSettings cmdHintFiles
2626
let apply = map (classify settings) . applyHint (readHints settings)
2727
ideas <- liftM concat $ mapM (liftM apply . parseFile) cmdFiles
28-
mapM_ print [i | i <- ideas, rank i /= Skip]
29-
30-
let n = length ideas
31-
if n == 0 then do
28+
mapM_ print [i | i <- ideas, cmdShowSkip || rank i /= Skip]
29+
30+
-- figure out statistics
31+
let counts = map (head &&& length) $ group $ sort $ map rank ideas
32+
let [skip,warn,fix] = map (fromMaybe 0 . flip lookup counts) [Skip,Warn,Fix]
33+
let total = skip + warn + fix
34+
let shown = if cmdShowSkip then total else total-skip
35+
let skipped = total-shown
36+
37+
if shown == 0 then do
3238
when (cmdReports /= []) $ putStrLn "Skipping writing reports"
33-
putStrLn "No relevant suggestions"
39+
printMsg "No relevant suggestions" [(skipped,"skipped")]
3440
else do
3541
flip mapM_ cmdReports $ \x -> do
3642
putStrLn $ "Writing report to " ++ x ++ " ..."
3743
writeReport x ideas
38-
putStrLn $ "Found " ++ show n ++ " suggestions"
44+
printMsg ("Found " ++ show shown ++ " suggestion" ++ ['s'|shown/=1])
45+
[(fix,"serious"),(skipped,"skipped")]
46+
47+
48+
printMsg :: String -> [(Int, String)] -> IO ()
49+
printMsg msg extras =
50+
putStrLn $ msg ++ if null xs then "" else
51+
" (" ++ intercalate ", " xs ++ ")"
52+
where
53+
xs = concatMap f extras
54+
f (0,_) = []
55+
f (i,x) = [unwords [show i, if i == 1 then "was" else "were", x]]

src/Type.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ instance Show Idea where
4343
show (Classify x y z) = unwords ["Classify",show x,show y,show z]
4444

4545
show x = unlines $
46-
[showSrcLoc (loc x) ++ " " ++ hint x] ++ f "Found" from ++ f "Why not" to
46+
[showSrcLoc (loc x) ++ " (" ++ show (rank x) ++ ") " ++ hint x] ++ f "Found" from ++ f "Why not" to
4747
where f msg sel = (msg ++ ":") : map (" "++) (lines $ sel x)
4848

4949
showList = showString . concatMap show

0 commit comments

Comments
 (0)