ls-usb 0.1 → 0.1.0.1
raw patch · 3 files changed
+14/−33 lines, 3 filesdep ~ansi-wl-pprintdep ~bytestringdep ~usbsetup-changed
Dependency ranges changed: ansi-wl-pprint, bytestring, usb
Files
- Setup.hs +1/−0
- ls-usb.cabal +6/−6
- ls-usb.hs +7/−27
Setup.hs view
@@ -1,2 +1,3 @@ import Distribution.Simple+ main = defaultMain
ls-usb.cabal view
@@ -1,5 +1,5 @@ name: ls-usb-version: 0.1+version: 0.1.0.1 cabal-version: >= 1.6 build-type: Simple stability: experimental@@ -14,12 +14,12 @@ A small utility that lists USB devices connected to your system. executable ls-usb- build-depends: ansi-wl-pprint == 0.5.*- , base >= 4.0 && < 4.2- , bytestring == 0.9.*+ build-depends: ansi-wl-pprint >= 0.5.1 && < 0.6+ , base >= 4.0 && < 4.2+ , bytestring >= 0.9.1.4 && < 0.10 , cmdargs == 0.1.*- , usb == 0.1.*+ , usb >= 0.1 && < 0.3 , usb-id-database == 0.4.*- ghc-options: -O2 -Wall -fno-warn-orphans+ ghc-options: -Wall -fno-warn-orphans main-is: ls-usb.hs other-modules: PrettyDevList
ls-usb.hs view
@@ -7,13 +7,9 @@ , brightStyle, darkStyle ) import System.Console.CmdArgs-import System.IO ( stdout ) import System.USB import System.USB.IDDB.LinuxUsbIdRepo ( staticDb )-import Text.PrettyPrint.ANSI.Leijen ( Doc, SimpleDoc(..)- , displayIO- , putDoc, renderPretty- )+import Text.PrettyPrint.ANSI.Leijen ( putDoc, plain ) ------------------------------------------------------------------------------- -- Main@@ -45,13 +41,13 @@ & helpSuffix ["Please ensure you have sufficient rights before running with higher verbosity"] main :: IO ()-main = do opts <- cmdArgs "ls-usb 0.1, (C) Roel van Dijk 2009" [defaultOpts]+main = do opts <- cmdArgs "ls-usb 0.1.0.1, (C) Roel van Dijk 2009" [defaultOpts] verbose <- isLoud db <- staticDb ctx <- newCtx let style | darker opts = darkStyle | otherwise = brightStyle- printDoc (not $ nocolour opts)+ (putDoc . if nocolour opts then plain else id) =<< ppDevices style db verbose =<< filterM (filterFromOpts opts) =<< getDevices ctx@@ -71,14 +67,14 @@ type F m a = a -> m Bool -- Construct a filter combinator from a binary boolean operator.-boolBinOpToFComb :: Monad m => (Bool -> Bool -> Bool) -> F m a -> F m a -> F m a-boolBinOpToFComb op f g = \x -> liftM2 op (f x) (g x)+binBoolOpToFComb :: Monad m => (Bool -> Bool -> Bool) -> F m a -> F m a -> F m a+binBoolOpToFComb op f g = \x -> liftM2 op (f x) (g x) (<||>) :: Monad m => F m a -> F m a -> F m a-(<||>) = boolBinOpToFComb (||)+(<||>) = binBoolOpToFComb (||) (<&&>) :: Monad m => F m a -> F m a -> F m a-(<&&>) = boolBinOpToFComb (&&)+(<&&>) = binBoolOpToFComb (&&) constF :: Monad m => Bool -> F m a constF = const . return@@ -116,19 +112,3 @@ . (address' ==) . fromIntegral =<< getDeviceAddress dev------------------------------------------------------------------------------------ Pretty printer utilities--printDoc :: Bool -> Doc -> IO ()-printDoc colour doc | colour = putDoc doc- | otherwise = displayIO stdout- . stripColours- $ renderPretty 0.4 100 doc- where- stripColours :: SimpleDoc -> SimpleDoc- stripColours e@(SEmpty) = e- stripColours (SChar c d) = SChar c $ stripColours d- stripColours (SText l s d) = SText l s $ stripColours d- stripColours (SLine l d) = SLine l $ stripColours d- stripColours (SSGR _ d) = stripColours d