on master help sign in
adjust for compile failures
81c65e2Corey O'Connor
src/Graphics/Vty/Image.hs+6
@@ -46,6 +46,7 @@ import Graphics.Text.Width
46
46
47import qualified Data.ByteString as B
47import qualified Data.ByteString as B
48import qualified Data.ByteString.Lazy as BL
48import qualified Data.ByteString.Lazy as BL
49+import Data.Monoid
49import qualified Data.Text as T
50import qualified Data.Text as T
50import qualified Data.Text.Encoding as T
51import qualified Data.Text.Encoding as T
51import qualified Data.Text.Lazy as TL
52import qualified Data.Text.Lazy as TL
@@ -55,6 +56,11 @@ import Data.Word
55infixr 5 <|>
56infixr 5 <|>
56infixr 4 <->
57infixr 4 <->
57
58
59+-- | Currently append in the Monoid instance is equivalent to <->.
60+instance Monoid Image where
61+ mempty = EmptyImage
62+ mappend = (<->)
63+
58-- | combines two images side by side
64-- | combines two images side by side
59--
65--
60-- Combines text chunks where possible. Assures output_width and output_height properties are not
66-- Combines text chunks where possible. Assures output_width and output_height properties are not
src/Graphics/Vty/Picture.hs+3−3
@@ -29,7 +29,7 @@ module Graphics.Vty.Picture ( module Graphics.Vty.Picture
29 where
29 where
30
30
31import Graphics.Vty.Attributes
31import Graphics.Vty.Attributes
32−import Graphics.Vty.Image hiding ( attr )
32+import Graphics.Vty.Image
33
33
34import Control.DeepSeq
34import Control.DeepSeq
35import Data.Word
35import Data.Word
@@ -72,7 +72,7 @@ data Cursor =
72
72
73instance NFData Cursor where
73instance NFData Cursor where
74 rnf NoCursor = ()
74 rnf NoCursor = ()
75− rnf (Cursor !w !h) = ()
75+ rnf (Cursor w h) = w `seq` h `seq` ()
76
76
77-- | Unspecified regions are filled with the picture's background pattern. The background pattern
77-- | Unspecified regions are filled with the picture's background pattern. The background pattern
78-- can specify a character and a display attribute. If the display attribute used previously should
78-- can specify a character and a display attribute. If the display attribute used previously should
@@ -91,5 +91,5 @@ data Background = Background
91 }
91 }
92
92
93instance NFData Background where
93instance NFData Background where
94− rnf (Background !c !a) = ()
94+ rnf (Background c a) = c `seq` a `seq` ()
95
95
src/Graphics/Vty/Span.hs+59−64
@@ -5,7 +5,17 @@
5{-# LANGUAGE NamedFieldPuns #-}
5{-# LANGUAGE NamedFieldPuns #-}
6{-# LANGUAGE GADTs #-}
6{-# LANGUAGE GADTs #-}
7{-# LANGUAGE ScopedTypeVariables #-}
7{-# LANGUAGE ScopedTypeVariables #-}
8−-- The ops to define the content for an output region.
8+{- | A picture is translated into a sequences of state changes and character spans.
9+ - State changes are currently limited to new attribute values. The attribute is applied to all
10+ - following spans. Including spans of the next row. The nth element of the sequence represents the
11+ - nth row (from top to bottom) of the picture to render.
12+ -
13+ - A span op sequence will be defined for all rows and columns (and no more) of the region provided
14+ - with the picture to spans_for_pic.
15+ -
16+ - todo: Partition attribute changes into multiple categories according to the serialized
17+ - representation of the various attributes.
18+ -}
9module Graphics.Vty.Span
19module Graphics.Vty.Span
10 where
20 where
11
21
@@ -32,26 +42,31 @@ import qualified Data.ByteString.Lazy as BL
32import qualified Data.ByteString.Lazy.Internal as BLInt
42import qualified Data.ByteString.Lazy.Internal as BLInt
33import qualified Data.Foldable as Foldable
43import qualified Data.Foldable as Foldable
34import qualified Data.Text.Lazy as TL
44import qualified Data.Text.Lazy as TL
45+import qualified Data.Text.Lazy.Encoding as TL
35import Data.Word
46import Data.Word
36
47
37import Foreign.Storable ( pokeByteOff )
48import Foreign.Storable ( pokeByteOff )
38
49
39−-- | Currently append in the Monoid instance is equivalent to <->.
50+-- | This represents an operation on the terminal. Either an attribute change or the output of a
40−instance Monoid Image where
51+-- text string.
41− mempty = EmptyImage
52+--
42− mappend = (<->)
53+-- todo: This type may need to be restructured to increase sharing in the bytestring
54+--
55+-- todo: Make foldable
56+data SpanOp =
57+ AttributeChange !Attr
58+ -- | a span of UTF-8 text occupies a specific number of screen space columns. A single UTF
59+ -- character does not necessarially represent 1 colunm. See Codec.Binary.UTF8.Width
60+ -- TextSpan [output width in columns] [number of characters] [data]
61+ | TextSpan !Int !Int BL.ByteString
62+ deriving Eq
63+
64+-- | vector of span operations. executed in succession. This represents the operations required to
65+-- render a row of the terminal. The operations in one row may effect subsequent rows.
66+-- EG: Setting the foreground color in one row will effect all subsequent rows until the foreground
67+-- color is changed.
68+type SpanOps = Vector SpanOp
43
69
44−{- | A picture is translated into a sequences of state changes and character spans.
45− - State changes are currently limited to new attribute values. The attribute is applied to all
46− - following spans. Including spans of the next row. The nth element of the sequence represents the
47− - nth row (from top to bottom) of the picture to render.
48− -
49− - A span op sequence will be defined for all rows and columns (and no more) of the region provided
50− - with the picture to spans_for_pic.
51− -
52− - todo: Partition attribute changes into multiple categories according to the serialized
53− - representation of the various attributes.
54− -}
55
70
56data DisplayOps = DisplayOps
71data DisplayOps = DisplayOps
57 { effected_region :: DisplayRegion
72 { effected_region :: DisplayRegion
@@ -63,12 +78,6 @@ type RowOps = Vector SpanOps
63
78
64type MRowOps s = MVector s SpanOps
79type MRowOps s = MVector s SpanOps
65
80
66−-- | vector of span operations. executed in succession. This represents the operations required to
67−-- render a row of the terminal. The operations in one row may effect subsequent rows.
68−-- EG: Setting the foreground color in one row will effect all subsequent rows until the foreground
69−-- color is changed.
70−type SpanOps = Vector SpanOp
71−
72type MSpanOps s = MVector s SpanOp
81type MSpanOps s = MVector s SpanOp
73
82
74instance Show DisplayOps where
83instance Show DisplayOps where
@@ -79,6 +88,34 @@ instance Show SpanOp where
79 show (AttributeChange attr) = show attr
88 show (AttributeChange attr) = show attr
80 show (TextSpan ow cw _) = "TextSpan " ++ show ow ++ " " ++ show cw
89 show (TextSpan ow cw _) = "TextSpan " ++ show ow ++ " " ++ show cw
81
90
91+-- transform plus clip. More or less.
92+data BlitState = BlitState
93+ -- we always snoc to the operation vectors. Thus the column_offset = length of row at row_offset
94+ { _row_offset :: Int
95+ -- clip coordinate space is in image space. Which means it's >= 0 and < image_width.
96+ , _skip_columns :: Int
97+ -- >= 0 and < image_height
98+ , _skip_rows :: Int
99+ -- includes consideration of skip_columns. In display space.
100+ -- The number of columns from the next column to be defined to the end of the display for the
101+ -- row.
102+ , _remaining_columns :: Int
103+ -- includes consideration of skip_rows. In display space.
104+ , _remaining_rows :: Int
105+ }
106+
107+makeLenses ''BlitState
108+
109+data BlitEnv s = BlitEnv
110+ { _bg :: Background
111+ , _region :: DisplayRegion
112+ , _mrow_ops :: MRowOps s
113+ }
114+
115+makeLenses ''BlitEnv
116+
117+type BlitM s a = ReaderT (BlitEnv s) (StateT BlitState (ST s)) a
118+
82-- | Number of columns the DisplayOps are defined for
119-- | Number of columns the DisplayOps are defined for
83span_ops_columns :: DisplayOps -> Word
120span_ops_columns :: DisplayOps -> Word
84span_ops_columns ops = region_width $ effected_region ops
121span_ops_columns ops = region_width $ effected_region ops
@@ -94,20 +131,6 @@ span_ops_effected_columns in_ops = Vector.foldl' span_ops_effected_columns' 0 in
94 span_ops_effected_columns' t (TextSpan w _ _ ) = t + w
131 span_ops_effected_columns' t (TextSpan w _ _ ) = t + w
95 span_ops_effected_columns' t _ = t
132 span_ops_effected_columns' t _ = t
96
133
97−-- | This represents an operation on the terminal. Either an attribute change or the output of a
98−-- text string.
99−--
100−-- todo: This type may need to be restructured to increase sharing in the bytestring
101−--
102−-- todo: Make foldable
103−data SpanOp =
104− AttributeChange !Attr
105− -- | a span of UTF-8 text occupies a specific number of screen space columns. A single UTF
106− -- character does not necessarially represent 1 colunm. See Codec.Binary.UTF8.Width
107− -- TextSpan [output width in columns] [number of characters] [data]
108− | TextSpan !Int !Int BL.ByteString
109− deriving Eq
110−
111-- | The width of a single SpanOp in columns
134-- | The width of a single SpanOp in columns
112span_op_has_width :: SpanOp -> Maybe (Int, Int)
135span_op_has_width :: SpanOp -> Maybe (Int, Int)
113span_op_has_width (TextSpan ow cw _) = Just (cw, ow)
136span_op_has_width (TextSpan ow cw _) = Just (cw, ow)
@@ -125,34 +148,6 @@ columns_to_char_offset _cx _ = error "columns_to_char_offset applied to span op
125spans_for_pic :: Picture -> DisplayRegion -> DisplayOps
148spans_for_pic :: Picture -> DisplayRegion -> DisplayOps
126spans_for_pic pic r = DisplayOps r $ Vector.create (build_spans pic r)
149spans_for_pic pic r = DisplayOps r $ Vector.create (build_spans pic r)
127
150
128−-- transform plus clip. More or less.
129−newtype BlitState = BlitState
130− -- we always snoc to the operation vectors. Thus the column_offset = length of row at row_offset
131− { _row_offset :: Int
132− -- clip coordinate space is in image space. Which means it's >= 0 and < image_width.
133− , _skip_columns :: Int
134− -- >= 0 and < image_height
135− , _skip_rows :: Int
136− -- includes consideration of skip_columns. In display space.
137− -- The number of columns from the next column to be defined to the end of the display for the
138− -- row.
139− , _remaining_columns :: Int
140− -- includes consideration of skip_rows. In display space.
141− , _remaining_rows :: Int
142− }
143−
144−makeLenses ''BlitState
145−
146−newtype BlitEnv s = BlitEnv
147− { _bg :: Background
148− , _region :: DisplayRegion
149− , _mrow_ops :: MRowOps s
150− }
151−
152−makeLenses ''BlitEnv
153−
154−type BlitM s a = ReaderT (BlitEnv s) (StateT BlitState (ST s)) a
155−
156-- | Builds a vector of row operations that will output the given picture to the terminal.
151-- | Builds a vector of row operations that will output the given picture to the terminal.
157--
152--
158-- Crops to the given display region.
153-- Crops to the given display region.
test/Makefile+3−2
@@ -4,11 +4,11 @@ verify_display_attributes \
4verify_parse_terminfo_caps \
4verify_parse_terminfo_caps \
5verify_eval_terminfo_caps \
5verify_eval_terminfo_caps \
6verify_utf8_width \
6verify_utf8_width \
7−verify_image_ops \
7+VerifyImageOps \
8verify_image_trans \
8verify_image_trans \
9verify_empty_image_props \
9verify_empty_image_props \
10verify_picture_ops \
10verify_picture_ops \
11−verify_span_ops \
11+VerifySpanOps \
12verify_debug_terminal \
12verify_debug_terminal \
13verify_inline \
13verify_inline \
14
14
@@ -28,6 +28,7 @@ GHC_ARGS=--make -i../src \
28 -package parallel \
28 -package parallel \
29 -package deepseq-1.3.0.1 \
29 -package deepseq-1.3.0.1 \
30 -hide-package transformers \
30 -hide-package transformers \
31+ -hide-package monads-tf \
31 -package QuickCheck \
32 -package QuickCheck \
32 -ignore-package vty \
33 -ignore-package vty \
33 ../cbits/gwinsz.c ../cbits/set_term_timing.c ../cbits/mk_wcwidth.c \
34 ../cbits/gwinsz.c ../cbits/set_term_timing.c ../cbits/mk_wcwidth.c \