on master help sign in
Image: update text/string functions to indicate that escapes are not permitted
bb68f7aJonathan Daugherty
src/Graphics/Vty/Image.hs+8−4
@@ -113,12 +113,14 @@ horizCat = foldr horizJoin EmptyImage
113vertCat :: [Image] -> Image
113vertCat :: [Image] -> Image
114vertCat = foldr vertJoin EmptyImage
114vertCat = foldr vertJoin EmptyImage
115
115
116−-- | Make an 'Image' from a lazy text value.
116+-- | Make an 'Image' from a lazy text value. This function should not be
117+-- given a text value containing escapes.
117text :: Attr -> TL.Text -> Image
118text :: Attr -> TL.Text -> Image
118text a txt = let displayWidth = safeWcswidth (TL.unpack txt)
119text a txt = let displayWidth = safeWcswidth (TL.unpack txt)
119 in HorizText a txt displayWidth (fromIntegral $! TL.length txt)
120 in HorizText a txt displayWidth (fromIntegral $! TL.length txt)
120
121
121−-- | Make an 'Image' from a text value.
122+-- | Make an 'Image' from a text value. This function should not be
123+-- given a text value containing escapes.
122text' :: Attr -> T.Text -> Image
124text' :: Attr -> T.Text -> Image
123text' a txt = let displayWidth = safeWcswidth (T.unpack txt)
125text' a txt = let displayWidth = safeWcswidth (T.unpack txt)
124 in HorizText a (TL.fromStrict txt) displayWidth (T.length txt)
126 in HorizText a (TL.fromStrict txt) displayWidth (T.length txt)
@@ -132,7 +134,8 @@ char a c =
132
134
133-- | Make an image from a string of characters layed out on a single
135-- | Make an image from a string of characters layed out on a single
134-- row with the same display attribute. The string is assumed to be a
136-- row with the same display attribute. The string is assumed to be a
135−-- sequence of ISO-10646 characters.
137+-- sequence of ISO-10646 characters. This function should not be given a
138+-- string containing escapes.
136--
139--
137-- Note: depending on how the Haskell compiler represents string
140-- Note: depending on how the Haskell compiler represents string
138-- literals, a string literal in a UTF-8 encoded source file, for
141-- literals, a string literal in a UTF-8 encoded source file, for
@@ -149,7 +152,8 @@ iso10646String a str =
149--
152--
150-- This is an alias for iso10646String since the usual case is that a
153-- This is an alias for iso10646String since the usual case is that a
151-- literal string like "foo" is represented internally as a list of ISO
154-- literal string like "foo" is represented internally as a list of ISO
152−-- 10646 31 bit characters.
155+-- 10646 31 bit characters. This function should not be given a string
156+-- containing escapes.
153--
157--
154-- Note: Keep in mind that GHC will compile source encoded as UTF-8
158-- Note: Keep in mind that GHC will compile source encoded as UTF-8
155-- but the literal strings, while UTF-8 encoded in the source, will be
159-- but the literal strings, while UTF-8 encoded in the source, will be