highlight-versions 0.1.0.0 → 0.1.1.0
raw patch · 3 files changed
+27/−15 lines, 3 files
Files
- CHANGES +8/−0
- highlight-versions.cabal +2/−1
- src/Highlight.hs +17/−14
+ CHANGES view
@@ -0,0 +1,8 @@+* 0.1.1.0: 25 August 2012++ - Highlight package identifiers even if more stuff comes after them+ on the same line++* 0.1.0.0: 25 August 2012++ Initial release
highlight-versions.cabal view
@@ -1,5 +1,5 @@ name: highlight-versions-version: 0.1.0.0+version: 0.1.1.0 synopsis: Highlight package versions which differ from the latest version on Hackage description: This package provides an executable which reads from@@ -19,6 +19,7 @@ it can indicate that something needs to be updated. license: BSD3 license-file: LICENSE+extra-source-files: CHANGES author: Brent Yorgey maintainer: byorgey@cis.upenn.edu copyright: Copyright 2012 Brent Yorgey
src/Highlight.hs view
@@ -1,5 +1,6 @@ module Main where +import Data.Char (isSpace) import qualified Data.Map as M import Distribution.Hackage.DB import Distribution.Text (simpleParse)@@ -13,16 +14,17 @@ let ls = lines input mapM_ (highlightOutdated db) ls --- | Take an individual line of output and see if it looks like a--- package identifier (/i.e./ @foo-0.3.2@). If so, compare it to--- the latest version on Hackage, and highlight it if the version--- differs (in red if the version is older than the latest on--- Hackage, or cyan if newer), also printing the version of the--- latest Hackage release in blue.+-- | Take an individual line of output and see if the first word on+-- the line looks like a package identifier (/i.e./ @foo-0.3.2@). If+-- so, compare it to the latest version on Hackage, and highlight it+-- if the version differs (in red if the version is older than the+-- latest on Hackage, or cyan if newer), also printing the version of+-- the latest Hackage release in blue. highlightOutdated :: Hackage -> String -> IO ()-highlightOutdated db s =- -- try to parse this line as a package identifier (like foo-1.3.2)- case simpleParse s of+highlightOutdated db s = do+ let (p,rest) = break isSpace s+ -- try to parse the beginning of the line as a package identifier (like foo-1.3.2)+ case simpleParse p of Nothing -> putStrLn s Just pkgId -> -- look up this package name in the Hackage DB@@ -33,13 +35,13 @@ let latest = maximum . P.map fst . M.assocs $ versions case compare (pkgVersion pkgId) latest of EQ -> putStrLn s- LT -> doHighlight s latest Red -- show outdated versions in red- GT -> doHighlight s latest Cyan -- show newer versions in cyan+ LT -> doHighlight p latest Red rest -- show outdated versions in red+ GT -> doHighlight p latest Cyan rest -- show newer versions in cyan -- | Output a package name highlighted in a given color, along with -- another version in blue.-doHighlight :: String -> Version -> Color -> IO ()-doHighlight s latest color = do+doHighlight :: String -> Version -> Color -> String -> IO ()+doHighlight s latest color rest = do setSGR [SetColor Foreground Vivid color] putStr s setSGR []@@ -47,7 +49,8 @@ setSGR [SetColor Foreground Vivid Blue] putStr (showVersion latest) setSGR []- putStrLn ")"+ putStr ")"+ putStrLn rest getPkgName :: PackageIdentifier -> String getPkgName pkgId = case pkgName pkgId of PackageName name -> name