Skip to content
Browse files

A bit prettier... thanks to sjanssen

  • Loading branch information...
1 parent 9448bb7 commit 2ee9bd4b26f9cfe0e4135da203eba1b999313aff @kolmodin kolmodin committed Aug 14, 2007
Showing with 18 additions and 11 deletions.
  1. +2 −0 AnsiColor.hs
  2. +13 −9 OverlayPortageDiff.hs
  3. +3 −2 P2.hs
View
2 AnsiColor.hs
@@ -32,6 +32,7 @@ col fg bf bg = show (fromEnum fg + 30) : bf' [show (fromEnum bg + 40)]
inColor c bf bg txt = esc (col c bf bg) ++ txt ++ esc ["00"]
+{-
data Doc = Doc (Bool -> String -> String)
char chr = Doc (\_ c -> chr:c)
@@ -48,3 +49,4 @@ color (Doc d) color = Doc (\ b c ->
if not b
then d b c
else inColor color False Default (d b ""))
+-}
View
22 OverlayPortageDiff.hs
@@ -9,6 +9,7 @@ import Diff
import Portage
import P2
+import Control.Arrow
import Control.Monad.Error
import Control.Monad.State
@@ -22,6 +23,8 @@ import Data.Char
import qualified Data.Map as Map
import qualified Data.Set as Set
+import qualified Data.Traversable as T
+
data Diff a = D
{ sameSame :: [a] -- ^ file exists in both portdirs, and are identical
, fileDiffers :: [a] -- ^ file exists in both portdirs, but are different
@@ -39,21 +42,22 @@ overlayonly = do
info "These packages are in the overlay but not in the portage tree:"
let (over, both) = portageDiff overlay portage
- forM_ (Map.toAscList both) $ \(package, ebuilds) -> liftIO $ do
- print package
- forM_ ebuilds $ \e -> do
+ both' <- T.forM both $ mapM $ \e -> liftIO $ do
-- can't fail, we know the ebuild exists in both portagedirs
let (Just e1) = lookupEbuildWith portage (ePackage e) (comparing eVersion e)
(Just e2) = lookupEbuildWith overlay (ePackage e) (comparing eVersion e)
eq <- equals (eFilePath e1) (eFilePath e2)
- let c | eq = Green
- | otherwise = Yellow
- putStrLn (showDoc (color (text $ show $ eVersion e) c) True)
+ return (let ev = eVersion e in (ev, toColor (if eq then Green else Yellow) (show ev)))
+
+ let over' = Map.map (map ((id &&& (toColor Red . show)).eVersion)) over
- liftIO $ putStrLn "**"
- forM_ (Map.toAscList over) $ \(package, ebuilds) -> liftIO $ do
+ meld = Map.map (map snd) $ Map.unionWith (\a b -> List.sort (a++b)) both' over'
+
+ forM_ (Map.toAscList meld) $ \(package, versions) -> liftIO $ do
print package
- forM_ ebuilds $ \e -> do print (eVersion e)
+ forM_ versions putStrLn
+
+toColor c t = inColor c False Default t
-- incomplete
portageDiff :: Portage -> Portage -> (Portage, Portage)
View
5 P2.hs
@@ -1,5 +1,7 @@
module P2 where
+import BlingBling
+
import qualified Data.Set as Set
import Control.Arrow
@@ -40,7 +42,6 @@ lookupEbuildWith portage package comp = do
es <- Map.lookup package portage
List.find comp es
-
main' = do
args <- getArgs
portdir <- case args of
@@ -51,7 +52,7 @@ main' = do
readPortageTree :: FilePath -> IO (Map Package [Ebuild])
readPortageTree portdir = do
categories <- getDirectories portdir
- packages <- fmap concat $ forM categories $ \c -> do
+ packages <- fmap concat $ forMbling categories $ \c -> do
putStr "."
pkg <- getDirectories (portdir </> c)
return (map ((,) c) pkg)

0 comments on commit 2ee9bd4

Please sign in to comment.
Something went wrong with that request. Please try again.