@@ -2,23 +2,7 @@
2{-# LANGUAGE BangPatterns #-}
2{-# LANGUAGE BangPatterns #-}
3{-# LANGUAGE NamedFieldPuns #-}
3{-# LANGUAGE NamedFieldPuns #-}
4{-# LANGUAGE DisambiguateRecordFields #-}
4{-# LANGUAGE DisambiguateRecordFields #-}
5−{-# LANGUAGE MagicHash, UnboxedTuples #-}
6{-# OPTIONS_GHC -funbox-strict-fields #-}
5{-# OPTIONS_GHC -funbox-strict-fields #-}
7−{- A picutre in VTY defines
8− - * properties required to display the image. These are properties that effect the output image
9− - but are independent of position
10− - * A set of position-dependent text and attribute regions. The possible regions are
12− - * a horizontal line of characters with a single attribute
13− - * a vertical line of a single character
14− - * a horizontal line of a single character.
15− - * a rectangle of a single character
19− - todo: Move to UTF-8 encoded bytestring streams?
22module Graphics.Vty.Image ( Image(..)
6module Graphics.Vty.Image ( Image(..)
23 , image_width
7 , image_width
24 , image_height
8 , image_height
@@ -31,7 +15,7 @@ module Graphics.Vty.Image ( Image(..)
31 , background_fill
15 , background_fill
34− , iso_10464_string
18+ , iso_10646_string
35 , utf8_string
19 , utf8_string
36 , utf8_bytestring
20 , utf8_bytestring
37 , char_fill
21 , char_fill
@@ -56,17 +40,34 @@ infixr 4 <->
57type StringSeq = Seq.Seq Char
41type StringSeq = Seq.Seq Char
43+-- | An image in VTY defines:
45+-- * properties required to display the image. These are properties that effect the output image
46+-- but are independent of position
48+-- * A set of position-dependent text and attribute regions. The possible regions are:
50+-- * a point. ( char )
52+-- * a horizontal line of characters with a single attribute. (string, utf8_string,
55+-- * a fill of a single character. (char_fill)
57+-- * a fill of the picture's background. (background_fill)
59+-- todo: increase the number of encoded bytestring formats supported.
59data Image =
60data Image =
60− -- | A horizontal text span is always >= 1 column and has a row height of 1.
61+ -- A horizontal text span is always >= 1 column and has a row height of 1.
62 { attr :: !Attr
63 { attr :: !Attr
63− -- | All character data is stored as Char sequences with the ISO-10646 encoding.
64+ -- All character data is stored as Char sequences with the ISO-10646 encoding.
64 , text :: StringSeq
65 , text :: StringSeq
65− -- | in columns
66+ -- in columns
66 , output_width :: !Word -- >= 0
67 , output_width :: !Word -- >= 0
67 , char_width :: !Word -- >= 1
68 , char_width :: !Word -- >= 1
69− -- | A horizontal join can be constructed between any two images. However a HorizJoin instance is
70+ -- A horizontal join can be constructed between any two images. However a HorizJoin instance is
70 -- required to be between two images of equal height. The horiz_join constructor adds blanks to
71 -- required to be between two images of equal height. The horiz_join constructor adds blanks to
71 -- the provided images that assure this is true for the HorizJoin value produced.
72 -- the provided images that assure this is true for the HorizJoin value produced.
72 | HorizJoin
73 | HorizJoin
@@ -75,7 +76,7 @@ data Image =
75 , output_width :: !Word -- >= 1
76 , output_width :: !Word -- >= 1
76 , output_height :: !Word -- >= 1
77 , output_height :: !Word -- >= 1
78− -- | A veritical join can be constructed between any two images. However a VertJoin instance is
79+ -- A veritical join can be constructed between any two images. However a VertJoin instance is
79 -- required to be between two images of equal width. The horiz_join constructor adds blanks to
80 -- required to be between two images of equal width. The horiz_join constructor adds blanks to
80 -- the provides images that assure this is true for the HorizJoin value produced.
81 -- the provides images that assure this is true for the HorizJoin value produced.
81 | VertJoin
82 | VertJoin
@@ -84,7 +85,7 @@ data Image =
84 , output_width :: !Word -- >= 1
85 , output_width :: !Word -- >= 1
85 , output_height :: !Word -- >= 1
86 , output_height :: !Word -- >= 1
87− -- | A background fill will be filled with the background pattern. The background pattern is
88+ -- A background fill will be filled with the background pattern. The background pattern is
88 -- defined as a property of the Picture this Image is used to form.
89 -- defined as a property of the Picture this Image is used to form.
90 { output_width :: !Word -- >= 1
91 { output_width :: !Word -- >= 1
@@ -173,14 +174,14 @@ vert_join i_0 i_1 w h
174vert_join _ _ _ _ = error "vert_join applied to undefined values."
175vert_join _ _ _ _ = error "vert_join applied to undefined values."
176−-- | An area of the picture's bacground (See `Background`) of w columns and h rows.
177+-- | An area of the picture's bacground (See Background) of w columns and h rows.
177background_fill :: Word -> Word -> Image
178background_fill :: Word -> Word -> Image
178background_fill w h
179background_fill w h
179 | w == 0 = IdImage
180 | w == 0 = IdImage
180 | h == 0 = IdImage
181 | h == 0 = IdImage
181 | otherwise = BGFill w h
182 | otherwise = BGFill w h
183−-- | Access the width of an Image.
184+-- | The width of an Image. This is the number display columns the image will occupy.
184image_width :: Image -> Word
185image_width :: Image -> Word
185image_width HorizText { output_width = w } = w
186image_width HorizText { output_width = w } = w
186image_width HorizJoin { output_width = w } = w
187image_width HorizJoin { output_width = w } = w
@@ -188,7 +189,7 @@ image_width VertJoin { output_width = w } = w
188image_width BGFill { output_width = w } = w
189image_width BGFill { output_width = w } = w
189image_width IdImage = 0
190image_width IdImage = 0
191−-- | Access the height of an Image.
192+-- | The height of an Image. This is the number of display rows the image will occupy.
192image_height :: Image -> Word
193image_height :: Image -> Word
193image_height HorizText {} = 1
194image_height HorizText {} = 1
194image_height HorizJoin { output_height = r } = r
195image_height HorizJoin { output_height = r } = r
@@ -197,10 +198,10 @@ image_height BGFill { output_height = r } = r
197image_height IdImage = 0
198image_height IdImage = 0
199-- | Combines two images side by side.
200-- | Combines two images side by side.
200−-- The result image will have a width equal to the sum of the two images width.
202+-- The result image will have a width equal to the sum of the two images width. And the height will
201−-- The height will equal the largest height of the two images
203+-- equal the largest height of the two images. The area not defined in one image due to a height
202−-- The area not defined in one image due to a height missmatch will be filled with the background
204+-- missmatch will be filled with the background pattern.
204(<|>) :: Image -> Image -> Image
205(<|>) :: Image -> Image -> Image
206-- Two horizontal text spans with the same attributes can be merged.
207-- Two horizontal text spans with the same attributes can be merged.
@@ -257,24 +258,30 @@ vertcat :: [Image] -> Image
257vertcat = vert_cat
258vertcat = vert_cat
259-- | an image of a single character. This is a standard Haskell 31-bit character assumed to be in
260-- | an image of a single character. This is a standard Haskell 31-bit character assumed to be in
260−-- the ISO-10464 encoding.
261+-- the ISO-10646 encoding.
261char :: Attr -> Char -> Image
262char :: Attr -> Char -> Image
262char !a !c = HorizText a (Seq.singleton c) (safe_wcwidth c) 1
263char !a !c = HorizText a (Seq.singleton c) (safe_wcwidth c) 1
264−-- | A string of characters layed out on a single row. The string is assumed to be a sequence of
265+-- | A string of characters layed out on a single row with the same display attribute. The string is
266+-- assumed to be a sequence of ISO-10646 characters.
265−-- ISO-10464 characters. Note: depending on how the Haskell compiler represents string literals a
268+-- Note: depending on how the Haskell compiler represents string literals a string literal in a
266−-- string literal in a UTF-8 encoded source file, for example, may be represented as a ISO-10464
269+-- UTF-8 encoded source file, for example, may be represented as a ISO-10646 string.
267−-- string. That is, I think, the case with GHC 6.10.
270+-- That is, I think, the case with GHC 6.10. This means, for the most part, you don't need to worry
271+-- about the encoding format when outputting string literals. Just provide the string literal
272+-- directly to iso_10646_string or string.
268−iso_10464_string :: Attr -> String -> Image
274+iso_10646_string :: Attr -> String -> Image
269−iso_10464_string !a !str = horiz_text a (Seq.fromList str) (safe_wcswidth str)
275+iso_10646_string !a !str = horiz_text a (Seq.fromList str) (safe_wcswidth str)
271-- | Alias for iso_10646_string. Since the usual case is that a literal string like "foo" is
277-- | Alias for iso_10646_string. Since the usual case is that a literal string like "foo" is
272−-- represented internally as a list of ISO 10646 31 bit characters.
278+-- represented internally as a list of ISO 10646 31 bit characters.
273-- Note: Keep in mind that GHC will compile source encoded as UTF-8 but the literal strings, while
280-- Note: Keep in mind that GHC will compile source encoded as UTF-8 but the literal strings, while
274-- UTF-8 encoded in the source, will be transcoded to a ISO 10646 31 bit characters runtime
281-- UTF-8 encoded in the source, will be transcoded to a ISO 10646 31 bit characters runtime
275-- representation.
282-- representation.
276string :: Attr -> String -> Image
283string :: Attr -> String -> Image
277−string = iso_10464_string
284+string = iso_10646_string
279-- | A string of characters layed out on a single row. The string is assumed to be a sequence of
286-- | A string of characters layed out on a single row. The string is assumed to be a sequence of
280-- UTF-8 characters.
287-- UTF-8 characters.
@@ -295,6 +302,10 @@ safe_wcswidth str = case wcswidth str of
295utf8_bytestring :: Attr -> BS.ByteString -> Image
302utf8_bytestring :: Attr -> BS.ByteString -> Image
296utf8_bytestring !a !bs = string a (UTF8.toString $ UTF8.fromRep bs)
303utf8_bytestring !a !bs = string a (UTF8.toString $ UTF8.fromRep bs)
305+-- | creates a fill of the specified character. The dimensions are in number of characters wide and
306+-- number of rows high.
308+-- Unlike the Background fill character this character can have double column display width.
298char_fill :: Enum d => Attr -> Char -> d -> d -> Image
309char_fill :: Enum d => Attr -> Char -> d -> d -> Image
299char_fill !a !c w h =
310char_fill !a !c w h =
300 vert_cat $ replicate (fromEnum h) $ horiz_cat $ replicate (fromEnum w) $ char a c
311 vert_cat $ replicate (fromEnum h) $ horiz_cat $ replicate (fromEnum w) $ char a c