From 50399ec4b1b0b47a110dcd8d30d4031341d3ae6b Mon Sep 17 00:00:00 2001 From: Joshua Clayton Date: Wed, 4 May 2016 20:51:41 -0400 Subject: [PATCH] Add number of files and number of occurrences --- app/Main.hs | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index bf470ea..d72a0aa 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -18,8 +18,13 @@ main = do case withOneOccurrence $ withOneFile response of Right termMatchSet -> do clearScreen - let responses = responsesGroupedByPath termMatchSet - mapM_ printDirectorySection responses + mapM_ (printDirectorySection $ maxWidth) responses + where + responses = responsesGroupedByPath termMatchSet + allSets = listFromMatchSet =<< map snd responses + allResults = fmap snd allSets + termLength = return . length . tmTerm + maxWidth = maximum $ termLength =<< trMatches =<< allResults Left e -> printParseError e @@ -77,16 +82,11 @@ printAnalysisHeader terms = do setSGR [Reset] putStr " terms\n\n" -printDirectorySection :: (DirectoryPrefix, TermMatchSet) -> IO () -printDirectorySection (dir, ss) = do +printDirectorySection :: Int -> (DirectoryPrefix, TermMatchSet) -> IO () +printDirectorySection w (dir, ss) = do printDirectory dir - mapM_ (printTermResults maxWidth) $ allSets + mapM_ (printTermResults w) $ listFromMatchSet ss putStr "\n" - where - allSets = listFromMatchSet ss - allResults = fmap snd allSets - termLength = return . length . tmTerm - maxWidth = maximum $ termLength =<< trMatches =<< allResults printDirectory :: DirectoryPrefix -> IO () printDirectory (DirectoryPrefix dir) = do @@ -111,6 +111,12 @@ printMatches w r ms = setSGR [SetConsoleIntensity NormalIntensity] putStr $ " " ++ (printf termFormat $ tmTerm m) setSGR [Reset] + + setSGR [SetColor Foreground Vivid Cyan] + setSGR [SetConsoleIntensity NormalIntensity] + putStr $ (printNumber $ trTotalFiles r) ++ "," ++ (printNumber $ trTotalOccurrences r) ++ " " + setSGR [Reset] + setSGR [SetColor Foreground Dull Cyan] setSGR [SetConsoleIntensity FaintIntensity] putStr $ " " ++ tmPath m @@ -118,6 +124,7 @@ printMatches w r ms = putStr "\n" where termFormat = "%-" ++ (show w) ++ "s" + printNumber = printf "%2d" printParseError :: ParseError -> IO () printParseError e = do