packages feed

highlight-versions (empty) → 0.1.0.0

raw patch · 4 files changed

+126/−0 lines, 4 filesdep +Cabaldep +ansi-terminaldep +basesetup-changed

Dependencies added: Cabal, ansi-terminal, base, containers, hackage-db

Files

+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2012, Brent Yorgey++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Brent Yorgey nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ highlight-versions.cabal view
@@ -0,0 +1,41 @@+name:                highlight-versions+version:             0.1.0.0+synopsis:            Highlight package versions which differ from the latest+                     version on Hackage+description:         This package provides an executable which reads from+                     stdin and outputs the same thing to stdout,+                     except that any lines which look like package+                     identifiers (e.g. foo-0.3.2) are highlighted if+                     the version does not match the latest version on+                     Hackage: red if the version is less than the+                     version on Hackage, or cyan if greater.  In+                     addition, the Hackage version is shown in blue.+                     .+                     In particular, it can be useful to pipe the+                     output of @cabal(-dev) install --dry-run@ through+                     this program, to aid in checking the install+                     plan. It's usually a good idea to understand why+                     an outdated package is being installed; otherwise+                     it can indicate that something needs to be updated.+license:             BSD3+license-file:        LICENSE+author:              Brent Yorgey+maintainer:          byorgey@cis.upenn.edu+copyright:           Copyright 2012 Brent Yorgey+category:            Distribution+build-type:          Simple+cabal-version:       >=1.10++source-repository head+  type: darcs+  location: http://code.haskell.org/~byorgey/code/highlight-versions++executable highlight-versions+  main-is:             Highlight.hs+  build-depends:       base >= 4 && < 5,+                       containers >= 0.4 && < 0.6,+                       hackage-db ==1.3.*,+                       Cabal ==1.14.*,+                       ansi-terminal ==0.5.*+  hs-source-dirs:      src+  default-language:    Haskell2010
+ src/Highlight.hs view
@@ -0,0 +1,53 @@+module Main where++import qualified Data.Map as M+import           Distribution.Hackage.DB+import           Distribution.Text (simpleParse)+import           Prelude+import qualified Prelude as P (map)+import           System.Console.ANSI++main = do+  db <- readHackage+  input <- getContents+  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.+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+    Nothing    -> putStrLn s+    Just pkgId ->+      -- look up this package name in the Hackage DB+      case (M.lookup (getPkgName pkgId) db) of+        Nothing -> putStrLn s+        Just versions -> do+          -- get the latest version and compare it to the stated version+          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++-- | 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+  setSGR [SetColor Foreground Vivid color]+  putStr s+  setSGR []+  putStr " ("+  setSGR [SetColor Foreground Vivid Blue]+  putStr (showVersion latest)+  setSGR []+  putStrLn ")"++getPkgName :: PackageIdentifier -> String+getPkgName pkgId = case pkgName pkgId of PackageName name -> name