mirror of
https://github.com/joshuaclayton/unused.git
synced 2024-09-11 12:55:54 +03:00
Remove columns displaying occurrence/file count
These columns were not well-explained and, with limited space for headers, often led to confusion. This removes the columns. The data is still displayed in the more verbose output (currently visible when seeing corresponding commit SHAs, via the `--commits #` flag). Closes #60
This commit is contained in:
parent
7d9c923bd1
commit
3c3e479e45
@ -4,17 +4,16 @@ module Unused.CLI.Views.SearchResult.ColumnFormatter
|
|||||||
) where
|
) where
|
||||||
|
|
||||||
import Text.Printf (printf)
|
import Text.Printf (printf)
|
||||||
import Unused.Types (TermResults(..), TermMatch(..), totalFileCount, totalOccurrenceCount)
|
import Unused.Types (TermResults(..), TermMatch(..))
|
||||||
|
|
||||||
data ColumnFormat = ColumnFormat
|
data ColumnFormat = ColumnFormat
|
||||||
{ cfPrintTerm :: String -> String
|
{ cfPrintTerm :: String -> String
|
||||||
, cfPrintPath :: String -> String
|
, cfPrintPath :: String -> String
|
||||||
, cfPrintNumber :: Int -> String
|
|
||||||
}
|
}
|
||||||
|
|
||||||
buildColumnFormatter :: [TermResults] -> ColumnFormat
|
buildColumnFormatter :: [TermResults] -> ColumnFormat
|
||||||
buildColumnFormatter r =
|
buildColumnFormatter r =
|
||||||
ColumnFormat (printf $ termFormat r) (printf $ pathFormat r) (printf $ numberFormat r)
|
ColumnFormat (printf $ termFormat r) (printf $ pathFormat r)
|
||||||
|
|
||||||
termFormat :: [TermResults] -> String
|
termFormat :: [TermResults] -> String
|
||||||
termFormat rs =
|
termFormat rs =
|
||||||
@ -29,17 +28,3 @@ pathFormat rs =
|
|||||||
where
|
where
|
||||||
pathWidth = maximum $ pathLength =<< trMatches =<< rs
|
pathWidth = maximum $ pathLength =<< trMatches =<< rs
|
||||||
pathLength = return . length . tmPath
|
pathLength = return . length . tmPath
|
||||||
|
|
||||||
numberFormat :: [TermResults] -> String
|
|
||||||
numberFormat rs =
|
|
||||||
"%" ++ show numberWidth ++ "d"
|
|
||||||
where
|
|
||||||
numberWidth = maximum [fileWidth, occurrenceWidth]
|
|
||||||
fileWidth = maximum $ fileLength =<< rs
|
|
||||||
occurrenceWidth = maximum $ occurrenceLength =<< rs
|
|
||||||
fileLength = return . numberLength . totalFileCount
|
|
||||||
occurrenceLength = return . numberLength . totalOccurrenceCount
|
|
||||||
|
|
||||||
numberLength :: Int -> Int
|
|
||||||
numberLength i =
|
|
||||||
1 + floor (logBase 10 $ fromIntegral i :: Double)
|
|
||||||
|
@ -6,14 +6,13 @@ import Control.Monad (forM_)
|
|||||||
import Unused.CLI.Util
|
import Unused.CLI.Util
|
||||||
import qualified Unused.CLI.Views.SearchResult.Internal as SR
|
import qualified Unused.CLI.Views.SearchResult.Internal as SR
|
||||||
import qualified Unused.CLI.Views.SearchResult.Types as SR
|
import qualified Unused.CLI.Views.SearchResult.Types as SR
|
||||||
import Unused.Types (TermResults, TermMatch(..), tmDisplayTerm, totalFileCount, totalOccurrenceCount)
|
import Unused.Types (TermResults, TermMatch(..), tmDisplayTerm)
|
||||||
|
|
||||||
printTable :: TermResults -> [TermMatch] -> SR.ResultsPrinter ()
|
printTable :: TermResults -> [TermMatch] -> SR.ResultsPrinter ()
|
||||||
printTable r ms = do
|
printTable r ms = do
|
||||||
cf <- SR.columnFormat
|
cf <- SR.columnFormat
|
||||||
let printTerm = SR.cfPrintTerm cf
|
let printTerm = SR.cfPrintTerm cf
|
||||||
let printPath = SR.cfPrintPath cf
|
let printPath = SR.cfPrintPath cf
|
||||||
let printNumber = SR.cfPrintNumber cf
|
|
||||||
|
|
||||||
SR.liftIO $ forM_ ms $ \m -> do
|
SR.liftIO $ forM_ ms $ \m -> do
|
||||||
setSGR [SetColor Foreground Dull (SR.termColor r)]
|
setSGR [SetColor Foreground Dull (SR.termColor r)]
|
||||||
@ -21,11 +20,6 @@ printTable r ms = do
|
|||||||
putStr $ " " ++ printTerm (tmDisplayTerm m)
|
putStr $ " " ++ printTerm (tmDisplayTerm m)
|
||||||
setSGR [Reset]
|
setSGR [Reset]
|
||||||
|
|
||||||
setSGR [SetColor Foreground Vivid Cyan]
|
|
||||||
setSGR [SetConsoleIntensity NormalIntensity]
|
|
||||||
putStr $ " " ++ printNumber (totalFileCount r) ++ ", " ++ printNumber (totalOccurrenceCount r)
|
|
||||||
setSGR [Reset]
|
|
||||||
|
|
||||||
setSGR [SetColor Foreground Dull Cyan]
|
setSGR [SetColor Foreground Dull Cyan]
|
||||||
setSGR [SetConsoleIntensity FaintIntensity]
|
setSGR [SetConsoleIntensity FaintIntensity]
|
||||||
putStr $ " " ++ printPath (tmPath m)
|
putStr $ " " ++ printPath (tmPath m)
|
||||||
|
Loading…
Reference in New Issue
Block a user