mirror of
https://github.com/joshuaclayton/unused.git
synced 2024-09-11 04:45:28 +03:00
Left-align and pad widths for term column
This commit is contained in:
parent
49b7b65b17
commit
02f90fdb7d
21
app/Main.hs
21
app/Main.hs
@ -4,6 +4,7 @@ import Control.Monad.State
|
|||||||
import System.IO (hSetBuffering, BufferMode(NoBuffering), stdout)
|
import System.IO (hSetBuffering, BufferMode(NoBuffering), stdout)
|
||||||
import System.Console.ANSI
|
import System.Console.ANSI
|
||||||
import System.ProgressBar
|
import System.ProgressBar
|
||||||
|
import Text.Printf
|
||||||
import Unused.TermSearch (search)
|
import Unused.TermSearch (search)
|
||||||
import Unused.Parser (parseLines, ParseError)
|
import Unused.Parser (parseLines, ParseError)
|
||||||
import Unused.Types
|
import Unused.Types
|
||||||
@ -79,8 +80,13 @@ printAnalysisHeader terms = do
|
|||||||
printDirectorySection :: (DirectoryPrefix, TermMatchSet) -> IO ()
|
printDirectorySection :: (DirectoryPrefix, TermMatchSet) -> IO ()
|
||||||
printDirectorySection (dir, ss) = do
|
printDirectorySection (dir, ss) = do
|
||||||
printDirectory dir
|
printDirectory dir
|
||||||
mapM_ printTermResults $ listFromMatchSet ss
|
mapM_ (printTermResults maxWidth) $ allSets
|
||||||
putStr "\n"
|
putStr "\n"
|
||||||
|
where
|
||||||
|
allSets = listFromMatchSet ss
|
||||||
|
allResults = fmap snd allSets
|
||||||
|
termLength = return . length . term
|
||||||
|
maxWidth = maximum $ termLength =<< matches =<< allResults
|
||||||
|
|
||||||
printDirectory :: DirectoryPrefix -> IO ()
|
printDirectory :: DirectoryPrefix -> IO ()
|
||||||
printDirectory (DirectoryPrefix dir) = do
|
printDirectory (DirectoryPrefix dir) = do
|
||||||
@ -89,18 +95,19 @@ printDirectory (DirectoryPrefix dir) = do
|
|||||||
putStrLn dir
|
putStrLn dir
|
||||||
setSGR [Reset]
|
setSGR [Reset]
|
||||||
|
|
||||||
printTermResults :: (String, TermResults) -> IO ()
|
printTermResults :: Int -> (String, TermResults) -> IO ()
|
||||||
printTermResults (_, results) = do
|
printTermResults w (_, results) = do
|
||||||
printMatches results $ matches results
|
printMatches w results $ matches results
|
||||||
|
|
||||||
printMatches :: TermResults -> [TermMatch] -> IO ()
|
printMatches :: Int -> TermResults -> [TermMatch] -> IO ()
|
||||||
printMatches _r ms = do
|
printMatches w _r ms = do
|
||||||
mapM_ printMatch ms
|
mapM_ printMatch ms
|
||||||
where
|
where
|
||||||
|
termFormat = "%-" ++ (show w) ++ "s"
|
||||||
printMatch m = do
|
printMatch m = do
|
||||||
setSGR [SetColor Foreground Dull Red]
|
setSGR [SetColor Foreground Dull Red]
|
||||||
setSGR [SetConsoleIntensity NormalIntensity]
|
setSGR [SetConsoleIntensity NormalIntensity]
|
||||||
putStr $ " " ++ term m
|
putStr $ " " ++ (printf termFormat $ term m)
|
||||||
setSGR [Reset]
|
setSGR [Reset]
|
||||||
setSGR [SetColor Foreground Dull Cyan]
|
setSGR [SetColor Foreground Dull Cyan]
|
||||||
setSGR [SetConsoleIntensity FaintIntensity]
|
setSGR [SetConsoleIntensity FaintIntensity]
|
||||||
|
Loading…
Reference in New Issue
Block a user