on dc8be4e help sign in
vty/src/Graphics/Vty/Picture.hs
94 lines 3.5 kB history raw
1{-# LANGUAGE BangPatterns #-}
2-- | The Picture data structure is representative of the final terminal view.
3--
4-- This module re-exports most of the Graphics.Vty.Image and Graphics.Vty.Attributes modules.
5--
6-- Copyright 2009-2010 Corey O'Connor
7module Graphics.Vty.Picture ( module Graphics.Vty.Picture
8 , Image
9 , image_width
10 , image_height
11 , (<|>)
12 , (<->)
13 , horiz_cat
14 , vert_cat
15 , background_fill
16 , char
17 , string
18 , iso_10646_string
19 , utf8_string
20 , utf8_bytestring
21 , char_fill
22 , empty_image
23 , translate
24 , crop
25 , pad
26 -- | The possible display attributes used in constructing an `Image`.
27 , module Graphics.Vty.Attributes
28 )
29 where
31import Graphics.Vty.Attributes
32import Graphics.Vty.Image
34import Control.DeepSeq
36-- | The type of images to be displayed using 'update'.
37-- Can be constructed directly or using `pic_for_image`. Which provides an initial instance with
38-- reasonable defaults for pic_cursor and pic_background.
39data Picture = Picture
40 { pic_cursor :: Cursor
41 , pic_image :: Image
42 , pic_background :: Background
43 }
45instance Show Picture where
46 show (Picture _ image _ ) = "Picture ?? " ++ show image ++ " ??"
48instance NFData Picture where
49 rnf (Picture c i b) = c `deepseq` i `deepseq` b `deepseq` ()
51-- | Create a picture for display for the given image. The picture will not have a displayed cursor
52-- and the background display attribute will be `current_attr`.
53pic_for_image :: Image -> Picture
54pic_for_image i = Picture
55 { pic_cursor = NoCursor
56 , pic_image = i
57 , pic_background = Background ' ' current_attr
58 }
60-- | A picture can be configured either to not show the cursor or show the cursor at the specified
61-- character position.
62--
63-- There is not a 1 to 1 map from character positions to a row and column on the screen due to
64-- characters that take more than 1 column.
65--
66-- todo: The Cursor can be given a (character,row) offset outside of the visible bounds of the
67-- output region. In this case the cursor will not be shown.
68data Cursor =
69 NoCursor
70 | Cursor Int Int
72instance NFData Cursor where
73 rnf NoCursor = ()
74 rnf (Cursor w h) = w `seq` h `seq` ()
76-- | Unspecified regions are filled with the picture's background pattern. The background pattern
77-- can specify a character and a display attribute. If the display attribute used previously should
78-- be used for a background fill then use `current_attr` for the background attribute. This is the
79-- default background display attribute.
80--
81-- \todo The current attribute is always set to the default attributes at the start of updating the
82-- screen to a picture.
83--
84-- \todo The background character *must* occupy a single column and no more.
85--
86-- \todo background char should be optional
87data Background = Background
88 { background_char :: Char
89 , background_attr :: Attr
90 }
92instance NFData Background where
93 rnf (Background c a) = c `seq` a `seq` ()