packages feed

rainbox 0.2.0.0 → 0.4.0.0

raw patch · 9 files changed

+78/−31 lines, 9 filesdep ~rainbow

Dependency ranges changed: rainbow

Files

README.md view
@@ -4,12 +4,6 @@ Provides pretty printing of boxes in two dimensions.  Rainbox is useful for console programs that need to format tabular data. -Current development status-==========================--Currently the library is done and passes all tests; I'm working on-adding more tests and some documentation.- Documentation ============= @@ -27,6 +21,29 @@ only on UNIX-like systems because it uses the UNIX terminfo library. I only develop for UNIX-like systems because they are the only ones I use.++Tests+=====++You can simply use "cabal test".  However, I recommend that you do:++    cabal configure --enable-tests+    cabal build+    dist/build/rainbox-test/rainbox-test+    dist/build/rainbox-visual/rainbox-visual++The last test, `rainbox-visual`, relies on you to examine the output+and make sure it looks correct.++Tests are also run on Travis:++[![Build Status](https://travis-ci.org/massysett/rainbox.svg?branch=master)](https://travis-ci.org/massysett/rainbox)++and although you can see the output of `rainbox-visual` there, it's+not formatted quite right on Travis.++At this time, Rainbox is verified to work with GHC versions 7.4.1,+7.6.3, and 7.8.2.  License =======
+ changelog view
@@ -0,0 +1,6 @@+0.4.0.0++  * update for newer version of rainbow, where each Chunk has a list of Text+  rather than a single Text++  * test with GHC 7.8.2
lib/Rainbox/Box.hs view
@@ -329,7 +329,7 @@     toChunk = either spcToChunk id . B.unNibble     spcToChunk ss =       Chunk (backgroundToTextSpec (B.spcBackground ss))-            (X.replicate (B.numSpaces ss) (X.singleton ' '))+            [X.replicate (B.numSpaces ss) (X.singleton ' ')]  -- | Prints a Box to standard output.  If standard output is not a -- terminal, no colors are used.  Otherwise, colors are used if your
lib/Rainbox/Box/Primitives.hs view
@@ -200,7 +200,7 @@   width :: a -> Int  instance HasWidth Bar where-  width = sum . map (X.length . text) . unBar+  width = sum . map (sum . map X.length . text) . unBar  instance HasWidth Box where   width b = case unBox b of@@ -210,7 +210,7 @@       x:_ -> width x  instance HasWidth Chunk where-  width = X.length . text+  width = sum . map X.length . text  -- # Making Boxes @@ -487,13 +487,25 @@            where              lenX = case unNibble x of               Left blnk -> numSpaces blnk-              Right chk -> X.length . text $ chk+              Right chk -> width chk              x' = case unNibble x of               Left blnk -> Nibble . Left $                 blnk { numSpaces = numSpaces blnk - n }-              Right chk -> Nibble . Right $ -                chk { text = X.drop n . text $ chk }+              Right chk -> Nibble . Right . dropChunkChars n $ chk +-- | Drops the given number of characters from a Chunk.+dropChunkChars :: Int -> Chunk -> Chunk+dropChunkChars n c = c { text = go n (text c) }+  where+    go nLeft ls = case ls of+      [] -> []+      t:ts+        | len < nLeft -> go (nLeft - len) ts+        | len == nLeft -> ts+        | otherwise -> X.drop nLeft t : ts+        where+          len = X.length t+ takeChars :: Int -> Rod -> Rod takeChars colsIn = Rod . go colsIn . unRod   where@@ -510,9 +522,20 @@                   ( numSpaces blnk,                     Nibble . Left $ blnk { numSpaces = n } )                 Right chk ->-                  ( X.length . text $ chk,-                    Nibble . Right $-                    chk { text = X.take n . text $ chk } )+                  ( width chk,+                    Nibble . Right . takeChunkChars n $ chk)++takeChunkChars :: Int -> Chunk -> Chunk+takeChunkChars n c = c { text = go n (text c) }+  where+    go nLeft ls = case ls of+      [] -> []+      t:ts+        | len < nLeft -> t : go (nLeft - len) ts+        | len == nLeft -> [t]+        | otherwise -> [X.take nLeft t]+        where+          len = X.length t  -- -- # Helpers
rainbox.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/  name:                rainbox-version:             0.2.0.0+version:             0.4.0.0 synopsis:            Two-dimensional box pretty printing, with colors description:            Prints boxes in two dimensions, with colors.  Boxes are@@ -20,9 +20,9 @@ copyright:           2014 Omari Norman category:            Text build-type:          Simple-extra-source-files:  README.md, sunlight-test.hs+extra-source-files:  README.md, sunlight-test.hs, changelog cabal-version:       >=1.10-tested-with: GHC ==7.4.1, GHC ==7.6.3+tested-with: GHC ==7.4.1, GHC ==7.6.3, GHC ==7.8.2  source-repository head   type: git@@ -40,7 +40,7 @@    build-depends:       base >=4.5.0.0 && < 5-    , rainbow >= 0.12.0.0+    , rainbow >= 0.14.0.0 && < 0.15     , text >= 0.11.3.1     , transformers >= 0.3.0.0     , array >= 0.4.0.1@@ -60,7 +60,7 @@     , tasty-quickcheck >= 0.8     , array >= 0.4.0.1     , base >= 4.5.0.0 && < 5-    , rainbow >= 0.12.0.0+    , rainbow >= 0.14.0.0 && < 0.15     , text >= 0.11.3.1     , transformers >= 0.3.0.0     , random >= 1.0.0.0@@ -79,7 +79,7 @@       QuickCheck >= 2.6 && < 2.7     , base >= 4.5.0.0 && < 5     , random >= 1.0.0.0-    , rainbow >= 0.12.0.0+    , rainbow >= 0.14.0.0 && < 0.15     , text >= 0.11.3.1     , tasty >= 0.8     , tasty-quickcheck >= 0.8@@ -103,7 +103,7 @@     , tasty-quickcheck >= 0.8     , array >= 0.4.0.1     , base >= 4.5.0.0 && < 5-    , rainbow >= 0.12.0.0+    , rainbow >= 0.14.0.0 && < 0.15     , text >= 0.11.3.1     , transformers >= 0.3.0.0     , QuickCheck >= 2.6 && < 2.7
sunlight-test.hs view
@@ -7,7 +7,8 @@   , tiCabal = "cabal"   , tiLowest = ("7.4.1", "ghc-7.4.1", "ghc-pkg-7.4.1")   , tiDefault = [ ("7.4.1", "ghc-7.4.1", "ghc-pkg-7.4.1")-                , ("7.6.3", "ghc-7.6.3", "ghc-pkg-7.6.3") ]+                , ("7.6.3", "ghc-7.6.3", "ghc-pkg-7.6.3")+                , ("7.8.2", "ghc-7.8.2", "ghc-pkg-7.8.2") ]   , tiTest = []   } 
test/Rainbox/Box/PrimitivesTests.hs view
@@ -17,7 +17,7 @@     c = elements ['0'..'Z']  genChunk :: Gen Chunk-genChunk = genText >>= G.chunk+genChunk = listOf genText >>= G.chunk  genHeight :: Gen Height genHeight = fmap Height $ frequency [(3, nonNeg), (1, neg)]@@ -69,7 +69,7 @@ genChunkLen bk l = do   let ts = backgroundToTextSpec bk   txt <- fmap X.pack $ vectorOf l (elements ['0'..'Z'])-  return $ Chunk ts txt+  return $ Chunk ts [txt]  -- | Generates a box of text; its horizontal and vertical size -- depends on the size parameter.@@ -155,7 +155,7 @@      , testProperty "makes Box with cols == number of characters" $ \i ->       let cks = iChunks i-          nChars = sum . map X.length . map text $ cks+          nChars = sum . map X.length . concat . map text $ cks       in (== nChars) . width $ chunks cks     ] 
test/Rainbox/BoxTests.hs view
@@ -35,7 +35,7 @@       (== 1) . height . chunk . iChunk      , testProperty "makes Box as wide as characters in chunk" $ \i ->-      let cs = X.length . text . iChunk $ i+      let cs = sum . map X.length . text . iChunk $ i       in (== cs) . width . chunk . iChunk $ i     ] 
test/Test/Rainbow/Generators.hs view
@@ -71,12 +71,12 @@ textSpec :: Gen TextSpec textSpec = liftM2 TextSpec style8 style256 -chunk :: X.Text -> Gen Chunk+chunk :: [X.Text] -> Gen Chunk chunk x = liftM2 Chunk textSpec (return x) --- | Generates one Chunk for each Text in the list and combines them--- into one Chunk.-combinedChunks :: [X.Text] -> Gen Chunk+-- | Generates one Chunk for each list of Text in the list and+-- combines them into one Chunk.+combinedChunks :: [[X.Text]] -> Gen Chunk combinedChunks ls = do   cs <- mapM chunk ls   return $ foldl (<>) mempty cs