1{-# LANGUAGE NamedFieldPuns #-}
2module Graphics.Vty.Image.Internal where
4import Graphics.Vty.Attributes
8import qualified Data.Text.Lazy as TL
10-- | A display text is a Data.Text.Lazy
12-- TODO(corey): hm. there is an explicit equation for each type which goes to a lazy text. Each
13-- application probably uses a single type. Perhaps parameterize the entire vty interface by the
15type DisplayText = TL.Text
17-- | An image in VTY is
19-- * a horizontal line of characters with a single attribute.
20-- * a fill of the picture's background. (background_fill)
21-- * a horizontal and vertical crops from both directions.
22-- * horizontal and vertical combinations
24 -- | A horizontal text span is always >= 1 column and has a row height of 1.
27 -- | The text to display. The display width of the text is always output_width.
28 , display_text :: DisplayText
29 -- | The number of display columns for the text.
31 -- | the number of characters in the text.
34 -- | A horizontal join can be constructed between any two images. However a HorizJoin instance is
35 -- required to be between two images of equal height. The horiz_join constructor adds background
36 -- filles to the provided images that assure this is true for the HorizJoin value produced.
40 , output_width :: Int -- ^ image_width part_left == image_width part_right. Always > 1
41 , output_height :: Int -- ^ image_height part_left == image_height part_right. Always > 0
43 -- | A veritical join can be constructed between any two images. However a VertJoin instance is
44 -- required to be between two images of equal width. The vert_join constructor adds background
45 -- fills to the provides images that assure this is true for the VertJoin value produced.
48 , part_bottom :: Image
49 , output_width :: Int -- ^ image_width part_top == image_width part_bottom. always > 0
50 , output_height :: Int -- ^ image_height part_top == image_height part_bottom. always > 1
52 -- | A background fill will be filled with the background char. The background char is
53 -- defined as a property of the Picture this Image is used to form.
55 { output_width :: Int -- ^ always > 0
56 , output_height :: Int -- ^ always > 0
58 -- | Crop an image horizontally to a size by reducing the size from the right.
60 { cropped_image :: Image
61 -- | Always < image_width cropped_image > 0
63 , output_height :: Int -- ^ image_height cropped_image
65 -- | Crop an image horizontally to a size by reducing the size from the left.
67 { cropped_image :: Image
68 -- | Always < image_width cropped_image > 0
70 -- | Always < image_width cropped_image > 0
72 , output_height :: Int
74 -- | Crop an image vertically to a size by reducing the size from the bottom
76 { cropped_image :: Image
77 -- | image_width cropped_image
79 -- | height image is cropped to. Always < image_height cropped_image > 0
80 , output_height :: Int
82 -- | Crop an image vertically to a size by reducing the size from the top
84 { cropped_image :: Image
85 -- | Always < image_height cropped_image > 0
87 -- | image_width cropped_image
89 -- | Always < image_height cropped_image > 0
90 , output_height :: Int
94 -- The combining operators identity constant.
95 -- EmptyImage <|> a = a
96 -- EmptyImage <-> a = a
98 -- Any image of zero size equals the empty image.
102instance Show Image where
103 show ( HorizText { attr, display_text, output_width, char_width } )
104 = "HorizText " ++ show display_text
105 ++ "@(" ++ show attr ++ ","
106 ++ show output_width ++ ","
107 ++ show char_width ++ ")"
108 show ( BGFill { output_width, output_height } )
109 = "BGFill (" ++ show output_width ++ "," ++ show output_height ++ ")"
110 show ( HorizJoin { part_left = l, part_right = r, output_width = c } )
111 = "HorizJoin " ++ show c ++ " (" ++ show l ++ " <|> " ++ show r ++ ")"
112 show ( VertJoin { part_top = t, part_bottom = b, output_width = c, output_height = r } )
113 = "VertJoin [" ++ show c ++ ", " ++ show r ++ "] (" ++ show t ++ ") <-> (" ++ show b ++ ")"
114 show ( CropRight { cropped_image, output_width, output_height } )
115 = "CropRight [" ++ show output_width ++ "," ++ show output_height ++ "]"
116 ++ " (" ++ show cropped_image ++ ")"
117 show ( CropLeft { cropped_image, left_skip, output_width, output_height } )
118 = "CropLeft [" ++ show left_skip ++ "," ++ show output_width ++ "," ++ show output_height ++ "]"
119 ++ " (" ++ show cropped_image ++ ")"
120 show ( CropBottom { cropped_image, output_width, output_height } )
121 = "CropBottom [" ++ show output_width ++ "," ++ show output_height ++ "]"
122 ++ " (" ++ show cropped_image ++ ")"
123 show ( CropTop { cropped_image, top_skip, output_width, output_height } )
124 = "CropTop [" ++ show top_skip ++ "," ++ show output_width ++ "," ++ show output_height ++ "]"
125 ++ " (" ++ show cropped_image ++ ")"
126 show ( EmptyImage ) = "EmptyImage"
128instance NFData Image where
130 rnf (CropRight i w h) = i `deepseq` w `seq` h `seq` ()
131 rnf (CropLeft i s w h) = i `deepseq` s `seq` w `seq` h `seq` ()
132 rnf (CropBottom i w h) = i `deepseq` w `seq` h `seq` ()
133 rnf (CropTop i s w h) = i `deepseq` s `seq` w `seq` h `seq` ()
134 rnf (BGFill w h) = w `seq` h `seq` ()
135 rnf (VertJoin t b w h) = t `deepseq` b `deepseq` w `seq` h `seq` ()
136 rnf (HorizJoin l r w h) = l `deepseq` r `deepseq` w `seq` h `seq` ()
137 rnf (HorizText a s w cw) = a `seq` s `deepseq` w `seq` cw `seq` ()
139-- | The width of an Image. This is the number display columns the image will occupy.
140image_width :: Image -> Int
141image_width HorizText { output_width = w } = w
142image_width HorizJoin { output_width = w } = w
143image_width VertJoin { output_width = w } = w
144image_width BGFill { output_width = w } = w
145image_width CropRight { output_width = w } = w
146image_width CropLeft { output_width = w } = w
147image_width CropBottom { output_width = w } = w
148image_width CropTop { output_width = w } = w
149image_width EmptyImage = 0
151-- | The height of an Image. This is the number of display rows the image will occupy.
152image_height :: Image -> Int
153image_height HorizText {} = 1
154image_height HorizJoin { output_height = h } = h
155image_height VertJoin { output_height = h } = h
156image_height BGFill { output_height = h } = h
157image_height CropRight { output_height = h } = h
158image_height CropLeft { output_height = h } = h
159image_height CropBottom { output_height = h } = h
160image_height CropTop { output_height = h } = h
161image_height EmptyImage = 0
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list