on master help sign in
Cap minimum values of charFill arguments to zero

Fixes #127

commitcb25af0cd042392879efc789a629bbcce9007f66 authorEric Mertens <emertens@galois.com> dateWed 28 Jun 2017, 20:19 (9 years ago) parenta551914
2 files changed+15−8
.gitignore+1 src/Graphics/Vty/Image.hs+14−8
.gitignore+1
@@ -6,6 +6,7 @@ Setup
66dist
77dist-newstyle
88cabal.project.local
9+.ghc.environment.*
910test/benchmark
1011.hpc
1112.cabal-sandbox
src/Graphics/Vty/Image.hs+14−8
@@ -171,6 +171,9 @@ utf8Bytestring' :: Attr -> B.ByteString -> Image
171171utf8Bytestring' a bs = text' a (T.decodeUtf8 bs)
172172
173173-- | Make an image filling a region with the specified character.
174+--
175+-- If either the width or height are less than or equal to 0, then
176+-- the result is the empty image.
174177charFill :: Integral d
175178 => Attr
176179 -- ^ The attribute to use.
@@ -181,14 +184,17 @@ charFill :: Integral d
181184 -> d
182185 -- ^ The region height.
183186 -> Image
184−charFill _a _c 0 _h = EmptyImage
185−charFill _a _c _w 0 = EmptyImage
186−charFill a c w h =
187− vertCat $ replicate (fromIntegral h) $ HorizText a txt displayWidth charWidth
188− where
189− txt = TL.replicate (fromIntegral w) (TL.singleton c)
190− displayWidth = safeWcwidth c * (fromIntegral w)
191− charWidth = fromIntegral w
187+charFill a c w h
188+ | w <= 0 || h <= 0 = EmptyImage
189+ | otherwise = vertCat
190+ $ replicate (fromIntegral h)
191+ $ HorizText a txt displayWidth charWidth
192+ where
193+ txt = TL.replicate charWidth (TL.singleton c)
194+ displayWidth = safeWcwidth c * charWidth
195+
196+ charWidth :: Num a => a
197+ charWidth = fromIntegral w
192198
193199-- | The empty image. Useful for fold combinators. These occupy no space
194200-- and do not affect display attributes.