on ffe6de2 help sign in
vty/src/Graphics/Vty/Picture.hs
93 lines 3.3 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 , module Graphics.Vty.Image
9 )
10 where
12import Graphics.Vty.Image
14import Control.DeepSeq
16-- | The type of images to be displayed using 'update'.
17-- Can be constructed directly or using `pic_for_image`. Which provides an initial instance with
18-- reasonable defaults for pic_cursor and pic_background.
19data Picture = Picture
20 { pic_cursor :: Cursor
21 , pic_layers :: [Image]
22 , pic_background :: Background
23 }
25instance Show Picture where
26 show (Picture _ layers _ ) = "Picture ?? " ++ show layers ++ " ??"
28instance NFData Picture where
29 rnf (Picture c l b) = c `deepseq` l `deepseq` b `deepseq` ()
31-- | Create a picture for display for the given image. The picture will not have a displayed cursor
32-- and the background display attribute will be `current_attr`.
33pic_for_image :: Image -> Picture
34pic_for_image i = Picture
35 { pic_cursor = NoCursor
36 , pic_layers = [i]
37 , pic_background = ClearBackground
38 }
40-- | Create a picture for display with the given layers. Ordered top to bottom.
41--
42-- The first image is the top layer.
43pic_for_layers :: [Image] -> Picture
44pic_for_layers is = Picture
45 { pic_cursor = NoCursor
46 , pic_layers = is
47 , pic_background = ClearBackground
48 }
50-- | A picture can be configured either to not show the cursor or show the cursor at the specified
51-- character position.
52--
53-- There is not a 1 to 1 map from character positions to a row and column on the screen due to
54-- characters that take more than 1 column.
55--
56-- todo: The Cursor can be given a (character,row) offset outside of the visible bounds of the
57-- output region. In this case the cursor will not be shown.
58data Cursor =
59 NoCursor
60 | Cursor Int Int
62instance NFData Cursor where
63 rnf NoCursor = ()
64 rnf (Cursor w h) = w `seq` h `seq` ()
66-- | Unspecified regions are filled with the picture's background pattern. The background pattern
67-- can specify a character and a display attribute. If the display attribute used previously should
68-- be used for a background fill then use `current_attr` for the background attribute. This is the
69-- default background display attribute.
70--
71-- \todo The current attribute is always set to the default attributes at the start of updating the
72-- screen to a picture.
73data Background
74 = Background
75 { background_char :: Char
76 , background_attr :: Attr
77 }
78 -- | The background is:
79 --
80 -- * the space character if there are remaining non-skip ops
81 -- * (?) nothing if there are no remaining non-skip ops.
82 --
83 -- Might require the terminal interface to do a line clear?
84 -- Or should the nothing case be switched with crlf?
85 | ClearBackground
87instance NFData Background where
88 rnf (Background c a) = c `seq` a `seq` ()
89 rnf ClearBackground = ()
91-- | Compatibility with applications that do not use more than a single layer.
92pic_image :: Picture -> Image
93pic_image = head . pic_layers