From cb25af0cd042392879efc789a629bbcce9007f66 Mon Sep 17 00:00:00 2001 From: Eric Mertens Date: Wed, 28 Jun 2017 20:19:04 -0500 Subject: [PATCH] Cap minimum values of charFill arguments to zero Fixes #127 --- .gitignore | 1 + src/Graphics/Vty/Image.hs | 22 ++++++++++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 0177ed2..0f9e2f1 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ Setup dist dist-newstyle cabal.project.local +.ghc.environment.* test/benchmark .hpc .cabal-sandbox diff --git a/src/Graphics/Vty/Image.hs b/src/Graphics/Vty/Image.hs index 1fb90aa..95ca841 100644 --- a/src/Graphics/Vty/Image.hs +++ b/src/Graphics/Vty/Image.hs @@ -171,6 +171,9 @@ utf8Bytestring' :: Attr -> B.ByteString -> Image utf8Bytestring' a bs = text' a (T.decodeUtf8 bs) -- | Make an image filling a region with the specified character. +-- +-- If either the width or height are less than or equal to 0, then +-- the result is the empty image. charFill :: Integral d => Attr -- ^ The attribute to use. @@ -181,14 +184,17 @@ charFill :: Integral d -> d -- ^ The region height. -> Image -charFill _a _c 0 _h = EmptyImage -charFill _a _c _w 0 = EmptyImage -charFill a c w h = - vertCat $ replicate (fromIntegral h) $ HorizText a txt displayWidth charWidth - where - txt = TL.replicate (fromIntegral w) (TL.singleton c) - displayWidth = safeWcwidth c * (fromIntegral w) - charWidth = fromIntegral w +charFill a c w h + | w <= 0 || h <= 0 = EmptyImage + | otherwise = vertCat + $ replicate (fromIntegral h) + $ HorizText a txt displayWidth charWidth + where + txt = TL.replicate charWidth (TL.singleton c) + displayWidth = safeWcwidth c * charWidth + + charWidth :: Num a => a + charWidth = fromIntegral w -- | The empty image. Useful for fold combinators. These occupy no space -- and do not affect display attributes.