rainbox 0.12.0.0 → 0.14.0.0
raw patch · 5 files changed
+75/−122 lines, 5 filesdep ~rainbowPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: rainbow
API changes (from Hackage documentation)
- Rainbox.Core: instance HasHeight Chunk
- Rainbox.Core: instance HasWidth Chunk
+ Rainbox.Core: instance HasHeight (Chunk a)
+ Rainbox.Core: instance HasWidth (Chunk Text)
- Rainbox: Cell :: Seq (Seq Chunk) -> Alignment Horizontal -> Alignment Vertical -> Radiant -> Cell
+ Rainbox: Cell :: Seq (Seq (Chunk Text)) -> Alignment Horizontal -> Alignment Vertical -> Radiant -> Cell
- Rainbox: cellRows :: Cell -> Seq (Seq Chunk)
+ Rainbox: cellRows :: Cell -> Seq (Seq (Chunk Text))
- Rainbox: fromChunk :: Alignment a -> Radiant -> Chunk -> Box a
+ Rainbox: fromChunk :: Alignment a -> Radiant -> Chunk Text -> Box a
- Rainbox: render :: Orientation a => Box a -> Seq Chunk
+ Rainbox: render :: Orientation a => Box a -> Seq (Chunk Text)
- Rainbox.Core: Cell :: Seq (Seq Chunk) -> Alignment Horizontal -> Alignment Vertical -> Radiant -> Cell
+ Rainbox.Core: Cell :: Seq (Seq (Chunk Text)) -> Alignment Horizontal -> Alignment Vertical -> Radiant -> Cell
- Rainbox.Core: Core :: (Either Chunk (Height, Width)) -> Core
+ Rainbox.Core: Core :: (Either (Chunk Text) (Height, Width)) -> Core
- Rainbox.Core: Rod :: (Either (Int, Radiant) Chunk) -> Rod
+ Rainbox.Core: Rod :: (Either (Int, Radiant) (Chunk Text)) -> Rod
- Rainbox.Core: cellRows :: Cell -> Seq (Seq Chunk)
+ Rainbox.Core: cellRows :: Cell -> Seq (Seq (Chunk Text))
- Rainbox.Core: chunksFromRodRows :: RodRows -> Seq (Seq Chunk)
+ Rainbox.Core: chunksFromRodRows :: RodRows -> Seq (Seq (Chunk Text))
- Rainbox.Core: fromChunk :: Alignment a -> Radiant -> Chunk -> Box a
+ Rainbox.Core: fromChunk :: Alignment a -> Radiant -> Chunk Text -> Box a
- Rainbox.Core: render :: Orientation a => Box a -> Seq Chunk
+ Rainbox.Core: render :: Orientation a => Box a -> Seq (Chunk Text)
- Rainbox.Tutorial: lineRow :: Radiant -> Line -> Seq Chunk
+ Rainbox.Tutorial: lineRow :: Radiant -> Line -> Seq (Chunk Text)
Files
- lib/Rainbox/Core.hs +18/−17
- lib/Rainbox/Tutorial.hs +10/−10
- rainbox.cabal +5/−5
- test/Rainbow/Instances.hs +38/−86
- test/rainbox-properties.hs +4/−4
lib/Rainbox/Core.hs view
@@ -14,6 +14,7 @@ import Data.Sequence (Seq, ViewL(..), viewl, (|>), (<|)) import qualified Data.Foldable as F import qualified Data.Sequence as Seq+import Data.Text (Text) import qualified Data.Text as X import qualified Data.Map as M @@ -80,7 +81,7 @@ instance HasHeight Height where height (Height a) = max 0 a -instance HasHeight Chunk where+instance HasHeight (Chunk a) where height _ = 1 instance (HasHeight a, HasHeight b) => HasHeight (Either a b) where@@ -92,8 +93,8 @@ instance HasWidth Width where width (Width a) = max 0 a -instance HasWidth Chunk where- width (Chunk _ ts) = F.sum . fmap X.length $ ts+instance HasWidth (Chunk Text) where+ width (Chunk _ _ t) = X.length t instance (HasWidth a, HasWidth b) => HasWidth (Either a b) where width = either width width@@ -102,7 +103,7 @@ -- | A 'Core' is either a single 'Chunk' or, if the box is blank, is -- merely a height and a width.-newtype Core = Core (Either Chunk (Height, Width))+newtype Core = Core (Either (Chunk Text) (Height, Width)) deriving (Eq, Ord, Show) instance HasWidth Core where@@ -115,7 +116,7 @@ -- | An intermediate type used in rendering; it consists either of -- text 'Chunk' or of a number of spaces coupled with a background color.-newtype Rod = Rod (Either (Int, Radiant) Chunk)+newtype Rod = Rod (Either (Int, Radiant) (Chunk Text)) deriving (Eq, Ord, Show) instance HasWidth Rod where@@ -167,12 +168,12 @@ -- | Converts a 'RodRows' to a nested 'Seq' of 'Chunk' in -- preparation for rendering. Newlines are added to the end of each -- line.-chunksFromRodRows :: RodRows -> Seq (Seq Chunk)+chunksFromRodRows :: RodRows -> Seq (Seq (Chunk Text)) chunksFromRodRows rr = case rr of- RodRowsWithHeight sq -> fmap (|> "\n") . fmap (fmap chunkFromRod) $ sq+ RodRowsWithHeight sq -> fmap (|> chunk "\n") . fmap (fmap chunkFromRod) $ sq where chunkFromRod (Rod ei) = case ei of- Left (i, r) -> (chunkFromText . X.replicate i $ " ") <> back r+ Left (i, r) -> (chunk . X.replicate i $ " ") & back r Right c -> c RodRowsNoHeight _ -> Seq.empty @@ -345,7 +346,7 @@ Payload (NonCenter ALeft) r (Right . Core . Right $ (Height (max 0 i), Width 0)) spreader a i = Box . Seq.singleton $- Payload a noColorRadiant (Right . Core . Right $+ Payload a mempty (Right . Core . Right $ (Height 0, Width (max 0 i))) instance Orientation Horizontal where@@ -355,7 +356,7 @@ Payload (NonCenter ATop) r (Right . Core . Right $ (Height 0, Width (max 0 i))) spreader a i = Box . Seq.singleton $- Payload a noColorRadiant (Right . Core . Right $+ Payload a mempty (Right . Core . Right $ (Height (max 0 i), Width 0)) -- # port, starboard, above, below@@ -428,7 +429,7 @@ -- ^ Background color. The background color in the 'Chunk' is not -- changed; this background is used if the 'Payload' must be padded -- later on.- -> Chunk+ -> Chunk Text -> Box a fromChunk a r = Box . Seq.singleton . Payload a r . Right . Core . Left @@ -464,7 +465,7 @@ -- | Convert a box to a 'Seq' of 'Chunk' in preparation for rendering. -- Use 'F.toList' to convert the 'Seq' of 'Chunk' to a list so that -- you can print it using the functions in "Rainbow".-render :: Orientation a => Box a -> Seq Chunk+render :: Orientation a => Box a -> Seq (Chunk Text) render = join . chunksFromRodRows . rodRows @@ -472,7 +473,7 @@ -- | A single cell in a spreadsheet-like grid. data Cell = Cell- { cellRows :: Seq (Seq Chunk)+ { cellRows :: Seq (Seq (Chunk Text)) -- ^ The cell can have multiple rows of text; there is one 'Seq' for -- each row of text. , cellHoriz :: Alignment Horizontal@@ -493,10 +494,10 @@ separator :: Radiant -> Int -> Cell separator rd i = Cell (Seq.singleton (Seq.singleton ck)) top left rd where- ck = (chunkFromText $ X.replicate (max 0 i) " ") <> back rd+ ck = (chunk $ X.replicate (max 0 i) " ") & back rd emptyCell :: Cell-emptyCell = Cell Seq.empty center center noColorRadiant+emptyCell = Cell Seq.empty center center mempty -- Cells by row:@@ -526,7 +527,7 @@ . equalize emptyCell rowToBoxV :: Box Horizontal -> Box Vertical-rowToBoxV = wrap center noColorRadiant+rowToBoxV = wrap center mempty cellToBoxV :: Cell -> (Box Vertical, Alignment Horizontal, Radiant) cellToBoxV (Cell rs ah av rd) = (bx, ah, rd)@@ -599,7 +600,7 @@ rowToBoxH :: Box Vertical -> Box Horizontal-rowToBoxH = wrap top noColorRadiant+rowToBoxH = wrap top mempty cellToBoxH :: Cell -> (Box Horizontal, Alignment Vertical, Radiant)
lib/Rainbox/Tutorial.hs view
@@ -340,7 +340,7 @@ -- given background is used as the background color for any added -- padding. textBox :: Radiant -> Text -> Box a-textBox r = fromChunk center r . chunkFromText+textBox r = fromChunk center r . chunk -- | Centers the given 'Box' within a larger 'Box' that has the given -- height and width and background color. The larger 'Box' has the@@ -445,36 +445,36 @@ nameCell :: Radiant -> Text -> Cell nameCell bk nm- = Cell (Seq.singleton . Seq.singleton $ (chunkFromText nm <> back bk))+ = Cell (Seq.singleton . Seq.singleton $ (chunk nm & back bk)) top left bk linesCell :: Radiant -> [Line] -> Cell linesCell bk lns = Cell (Seq.fromList . fmap (lineRow bk) $ lns) top right bk -lineRow :: Radiant -> Line -> Seq Chunk+lineRow :: Radiant -> Line -> Seq (Chunk Text) lineRow bk li = Seq.singleton ck where- ck = chunkFromText (X.pack . show $ li) <> fore clr <> back bk+ ck = chunk (X.pack . show $ li) & fore clr & back bk clr = case li of Red -> red Blue -> blue- Orange -> Radiant yellow8 (Just . Color256 . Just $ 220)+ Orange -> yellow <> color256 220 Green -> green Yellow -> yellow- Silver -> Radiant white8 (Just grey)+ Silver -> white <> grey addressCell :: Radiant -> [Text] -> Cell addressCell bk lns = Cell (Seq.fromList . fmap addrRow $ lns) top center bk where- addrRow txt = Seq.singleton $ chunkFromText txt <> back bk+ addrRow txt = Seq.singleton $ chunk txt & back bk undergroundCell :: Radiant -> Bool -> Cell undergroundCell bk bl = Cell (Seq.singleton . Seq.singleton $ ck) top left bk where- ck = (if bl then "Yes" else "No") <> back bk+ ck = (chunk $ if bl then "Yes" else "No") & back bk -- | Converts a 'Station' to a list of 'Cell'. @@ -490,10 +490,10 @@ stationTable = tableByRows . Seq.fromList- . zipWith stationRow (cycle [coloredBack, noColorRadiant])+ . zipWith stationRow (cycle [coloredBack, mempty]) $ stations where- coloredBack = Radiant noColor8 (Just . Color256 . Just $ 195)+ coloredBack = mempty <> color256 195 stationRow bk = intersperse (separator bk 1) . Seq.fromList
rainbox.cabal view
@@ -3,11 +3,11 @@ -- http://www.github.com/massysett/cartel -- -- Script name used to generate: genCabal.hs--- Generated on: 2015-04-14 07:08:21.967655 EDT+-- Generated on: 2015-04-25 16:47:00.642334 EDT -- Cartel library version: 0.14.2.6 name: rainbox-version: 0.12.0.0+version: 0.14.0.0 cabal-version: >= 1.18 license: BSD3 license-file: LICENSE@@ -43,7 +43,7 @@ lib build-depends: base >= 4.5.0.0 && < 4.9.0.0- , rainbow >= 0.22 && < 0.23+ , rainbow >= 0.24 && < 0.25 , bytestring >= 0.10 && < 0.11 , containers >= 0.5.5 && < 0.6 , text >= 0.11.3.1 && < 1.3.0.0@@ -56,7 +56,7 @@ main-is: rainbox-properties.hs build-depends: base >= 4.5.0.0 && < 4.9.0.0- , rainbow >= 0.22 && < 0.23+ , rainbow >= 0.24 && < 0.25 , bytestring >= 0.10 && < 0.11 , containers >= 0.5.5 && < 0.6 , text >= 0.11.3.1 && < 1.3.0.0@@ -81,7 +81,7 @@ main-is: rainbox-visual.hs build-depends: base >= 4.5.0.0 && < 4.9.0.0- , rainbow >= 0.22 && < 0.23+ , rainbow >= 0.24 && < 0.25 , bytestring >= 0.10 && < 0.11 , containers >= 0.5.5 && < 0.6 , text >= 0.11.3.1 && < 1.3.0.0
test/Rainbow/Instances.hs view
@@ -15,12 +15,16 @@ import Control.Applicative import Test.QuickCheck-import Rainbow.Colors import Rainbow.Types-import Data.Monoid-import Control.Monad import qualified Data.Text as X +instance Arbitrary a => Arbitrary (Color a) where+ arbitrary = Color <$> arbitrary+ shrink = genericShrink++instance CoArbitrary a => CoArbitrary (Color a) where+ coarbitrary (Color a) = coarbitrary a+ varInt :: Int -> Gen b -> Gen b varInt = variant @@ -39,51 +43,15 @@ E6 -> varInt 6 E7 -> varInt 7 -instance Arbitrary Color8 where- arbitrary = fmap Color8 arbitrary- shrink = genericShrink--instance CoArbitrary Color8 where- coarbitrary (Color8 Nothing) = varInt 0- coarbitrary (Color8 (Just e)) = varInt 1 . coarbitrary e--instance Arbitrary Color256 where- arbitrary = fmap Color256 arbitrary- shrink = genericShrink--instance CoArbitrary Color256 where- coarbitrary (Color256 Nothing) = varInt 0- coarbitrary (Color256 (Just w)) = varInt 1 . coarbitrary w--instance Arbitrary (Last Color8) where- arbitrary = fmap Last arbitrary--instance CoArbitrary (Last Color8) where- coarbitrary (Last Nothing) = varInt 0- coarbitrary (Last (Just c)) = varInt 1 . coarbitrary c--instance Arbitrary (Last Color256) where- arbitrary = fmap Last arbitrary--instance CoArbitrary (Last Color256) where- coarbitrary (Last Nothing) = varInt 0- coarbitrary (Last (Just c)) = varInt 1 . coarbitrary c--instance Arbitrary (Last Bool) where- arbitrary = fmap Last arbitrary--instance CoArbitrary (Last Bool) where- coarbitrary (Last Nothing) = varInt 0- coarbitrary (Last (Just b)) = varInt 1 . coarbitrary b--instance Arbitrary StyleCommon where+instance Arbitrary Format where arbitrary- = StyleCommon <$> g <*> g <*> g <*> g <*> g <*> g <*> g <*> g+ = Format <$> g <*> g <*> g <*> g <*> g <*> g <*> g <*> g where- g = fmap Last arbitrary+ g = arbitrary+ shrink = genericShrink -instance CoArbitrary StyleCommon where- coarbitrary (StyleCommon x0 x1 x2 x3 x4 x5 x6 x7)+instance CoArbitrary Format where+ coarbitrary (Format x0 x1 x2 x3 x4 x5 x6 x7) = coarbitrary x0 . coarbitrary x1 . coarbitrary x2@@ -92,56 +60,40 @@ . coarbitrary x5 . coarbitrary x6 . coarbitrary x7- -instance Arbitrary Style256 where- arbitrary = liftM3 Style256 arbitrary arbitrary arbitrary--instance CoArbitrary Style256 where- coarbitrary (Style256 x0 x1 x2)- = coarbitrary x0- . coarbitrary x1- . coarbitrary x2--instance Arbitrary Style8 where- arbitrary = liftM3 Style8 arbitrary arbitrary arbitrary--instance CoArbitrary Style8 where- coarbitrary (Style8 x0 x1 x2)- = coarbitrary x0- . coarbitrary x1- . coarbitrary x2--instance Arbitrary TextSpec where- arbitrary = liftM2 TextSpec arbitrary arbitrary+instance Arbitrary a => Arbitrary (Style a) where+ arbitrary = Style <$> arbitrary <*> arbitrary <*> arbitrary shrink = genericShrink -instance CoArbitrary TextSpec where- coarbitrary (TextSpec x0 x1)- = coarbitrary x0- . coarbitrary x1+instance CoArbitrary a => CoArbitrary (Style a) where+ coarbitrary (Style a b c)+ = coarbitrary a+ . coarbitrary b+ . coarbitrary c --- The Arbitrary instance for Text--- is different from the one that comes from the Rainbow package -instance Arbitrary X.Text where- arbitrary = fmap X.pack . listOf . elements $ ['0'..'Z']- shrink = map X.pack . shrink . X.unpack--instance Arbitrary Chunk where- arbitrary = liftM2 Chunk arbitrary- (listOf (fmap X.pack (listOf (elements ['a'..'z']))))+instance Arbitrary a => Arbitrary (Chunk a) where+ arbitrary = Chunk <$> arbitrary <*> arbitrary <*> arbitrary shrink = genericShrink -instance CoArbitrary Chunk where- coarbitrary (Chunk ts txts) = coarbitrary ts- . coarbitrary (map X.unpack txts)+instance CoArbitrary a => CoArbitrary (Chunk a) where+ coarbitrary (Chunk a b c)+ = coarbitrary a+ . coarbitrary b+ . coarbitrary c instance Arbitrary Radiant where- arbitrary = liftM2 Radiant arbitrary arbitrary+ arbitrary = Radiant <$> arbitrary <*> arbitrary shrink = genericShrink instance CoArbitrary Radiant where- coarbitrary (Radiant x0 x1)- = coarbitrary x0- . coarbitrary x1+ coarbitrary (Radiant a b) = coarbitrary a . coarbitrary b++instance Arbitrary X.Text where+ arbitrary = fmap X.pack $ listOf genChar+ where+ genChar = elements ['a'..'z']+ shrink = fmap X.pack . shrink . X.unpack++instance CoArbitrary X.Text where+ coarbitrary = coarbitrary . X.unpack
test/rainbox-properties.hs view
@@ -54,7 +54,7 @@ [ testGroup "never returns less than zero" $ let go a = let w = width a in classify (w > 2) "w > 2" (w >= 0) in [ testProperty "Chunk" $- \a -> go (a `asTypeOf` (undefined :: Chunk))+ \a -> go (a `asTypeOf` (undefined :: Chunk X.Text)) , testProperty "RodRows" $ \a -> go (a `asTypeOf` (undefined :: RodRows)) , testProperty "Rod" $@@ -74,9 +74,9 @@ , testGroup "chunk" $ [ testProperty "height is always 1" $ \c ->- let _types = c :: Chunk in height c == 1- , testProperty "width is sum of number of characters" $ \c@(Chunk _ t) ->- width c == F.sum (fmap X.length t)+ let _types = c :: Chunk X.Text in height c == 1+ , testProperty "width is sum of number of characters" $ \c@(Chunk _ _ t) ->+ let _types = c :: Chunk X.Text in width c == X.length t ] , testGroup "addVerticalPadding"