on master help sign in
cleanup and updates to get the test suite to compile
commitf3108faed908d9b53a6682a6b6811b8dd9d47b36 authorCorey O'Connor <corey@ooyala.com> dateSat 1 Jun 2013, 06:47 (13 years ago) parentcd6747c
9 files changed+46−49
src/Graphics/Vty/DisplayRegion.hs−2 src/Graphics/Vty/Picture.hs−1 src/Graphics/Vty/Span.hs+13−23 src/Graphics/Vty/Terminal/Debug.hs+3 test/Verify/Graphics/Vty/DisplayRegion.hs+1−3 test/Verify/Graphics/Vty/Image.hs+3−5 test/VerifyImageOps.hs+3−4 test/VerifyImageTrans.hs+3−1 vty.cabal+20−10
src/Graphics/Vty/DisplayRegion.hs−2
@@ -2,8 +2,6 @@
22module Graphics.Vty.DisplayRegion
33 where
44
5−import Data.Word
6−
75-- | Region of the terminal that vty will output to. Units are columns not characters.
86data DisplayRegion = DisplayRegion
97 { region_width :: !Int
src/Graphics/Vty/Picture.hs−1
@@ -32,7 +32,6 @@ import Graphics.Vty.Attributes
3232import Graphics.Vty.Image
3333
3434import Control.DeepSeq
35−import Data.Word
3635
3736-- | The type of images to be displayed using 'update'.
3837-- Can be constructed directly or using `pic_for_image`. Which provides an initial instance with
src/Graphics/Vty/Span.hs+13−23
@@ -24,33 +24,22 @@ import Graphics.Vty.Image
2424import Graphics.Vty.Image.Internal
2525import Graphics.Vty.Picture
2626import Graphics.Vty.DisplayRegion
27−import Graphics.Text.Width
2827
2928import Control.Applicative
30−import Control.Lens
31−import Control.Monad ( forM_ )
29+import Control.Lens hiding ( op )
3230import Control.Monad.Reader
33−import Control.Monad.State.Strict
31+import Control.Monad.State.Strict hiding ( state )
3432import Control.Monad.ST.Strict hiding ( unsafeIOToST )
35−import Control.Monad.ST.Unsafe ( unsafeIOToST )
3633
37−import Data.Monoid
3834import Data.Vector (Vector)
3935import qualified Data.Vector as Vector hiding ( take, replicate )
4036import Data.Vector.Mutable ( MVector(..))
4137import qualified Data.Vector.Mutable as Vector
4238
4339import qualified Data.ByteString as BS
44−import qualified Data.ByteString.Lazy as BL
45−import qualified Data.ByteString.Lazy.Internal as BL
46−import qualified Data.Foldable as Foldable
4740import qualified Data.Text as T
4841import qualified Data.Text.Encoding as T
4942import qualified Data.Text.Lazy as TL
50−import qualified Data.Text.Lazy.Encoding as TL
51−import Data.Word
52−
53−import Foreign.Storable ( pokeByteOff )
5443
5544-- | This represents an operation on the terminal. Either an attribute change or the output of a
5645-- text string.
@@ -157,9 +146,9 @@ spans_for_pic pic r = DisplayOps r $ Vector.create (build_spans pic r)
157146--
158147-- Crops to the given display region.
159148build_spans :: Picture -> DisplayRegion -> ST s (MRowOps s)
160−build_spans pic region = do
149+build_spans pic out_region = do
161150 -- First we create a mutable vector for each rows output operations.
162− mrow_ops <- Vector.replicate (region_height region) Vector.empty
151+ out_ops <- Vector.replicate (region_height out_region) Vector.empty
163152 -- \todo I think building the span operations in display order would provide better performance.
164153 -- However, I got stuck trying to implement an algorithm that did this. This will be considered
165154 -- as a possible future optimization.
@@ -171,29 +160,29 @@ build_spans pic region = do
171160 --
172161 -- The images are made into span operations from left to right. It's possible that this could
173162 -- easily be made to assure top to bottom output as well.
174− when (region_height region > 0 && region_width region > 0) $ do
163+ when (region_height out_region > 0 && region_width out_region > 0) $ do
175164 -- The ops builder recursively descends the image and outputs span ops that would
176165 -- display that image. The number of columns remaining in this row before exceeding the
177166 -- bounds is also provided. This is used to clip the span ops produced to the display.
178167 let full_build = do
179168 start_image_build $ pic_image pic
180169 -- Fill in any unspecified columns with the background pattern.
181− forM_ [0 .. (region_height region - 1)] add_row_completion
182− init_env = BlitEnv (pic_background pic) region mrow_ops
183− init_state = BlitState 0 0 0 0 (region_width region) (region_height region)
170+ forM_ [0 .. (region_height out_region - 1)] add_row_completion
171+ init_env = BlitEnv (pic_background pic) out_region out_ops
172+ init_state = BlitState 0 0 0 0 (region_width out_region) (region_height out_region)
184173 _ <- runStateT (runReaderT full_build init_env) init_state
185174 return ()
186− return mrow_ops
175+ return out_ops
187176
188177-- | Add the operations required to build a given image to the current set of row operations
189178-- returns the number of columns and rows contributed to the output.
190179start_image_build :: Image -> BlitM s ()
191180start_image_build image = do
192− out_of_bounds <- is_out_of_bounds image <$> get
181+ out_of_bounds <- is_out_of_bounds <$> get
193182 when (not out_of_bounds) $ add_maybe_clipped image
194183
195−is_out_of_bounds :: Image -> BlitState -> Bool
196−is_out_of_bounds image s
184+is_out_of_bounds :: BlitState -> Bool
185+is_out_of_bounds s
197186 | s ^. remaining_columns <= 0 = True
198187 | s ^. remaining_rows <= 0 = True
199188 | otherwise = False
@@ -334,6 +323,7 @@ clip_text txt left_skip right_clip =
334323 | w == cw = (n+1, False)
335324 | w > cw = clip_for_char_width (w - cw) (TL.tail t) (n + 1)
336325 where cw = safe_wcwidth (TL.head t)
326+ clip_for_char_width _ _ _ = error "clip_for_char_width applied to undefined"
337327 in txt''
338328
339329add_unclipped_text :: DisplayText -> BlitM s ()
src/Graphics/Vty/Terminal/Debug.hs+3
@@ -82,6 +82,9 @@ instance DisplayTerminal DebugDisplay where
8282 -- | Provide the current bounds of the output terminal.
8383 context_region d = debug_display_bounds d
8484
85+ -- | Assume 16 colors
86+ context_color_count d = 16
87+
8588 -- | A cursor move is always visualized as the single character 'M'
8689 move_cursor_required_bytes _d _x _y = 1
8790
test/Verify/Graphics/Vty/DisplayRegion.hs+1−3
@@ -10,12 +10,10 @@ import Graphics.Vty.DisplayRegion
1010
1111import Verify
1212
13−import Data.Word
14−
1513data EmptyWindow = EmptyWindow DebugWindow
1614
1715instance Arbitrary EmptyWindow where
18− arbitrary = return $ EmptyWindow (DebugWindow (0 :: Word) (0 :: Word))
16+ arbitrary = return $ EmptyWindow (DebugWindow (0 :: Int) (0 :: Int))
1917
2018instance Show EmptyWindow where
2119 show (EmptyWindow _) = "EmptyWindow"
test/Verify/Graphics/Vty/Image.hs+3−5
@@ -11,8 +11,6 @@ import Graphics.Vty.Image
1111
1212import Verify
1313
14−import Data.Word
15−
1614data UnitImage = UnitImage Char Image
1715
1816instance Arbitrary UnitImage where
@@ -38,7 +36,7 @@ instance Arbitrary DefaultImage where
3836data SingleRowSingleAttrImage
3937 = SingleRowSingleAttrImage
4038 { expected_attr :: Attr
41− , expected_columns :: Word
39+ , expected_columns :: Int
4240 , row_image :: Image
4341 }
4442
@@ -74,8 +72,8 @@ instance Arbitrary SingleRowTwoAttrImage where
7472data SingleAttrSingleSpanStack = SingleAttrSingleSpanStack
7573 { stack_image :: Image
7674 , stack_source_images :: [SingleRowSingleAttrImage]
77− , stack_width :: Word
78− , stack_height :: Word
75+ , stack_width :: Int
76+ , stack_height :: Int
7977 }
8078 deriving Show
8179
test/VerifyImageOps.hs+3−4
@@ -2,12 +2,11 @@
22module VerifyImageOps where
33
44import Graphics.Vty.Attributes
5+import Graphics.Vty.Image.Internal
56import Verify.Graphics.Vty.Image
67
78import Verify
89
9−import Data.Word
10−
1110two_sw_horiz_concat :: SingleColumnChar -> SingleColumnChar -> Bool
1211two_sw_horiz_concat (SingleColumnChar c1) (SingleColumnChar c2) =
1312 image_width (char def_attr c1 <|> char def_attr c2) == 2
@@ -50,7 +49,7 @@ horiz_concat_dw_assoc (DoubleColumnChar c0) (DoubleColumnChar c1) (DoubleColumnC
5049
5150vert_contat_single_row :: NonEmptyList SingleRowSingleAttrImage -> Bool
5251vert_contat_single_row (NonEmpty stack) =
53− let expected_height :: Word = fromIntegral $ length stack
52+ let expected_height :: Int = length stack
5453 stack_image = vert_cat [ i | SingleRowSingleAttrImage { row_image = i } <- stack ]
5554 in image_height stack_image == expected_height
5655
@@ -58,7 +57,7 @@ disjoint_height_horiz_join :: NonEmptyList SingleRowSingleAttrImage
5857 -> NonEmptyList SingleRowSingleAttrImage
5958 -> Bool
6059disjoint_height_horiz_join (NonEmpty stack_0) (NonEmpty stack_1) =
61− let expected_height :: Word = fromIntegral $ max (length stack_0) (length stack_1)
60+ let expected_height :: Int = max (length stack_0) (length stack_1)
6261 stack_image_0 = vert_cat [ i | SingleRowSingleAttrImage { row_image = i } <- stack_0 ]
6362 stack_image_1 = vert_cat [ i | SingleRowSingleAttrImage { row_image = i } <- stack_1 ]
6463 in image_height (stack_image_0 <|> stack_image_1) == expected_height
test/VerifyImageTrans.hs+3−1
@@ -3,11 +3,13 @@ module VerifyImageTrans where
33
44import Verify.Graphics.Vty.Image
55
6+import Graphics.Vty.Image.Internal
7+
68import Verify
79
810import Data.Word
911
10−is_horiz_text_of_columns :: Image -> Word -> Bool
12+is_horiz_text_of_columns :: Image -> Int -> Bool
1113is_horiz_text_of_columns (HorizText { output_width = in_w }) expected_w = in_w == expected_w
1214is_horiz_text_of_columns (BGFill { output_width = in_w }) expected_w = in_w == expected_w
1315is_horiz_text_of_columns _image _expected_w = False
vty.cabal+20−10
@@ -62,12 +62,13 @@ library
6262 Graphics.Vty.LLInput
6363 Graphics.Vty.Picture
6464 Graphics.Vty.Terminal
65− Codec.Binary.UTF8.Width
65+ Graphics.Text.Width
6666
6767 other-modules: Data.Marshalling
6868 Data.Terminfo.Parse
6969 Data.Terminfo.Eval
7070 Graphics.Vty.DisplayAttributes
71+ Graphics.Vty.Image.Internal
7172 Graphics.Vty.Span
7273 Graphics.Vty.Terminal.Generic
7374 Graphics.Vty.Terminal.MacOSX
@@ -125,6 +126,7 @@ test-suite verify-using-mock-terminal
125126 Graphics.Vty.DisplayAttributes
126127 Graphics.Vty.DisplayRegion
127128 Graphics.Vty.Image
129+ Graphics.Vty.Image.Internal
128130 Graphics.Vty.Picture
129131 Graphics.Vty.Span
130132 Graphics.Vty.Terminal
@@ -132,7 +134,7 @@ test-suite verify-using-mock-terminal
132134 Graphics.Vty.Terminal.Debug
133135 Graphics.Vty.Debug
134136 Graphics.Vty.Debug.Image
135− Codec.Binary.UTF8.Width
137+ Graphics.Text.Width
136138 Verify
137139 Verify.Graphics.Vty.Attributes
138140 Verify.Graphics.Vty.DisplayRegion
@@ -178,6 +180,7 @@ test-suite verify-display-attributes
178180 Graphics.Vty.DisplayAttributes
179181 Graphics.Vty.DisplayRegion
180182 Graphics.Vty.Image
183+ Graphics.Vty.Image.Internal
181184 Graphics.Vty.Picture
182185 Graphics.Vty.Span
183186 Graphics.Vty.Terminal
@@ -185,7 +188,7 @@ test-suite verify-display-attributes
185188 Graphics.Vty.Terminal.Debug
186189 Graphics.Vty.Debug
187190 Graphics.Vty.Debug.Image
188− Codec.Binary.UTF8.Width
191+ Graphics.Text.Width
189192 Verify
190193 Verify.Graphics.Vty.Attributes
191194 Verify.Graphics.Vty.DisplayRegion
@@ -259,7 +262,7 @@ test-suite verify-eval-terminfo-caps
259262 other-modules: Data.Terminfo.Parse
260263 Data.Terminfo.Eval
261264 Data.Marshalling
262− Codec.Binary.UTF8.Width
265+ Graphics.Text.Width
263266 Verify
264267
265268 build-depends: Cabal == 1.17.*,
@@ -293,10 +296,11 @@ test-suite verify-image-ops
293296 Graphics.Vty.DisplayAttributes
294297 Graphics.Vty.DisplayRegion
295298 Graphics.Vty.Image
299+ Graphics.Vty.Image.Internal
296300 Graphics.Vty.Picture
297301 Graphics.Vty.Span
298302 Graphics.Vty.Debug.Image
299− Codec.Binary.UTF8.Width
303+ Graphics.Text.Width
300304 Verify
301305 Verify.Graphics.Vty.Attributes
302306 Verify.Graphics.Vty.Image
@@ -337,7 +341,8 @@ test-suite verify-image-trans
337341 other-modules: Graphics.Vty.Attributes
338342 Graphics.Vty.Debug.Image
339343 Graphics.Vty.Image
340− Codec.Binary.UTF8.Width
344+ Graphics.Vty.Image.Internal
345+ Graphics.Text.Width
341346 Verify
342347 Verify.Graphics.Vty.Attributes
343348 Verify.Graphics.Vty.Image
@@ -373,7 +378,7 @@ test-suite verify-inline
373378
374379 test-module: VerifyInline
375380
376− other-modules: Codec.Binary.UTF8.Width
381+ other-modules: Graphics.Text.Width
377382 Data.Terminfo.Eval
378383 Data.Terminfo.Parse
379384 Data.Marshalling
@@ -381,7 +386,9 @@ test-suite verify-inline
381386 Graphics.Vty.DisplayAttributes
382387 Graphics.Vty.DisplayRegion
383388 Graphics.Vty.Image
389+ Graphics.Vty.Image.Internal
384390 Graphics.Vty.Inline
391+ Graphics.Vty.Picture
385392 Graphics.Vty.Span
386393 Graphics.Vty.Terminal
387394 Graphics.Vty.Terminal.Generic
@@ -492,6 +499,7 @@ test-suite verify-picture-to-span
492499 Graphics.Vty.DisplayAttributes
493500 Graphics.Vty.DisplayRegion
494501 Graphics.Vty.Image
502+ Graphics.Vty.Image.Internal
495503 Graphics.Vty.Picture
496504 Graphics.Vty.Span
497505 Graphics.Vty.Terminal
@@ -499,7 +507,7 @@ test-suite verify-picture-to-span
499507 Graphics.Vty.Terminal.Debug
500508 Graphics.Vty.Debug
501509 Graphics.Vty.Debug.Image
502− Codec.Binary.UTF8.Width
510+ Graphics.Text.Width
503511 Verify
504512 Verify.Graphics.Vty.Attributes
505513 Verify.Graphics.Vty.DisplayRegion
@@ -545,6 +553,7 @@ test-suite verify-span-ops
545553 Graphics.Vty.DisplayAttributes
546554 Graphics.Vty.DisplayRegion
547555 Graphics.Vty.Image
556+ Graphics.Vty.Image.Internal
548557 Graphics.Vty.Picture
549558 Graphics.Vty.Span
550559 Graphics.Vty.Terminal
@@ -552,7 +561,7 @@ test-suite verify-span-ops
552561 Graphics.Vty.Terminal.Debug
553562 Graphics.Vty.Debug
554563 Graphics.Vty.Debug.Image
555− Codec.Binary.UTF8.Width
564+ Graphics.Text.Width
556565 Verify
557566 Verify.Graphics.Vty.Attributes
558567 Verify.Graphics.Vty.DisplayRegion
@@ -593,9 +602,10 @@ test-suite verify-utf8-width
593602
594603 test-module: VerifyUtf8Width
595604
596− other-modules: Codec.Binary.UTF8.Width
605+ other-modules: Graphics.Text.Width
597606 Graphics.Vty.Attributes
598607 Graphics.Vty.Image
608+ Graphics.Vty.Image.Internal
599609 Verify
600610
601611 c-sources: cbits/mk_wcwidth.c