diff --git a/app/Main.hs b/app/Main.hs index 085a60e..b967e74 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -9,7 +9,8 @@ import Unused.TermSearch (SearchResults(..), fromResults) import Unused.ResultsClassifier import Unused.ResponseFilter (withOneOccurrence, withLikelihoods, ignoringPaths) import Unused.Grouping (CurrentGrouping(..), groupedResponses) -import Unused.CLI (SearchRunner(..), withoutCursor, renderHeader, executeSearch, printMissingTagsFileError, printSearchResults, resetScreen, withInterruptHandler) +import Unused.CLI (SearchRunner(..), withoutCursor, renderHeader, executeSearch, resetScreen, withInterruptHandler) +import qualified Unused.CLI.Views as V import Unused.Cache import Unused.TagsSource @@ -42,7 +43,7 @@ run options = withoutCursor $ do terms' <- calculateTagInput options case terms' of - (Left e) -> printMissingTagsFileError e + (Left e) -> V.missingTagsFileError e (Right terms) -> do renderHeader terms @@ -59,7 +60,7 @@ run options = withoutCursor $ do return () printResults :: Options -> TermMatchSet -> IO () -printResults options = printSearchResults . groupedResponses (oGrouping options) . optionFilters options +printResults options = V.searchResults . groupedResponses (oGrouping options) . optionFilters options loadLanguageConfig :: IO [LanguageConfiguration] loadLanguageConfig = either (const []) id <$> loadConfig diff --git a/src/Unused/CLI.hs b/src/Unused/CLI.hs index ec3836d..d927d29 100644 --- a/src/Unused/CLI.hs +++ b/src/Unused/CLI.hs @@ -3,6 +3,4 @@ module Unused.CLI ) where import Unused.CLI.Search as X -import Unused.CLI.MissingTagsFileError as X -import Unused.CLI.SearchResult as X import Unused.CLI.Util as X diff --git a/src/Unused/CLI/Search.hs b/src/Unused/CLI/Search.hs index aa03cab..9e5019d 100644 --- a/src/Unused/CLI/Search.hs +++ b/src/Unused/CLI/Search.hs @@ -6,6 +6,7 @@ module Unused.CLI.Search import Unused.TermSearch (SearchResults, search) import Unused.CLI.Util +import qualified Unused.CLI.Views as V import Unused.CLI.ProgressIndicator data SearchRunner = SearchWithProgress | SearchWithoutProgress @@ -13,26 +14,13 @@ data SearchRunner = SearchWithProgress | SearchWithoutProgress renderHeader :: [String] -> IO () renderHeader terms = do resetScreen - printAnalysisHeader terms + V.analysisHeader terms executeSearch :: SearchRunner -> [String] -> IO SearchResults executeSearch runner terms = do renderHeader terms runSearch runner terms <* resetScreen -printAnalysisHeader :: [String] -> IO () -printAnalysisHeader terms = do - setSGR [SetConsoleIntensity BoldIntensity] - putStr "Unused: " - setSGR [Reset] - - putStr "analyzing " - - setSGR [SetColor Foreground Dull Green] - putStr $ show $ length terms - setSGR [Reset] - putStr " terms" - runSearch :: SearchRunner -> [String] -> IO SearchResults runSearch SearchWithProgress = progressWithIndicator search createProgressBar runSearch SearchWithoutProgress = progressWithIndicator search createSpinner diff --git a/src/Unused/CLI/Views.hs b/src/Unused/CLI/Views.hs new file mode 100644 index 0000000..e4e0166 --- /dev/null +++ b/src/Unused/CLI/Views.hs @@ -0,0 +1,8 @@ +module Unused.CLI.Views + ( module X + ) where + +import Unused.CLI.Views.NoResultsFound as X +import Unused.CLI.Views.AnalysisHeader as X +import Unused.CLI.Views.MissingTagsFileError as X +import Unused.CLI.Views.SearchResult as X diff --git a/src/Unused/CLI/Views/AnalysisHeader.hs b/src/Unused/CLI/Views/AnalysisHeader.hs new file mode 100644 index 0000000..6586005 --- /dev/null +++ b/src/Unused/CLI/Views/AnalysisHeader.hs @@ -0,0 +1,18 @@ +module Unused.CLI.Views.AnalysisHeader + ( analysisHeader + ) where + +import Unused.CLI.Util + +analysisHeader :: [String] -> IO () +analysisHeader terms = do + setSGR [SetConsoleIntensity BoldIntensity] + putStr "Unused: " + setSGR [Reset] + + putStr "analyzing " + + setSGR [SetColor Foreground Dull Green] + putStr $ show $ length terms + setSGR [Reset] + putStr " terms" diff --git a/src/Unused/CLI/MissingTagsFileError.hs b/src/Unused/CLI/Views/MissingTagsFileError.hs similarity index 88% rename from src/Unused/CLI/MissingTagsFileError.hs rename to src/Unused/CLI/Views/MissingTagsFileError.hs index 866714d..8cde5a4 100644 --- a/src/Unused/CLI/MissingTagsFileError.hs +++ b/src/Unused/CLI/Views/MissingTagsFileError.hs @@ -1,12 +1,12 @@ -module Unused.CLI.MissingTagsFileError - ( printMissingTagsFileError +module Unused.CLI.Views.MissingTagsFileError + ( missingTagsFileError ) where import Unused.TagsSource import Unused.CLI.Util -printMissingTagsFileError :: TagSearchOutcome -> IO () -printMissingTagsFileError e = do +missingTagsFileError :: TagSearchOutcome -> IO () +missingTagsFileError e = do setSGR [SetColor Background Vivid Red] setSGR [SetColor Foreground Vivid White] setSGR [SetConsoleIntensity BoldIntensity] @@ -45,4 +45,3 @@ printOutcomeMessage :: TagSearchOutcome -> IO () printOutcomeMessage (TagsFileNotFound directoriesSearched) = do putStrLn "Looked for a 'tags' file in the following directories:\n" mapM_ (\d -> putStrLn $ "* " ++ d) directoriesSearched - diff --git a/src/Unused/CLI/Views/NoResultsFound.hs b/src/Unused/CLI/Views/NoResultsFound.hs new file mode 100644 index 0000000..2aca9d5 --- /dev/null +++ b/src/Unused/CLI/Views/NoResultsFound.hs @@ -0,0 +1,12 @@ +module Unused.CLI.Views.NoResultsFound + ( noResultsFound + ) where + +import Unused.CLI.Util + +noResultsFound :: IO () +noResultsFound = do + setSGR [SetColor Foreground Dull Green] + setSGR [SetConsoleIntensity BoldIntensity] + putStrLn "Unused found no results" + setSGR [Reset] diff --git a/src/Unused/CLI/SearchResult.hs b/src/Unused/CLI/Views/SearchResult.hs similarity index 72% rename from src/Unused/CLI/SearchResult.hs rename to src/Unused/CLI/Views/SearchResult.hs index 7b32962..3fc49ef 100644 --- a/src/Unused/CLI/SearchResult.hs +++ b/src/Unused/CLI/Views/SearchResult.hs @@ -1,34 +1,35 @@ -module Unused.CLI.SearchResult - ( printSearchResults +module Unused.CLI.Views.SearchResult + ( searchResults ) where import Control.Monad (forM_) import qualified Data.Map.Strict as Map import Unused.Types import Unused.Grouping (Grouping(..), GroupedTerms) -import Unused.CLI.SearchResult.ColumnFormatter +import Unused.CLI.Views.SearchResult.ColumnFormatter import Unused.CLI.Util +import qualified Unused.CLI.Views.NoResultsFound as V -printSearchResults :: [GroupedTerms] -> IO () -printSearchResults responses = - printFormattedResponses columnFormat responses +searchResults :: [GroupedTerms] -> IO () +searchResults terms = + printFormattedTerms columnFormat terms where - allSets = listFromMatchSet =<< map snd responses + allSets = listFromMatchSet =<< map snd terms allResults = map snd allSets columnFormat = buildColumnFormatter allResults -printFormattedResponses :: ColumnFormat -> [GroupedTerms] -> IO () -printFormattedResponses _ [] = printNoResultsFound -printFormattedResponses cf r = mapM_ (printGroupingSection cf) r +printFormattedTerms :: ColumnFormat -> [GroupedTerms] -> IO () +printFormattedTerms _ [] = V.noResultsFound +printFormattedTerms cf ts = mapM_ (printGroupingSection cf) ts listFromMatchSet :: TermMatchSet -> [(String, TermResults)] listFromMatchSet = Map.toList printGroupingSection :: ColumnFormat -> GroupedTerms -> IO () -printGroupingSection cf (g, ss) = do +printGroupingSection cf (g, tms) = do printGrouping g - mapM_ (printTermResults cf) $ listFromMatchSet ss + mapM_ (printTermResults cf) $ listFromMatchSet tms printGrouping :: Grouping -> IO () printGrouping NoGrouping = return () @@ -76,10 +77,3 @@ printMatches cf r ms = printNumber = cfPrintNumber cf termColor = likelihoodColor . rLikelihood . trRemoval removalReason = rReason . trRemoval - -printNoResultsFound :: IO () -printNoResultsFound = do - setSGR [SetColor Foreground Dull Green] - setSGR [SetConsoleIntensity BoldIntensity] - putStrLn "Unused found no results" - setSGR [Reset] diff --git a/src/Unused/CLI/SearchResult/ColumnFormatter.hs b/src/Unused/CLI/Views/SearchResult/ColumnFormatter.hs similarity index 96% rename from src/Unused/CLI/SearchResult/ColumnFormatter.hs rename to src/Unused/CLI/Views/SearchResult/ColumnFormatter.hs index 343cda7..433d35f 100644 --- a/src/Unused/CLI/SearchResult/ColumnFormatter.hs +++ b/src/Unused/CLI/Views/SearchResult/ColumnFormatter.hs @@ -1,4 +1,4 @@ -module Unused.CLI.SearchResult.ColumnFormatter +module Unused.CLI.Views.SearchResult.ColumnFormatter ( ColumnFormat(..) , buildColumnFormatter ) where diff --git a/unused.cabal b/unused.cabal index 896a813..2988e6d 100644 --- a/unused.cabal +++ b/unused.cabal @@ -37,10 +37,13 @@ library , Unused.TagsSource , Unused.CLI , Unused.CLI.Search - , Unused.CLI.MissingTagsFileError - , Unused.CLI.SearchResult - , Unused.CLI.SearchResult.ColumnFormatter , Unused.CLI.Util + , Unused.CLI.Views + , Unused.CLI.Views.NoResultsFound + , Unused.CLI.Views.AnalysisHeader + , Unused.CLI.Views.MissingTagsFileError + , Unused.CLI.Views.SearchResult + , Unused.CLI.Views.SearchResult.ColumnFormatter , Unused.CLI.ProgressIndicator , Unused.CLI.ProgressIndicator.Internal , Unused.CLI.ProgressIndicator.Types