on master help sign in
Cap minimum values of charFill arguments to zero
cb25af0Eric Mertens
.gitignore+1
@@ -6,6 +6,7 @@ Setup
6dist
6dist
7dist-newstyle
7dist-newstyle
8cabal.project.local
8cabal.project.local
9+.ghc.environment.*
9test/benchmark
10test/benchmark
10.hpc
11.hpc
11.cabal-sandbox
12.cabal-sandbox
src/Graphics/Vty/Image.hs+14−8
@@ -171,6 +171,9 @@ utf8Bytestring' :: Attr -> B.ByteString -> Image
171utf8Bytestring' a bs = text' a (T.decodeUtf8 bs)
171utf8Bytestring' a bs = text' a (T.decodeUtf8 bs)
172
172
173-- | Make an image filling a region with the specified character.
173-- | 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.
174charFill :: Integral d
177charFill :: Integral d
175 => Attr
178 => Attr
176 -- ^ The attribute to use.
179 -- ^ The attribute to use.
@@ -181,14 +184,17 @@ charFill :: Integral d
181 -> d
184 -> d
182 -- ^ The region height.
185 -- ^ The region height.
183 -> Image
186 -> Image
184−charFill _a _c 0 _h = EmptyImage
187+charFill a c w h
185−charFill _a _c _w 0 = EmptyImage
188+ | w <= 0 || h <= 0 = EmptyImage
186−charFill a c w h =
189+ | otherwise = vertCat
190+ $ replicate (fromIntegral h)
187− vertCat $ replicate (fromIntegral h) $ HorizText a txt displayWidth charWidth
191+ $ HorizText a txt displayWidth charWidth
188− where
192+ where
189− txt = TL.replicate (fromIntegral w) (TL.singleton c)
193+ txt = TL.replicate charWidth (TL.singleton c)
190− displayWidth = safeWcwidth c * (fromIntegral w)
194+ displayWidth = safeWcwidth c * charWidth
195+
196+ charWidth :: Num a => a
191− charWidth = fromIntegral w
197+ charWidth = fromIntegral w
192
198
193-- | The empty image. Useful for fold combinators. These occupy no space
199-- | The empty image. Useful for fold combinators. These occupy no space
194-- and do not affect display attributes.
200-- and do not affect display attributes.