on master help sign in
cleanup and updates to get the test suite to compile
f3108faCorey O'Connor
src/Graphics/Vty/DisplayRegion.hs−2
@@ -2,8 +2,6 @@
2module Graphics.Vty.DisplayRegion
2module Graphics.Vty.DisplayRegion
3 where
3 where
4
4
5−import Data.Word
6−
7-- | Region of the terminal that vty will output to. Units are columns not characters.
5-- | Region of the terminal that vty will output to. Units are columns not characters.
8data DisplayRegion = DisplayRegion
6data DisplayRegion = DisplayRegion
9 { region_width :: !Int
7 { region_width :: !Int
src/Graphics/Vty/Picture.hs−1
@@ -32,7 +32,6 @@ import Graphics.Vty.Attributes
32import Graphics.Vty.Image
32import Graphics.Vty.Image
33
33
34import Control.DeepSeq
34import Control.DeepSeq
35−import Data.Word
36
35
37-- | The type of images to be displayed using 'update'.
36-- | The type of images to be displayed using 'update'.
38-- Can be constructed directly or using `pic_for_image`. Which provides an initial instance with
37-- 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
24import Graphics.Vty.Image.Internal
24import Graphics.Vty.Image.Internal
25import Graphics.Vty.Picture
25import Graphics.Vty.Picture
26import Graphics.Vty.DisplayRegion
26import Graphics.Vty.DisplayRegion
27−import Graphics.Text.Width
28
27
29import Control.Applicative
28import Control.Applicative
30−import Control.Lens
29+import Control.Lens hiding ( op )
31−import Control.Monad ( forM_ )
32import Control.Monad.Reader
30import Control.Monad.Reader
33−import Control.Monad.State.Strict
31+import Control.Monad.State.Strict hiding ( state )
34import Control.Monad.ST.Strict hiding ( unsafeIOToST )
32import Control.Monad.ST.Strict hiding ( unsafeIOToST )
35−import Control.Monad.ST.Unsafe ( unsafeIOToST )
36
33
37−import Data.Monoid
38import Data.Vector (Vector)
34import Data.Vector (Vector)
39import qualified Data.Vector as Vector hiding ( take, replicate )
35import qualified Data.Vector as Vector hiding ( take, replicate )
40import Data.Vector.Mutable ( MVector(..))
36import Data.Vector.Mutable ( MVector(..))
41import qualified Data.Vector.Mutable as Vector
37import qualified Data.Vector.Mutable as Vector
42
38
43import qualified Data.ByteString as BS
39import 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
47import qualified Data.Text as T
40import qualified Data.Text as T
48import qualified Data.Text.Encoding as T
41import qualified Data.Text.Encoding as T
49import qualified Data.Text.Lazy as TL
42import 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 )
54
43
55-- | This represents an operation on the terminal. Either an attribute change or the output of a
44-- | This represents an operation on the terminal. Either an attribute change or the output of a
56-- text string.
45-- text string.
@@ -157,9 +146,9 @@ spans_for_pic pic r = DisplayOps r $ Vector.create (build_spans pic r)
157--
146--
158-- Crops to the given display region.
147-- Crops to the given display region.
159build_spans :: Picture -> DisplayRegion -> ST s (MRowOps s)
148build_spans :: Picture -> DisplayRegion -> ST s (MRowOps s)
160−build_spans pic region = do
149+build_spans pic out_region = do
161 -- First we create a mutable vector for each rows output operations.
150 -- 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
163 -- \todo I think building the span operations in display order would provide better performance.
152 -- \todo I think building the span operations in display order would provide better performance.
164 -- However, I got stuck trying to implement an algorithm that did this. This will be considered
153 -- However, I got stuck trying to implement an algorithm that did this. This will be considered
165 -- as a possible future optimization.
154 -- as a possible future optimization.
@@ -171,29 +160,29 @@ build_spans pic region = do
171 --
160 --
172 -- The images are made into span operations from left to right. It's possible that this could
161 -- The images are made into span operations from left to right. It's possible that this could
173 -- easily be made to assure top to bottom output as well.
162 -- 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
175 -- The ops builder recursively descends the image and outputs span ops that would
164 -- The ops builder recursively descends the image and outputs span ops that would
176 -- display that image. The number of columns remaining in this row before exceeding the
165 -- display that image. The number of columns remaining in this row before exceeding the
177 -- bounds is also provided. This is used to clip the span ops produced to the display.
166 -- bounds is also provided. This is used to clip the span ops produced to the display.
178 let full_build = do
167 let full_build = do
179 start_image_build $ pic_image pic
168 start_image_build $ pic_image pic
180 -- Fill in any unspecified columns with the background pattern.
169 -- Fill in any unspecified columns with the background pattern.
181− forM_ [0 .. (region_height region - 1)] add_row_completion
170+ forM_ [0 .. (region_height out_region - 1)] add_row_completion
182− init_env = BlitEnv (pic_background pic) region mrow_ops
171+ init_env = BlitEnv (pic_background pic) out_region out_ops
183− init_state = BlitState 0 0 0 0 (region_width region) (region_height region)
172+ init_state = BlitState 0 0 0 0 (region_width out_region) (region_height out_region)
184 _ <- runStateT (runReaderT full_build init_env) init_state
173 _ <- runStateT (runReaderT full_build init_env) init_state
185 return ()
174 return ()
186− return mrow_ops
175+ return out_ops
187
176
188-- | Add the operations required to build a given image to the current set of row operations
177-- | Add the operations required to build a given image to the current set of row operations
189-- returns the number of columns and rows contributed to the output.
178-- returns the number of columns and rows contributed to the output.
190start_image_build :: Image -> BlitM s ()
179start_image_build :: Image -> BlitM s ()
191start_image_build image = do
180start_image_build image = do
192− out_of_bounds <- is_out_of_bounds image <$> get
181+ out_of_bounds <- is_out_of_bounds <$> get
193 when (not out_of_bounds) $ add_maybe_clipped image
182 when (not out_of_bounds) $ add_maybe_clipped image
194
183
195−is_out_of_bounds :: Image -> BlitState -> Bool
184+is_out_of_bounds :: BlitState -> Bool
196−is_out_of_bounds image s
185+is_out_of_bounds s
197 | s ^. remaining_columns <= 0 = True
186 | s ^. remaining_columns <= 0 = True
198 | s ^. remaining_rows <= 0 = True
187 | s ^. remaining_rows <= 0 = True
199 | otherwise = False
188 | otherwise = False
@@ -334,6 +323,7 @@ clip_text txt left_skip right_clip =
334 | w == cw = (n+1, False)
323 | w == cw = (n+1, False)
335 | w > cw = clip_for_char_width (w - cw) (TL.tail t) (n + 1)
324 | w > cw = clip_for_char_width (w - cw) (TL.tail t) (n + 1)
336 where cw = safe_wcwidth (TL.head t)
325 where cw = safe_wcwidth (TL.head t)
326+ clip_for_char_width _ _ _ = error "clip_for_char_width applied to undefined"
337 in txt''
327 in txt''
338
328
339add_unclipped_text :: DisplayText -> BlitM s ()
329add_unclipped_text :: DisplayText -> BlitM s ()
src/Graphics/Vty/Terminal/Debug.hs+3
@@ -82,6 +82,9 @@ instance DisplayTerminal DebugDisplay where
82 -- | Provide the current bounds of the output terminal.
82 -- | Provide the current bounds of the output terminal.
83 context_region d = debug_display_bounds d
83 context_region d = debug_display_bounds d
84
84
85+ -- | Assume 16 colors
86+ context_color_count d = 16
87+
85 -- | A cursor move is always visualized as the single character 'M'
88 -- | A cursor move is always visualized as the single character 'M'
86 move_cursor_required_bytes _d _x _y = 1
89 move_cursor_required_bytes _d _x _y = 1
87
90
test/Verify/Graphics/Vty/DisplayRegion.hs+1−3
@@ -10,12 +10,10 @@ import Graphics.Vty.DisplayRegion
10
10
11import Verify
11import Verify
12
12
13−import Data.Word
14−
15data EmptyWindow = EmptyWindow DebugWindow
13data EmptyWindow = EmptyWindow DebugWindow
16
14
17instance Arbitrary EmptyWindow where
15instance Arbitrary EmptyWindow where
18− arbitrary = return $ EmptyWindow (DebugWindow (0 :: Word) (0 :: Word))
16+ arbitrary = return $ EmptyWindow (DebugWindow (0 :: Int) (0 :: Int))
19
17
20instance Show EmptyWindow where
18instance Show EmptyWindow where
21 show (EmptyWindow _) = "EmptyWindow"
19 show (EmptyWindow _) = "EmptyWindow"
test/Verify/Graphics/Vty/Image.hs+3−5
@@ -11,8 +11,6 @@ import Graphics.Vty.Image
11
11
12import Verify
12import Verify
13
13
14−import Data.Word
15−
16data UnitImage = UnitImage Char Image
14data UnitImage = UnitImage Char Image
17
15
18instance Arbitrary UnitImage where
16instance Arbitrary UnitImage where
@@ -38,7 +36,7 @@ instance Arbitrary DefaultImage where
38data SingleRowSingleAttrImage
36data SingleRowSingleAttrImage
39 = SingleRowSingleAttrImage
37 = SingleRowSingleAttrImage
40 { expected_attr :: Attr
38 { expected_attr :: Attr
41− , expected_columns :: Word
39+ , expected_columns :: Int
42 , row_image :: Image
40 , row_image :: Image
43 }
41 }
44
42
@@ -74,8 +72,8 @@ instance Arbitrary SingleRowTwoAttrImage where
74data SingleAttrSingleSpanStack = SingleAttrSingleSpanStack
72data SingleAttrSingleSpanStack = SingleAttrSingleSpanStack
75 { stack_image :: Image
73 { stack_image :: Image
76 , stack_source_images :: [SingleRowSingleAttrImage]
74 , stack_source_images :: [SingleRowSingleAttrImage]
77− , stack_width :: Word
75+ , stack_width :: Int
78− , stack_height :: Word
76+ , stack_height :: Int
79 }
77 }
80 deriving Show
78 deriving Show
81
79
test/VerifyImageOps.hs+3−4
@@ -2,12 +2,11 @@
2module VerifyImageOps where
2module VerifyImageOps where
3
3
4import Graphics.Vty.Attributes
4import Graphics.Vty.Attributes
5+import Graphics.Vty.Image.Internal
5import Verify.Graphics.Vty.Image
6import Verify.Graphics.Vty.Image
6
7
7import Verify
8import Verify
8
9
9−import Data.Word
10−
11two_sw_horiz_concat :: SingleColumnChar -> SingleColumnChar -> Bool
10two_sw_horiz_concat :: SingleColumnChar -> SingleColumnChar -> Bool
12two_sw_horiz_concat (SingleColumnChar c1) (SingleColumnChar c2) =
11two_sw_horiz_concat (SingleColumnChar c1) (SingleColumnChar c2) =
13 image_width (char def_attr c1 <|> char def_attr c2) == 2
12 image_width (char def_attr c1 <|> char def_attr c2) == 2
@@ -50,7 +49,7 @@ horiz_concat_dw_assoc (DoubleColumnChar c0) (DoubleColumnChar c1) (DoubleColumnC
50
49
51vert_contat_single_row :: NonEmptyList SingleRowSingleAttrImage -> Bool
50vert_contat_single_row :: NonEmptyList SingleRowSingleAttrImage -> Bool
52vert_contat_single_row (NonEmpty stack) =
51vert_contat_single_row (NonEmpty stack) =
53− let expected_height :: Word = fromIntegral $ length stack
52+ let expected_height :: Int = length stack
54 stack_image = vert_cat [ i | SingleRowSingleAttrImage { row_image = i } <- stack ]
53 stack_image = vert_cat [ i | SingleRowSingleAttrImage { row_image = i } <- stack ]
55 in image_height stack_image == expected_height
54 in image_height stack_image == expected_height
56
55
@@ -58,7 +57,7 @@ disjoint_height_horiz_join :: NonEmptyList SingleRowSingleAttrImage
58 -> NonEmptyList SingleRowSingleAttrImage
57 -> NonEmptyList SingleRowSingleAttrImage
59 -> Bool
58 -> Bool
60disjoint_height_horiz_join (NonEmpty stack_0) (NonEmpty stack_1) =
59disjoint_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)
62 stack_image_0 = vert_cat [ i | SingleRowSingleAttrImage { row_image = i } <- stack_0 ]
61 stack_image_0 = vert_cat [ i | SingleRowSingleAttrImage { row_image = i } <- stack_0 ]
63 stack_image_1 = vert_cat [ i | SingleRowSingleAttrImage { row_image = i } <- stack_1 ]
62 stack_image_1 = vert_cat [ i | SingleRowSingleAttrImage { row_image = i } <- stack_1 ]
64 in image_height (stack_image_0 <|> stack_image_1) == expected_height
63 in image_height (stack_image_0 <|> stack_image_1) == expected_height
test/VerifyImageTrans.hs+3−1
@@ -3,11 +3,13 @@ module VerifyImageTrans where
3
3
4import Verify.Graphics.Vty.Image
4import Verify.Graphics.Vty.Image
5
5
6+import Graphics.Vty.Image.Internal
7+
6import Verify
8import Verify
7
9
8import Data.Word
10import Data.Word
9
11
10−is_horiz_text_of_columns :: Image -> Word -> Bool
12+is_horiz_text_of_columns :: Image -> Int -> Bool
11is_horiz_text_of_columns (HorizText { output_width = in_w }) expected_w = in_w == expected_w
13is_horiz_text_of_columns (HorizText { output_width = in_w }) expected_w = in_w == expected_w
12is_horiz_text_of_columns (BGFill { output_width = in_w }) expected_w = in_w == expected_w
14is_horiz_text_of_columns (BGFill { output_width = in_w }) expected_w = in_w == expected_w
13is_horiz_text_of_columns _image _expected_w = False
15is_horiz_text_of_columns _image _expected_w = False
vty.cabal+20−10
@@ -62,12 +62,13 @@ library
62 Graphics.Vty.LLInput
62 Graphics.Vty.LLInput
63 Graphics.Vty.Picture
63 Graphics.Vty.Picture
64 Graphics.Vty.Terminal
64 Graphics.Vty.Terminal
65− Codec.Binary.UTF8.Width
65+ Graphics.Text.Width
66
66
67 other-modules: Data.Marshalling
67 other-modules: Data.Marshalling
68 Data.Terminfo.Parse
68 Data.Terminfo.Parse
69 Data.Terminfo.Eval
69 Data.Terminfo.Eval
70 Graphics.Vty.DisplayAttributes
70 Graphics.Vty.DisplayAttributes
71+ Graphics.Vty.Image.Internal
71 Graphics.Vty.Span
72 Graphics.Vty.Span
72 Graphics.Vty.Terminal.Generic
73 Graphics.Vty.Terminal.Generic
73 Graphics.Vty.Terminal.MacOSX
74 Graphics.Vty.Terminal.MacOSX
@@ -125,6 +126,7 @@ test-suite verify-using-mock-terminal
125 Graphics.Vty.DisplayAttributes
126 Graphics.Vty.DisplayAttributes
126 Graphics.Vty.DisplayRegion
127 Graphics.Vty.DisplayRegion
127 Graphics.Vty.Image
128 Graphics.Vty.Image
129+ Graphics.Vty.Image.Internal
128 Graphics.Vty.Picture
130 Graphics.Vty.Picture
129 Graphics.Vty.Span
131 Graphics.Vty.Span
130 Graphics.Vty.Terminal
132 Graphics.Vty.Terminal
@@ -132,7 +134,7 @@ test-suite verify-using-mock-terminal
132 Graphics.Vty.Terminal.Debug
134 Graphics.Vty.Terminal.Debug
133 Graphics.Vty.Debug
135 Graphics.Vty.Debug
134 Graphics.Vty.Debug.Image
136 Graphics.Vty.Debug.Image
135− Codec.Binary.UTF8.Width
137+ Graphics.Text.Width
136 Verify
138 Verify
137 Verify.Graphics.Vty.Attributes
139 Verify.Graphics.Vty.Attributes
138 Verify.Graphics.Vty.DisplayRegion
140 Verify.Graphics.Vty.DisplayRegion
@@ -178,6 +180,7 @@ test-suite verify-display-attributes
178 Graphics.Vty.DisplayAttributes
180 Graphics.Vty.DisplayAttributes
179 Graphics.Vty.DisplayRegion
181 Graphics.Vty.DisplayRegion
180 Graphics.Vty.Image
182 Graphics.Vty.Image
183+ Graphics.Vty.Image.Internal
181 Graphics.Vty.Picture
184 Graphics.Vty.Picture
182 Graphics.Vty.Span
185 Graphics.Vty.Span
183 Graphics.Vty.Terminal
186 Graphics.Vty.Terminal
@@ -185,7 +188,7 @@ test-suite verify-display-attributes
185 Graphics.Vty.Terminal.Debug
188 Graphics.Vty.Terminal.Debug
186 Graphics.Vty.Debug
189 Graphics.Vty.Debug
187 Graphics.Vty.Debug.Image
190 Graphics.Vty.Debug.Image
188− Codec.Binary.UTF8.Width
191+ Graphics.Text.Width
189 Verify
192 Verify
190 Verify.Graphics.Vty.Attributes
193 Verify.Graphics.Vty.Attributes
191 Verify.Graphics.Vty.DisplayRegion
194 Verify.Graphics.Vty.DisplayRegion
@@ -259,7 +262,7 @@ test-suite verify-eval-terminfo-caps
259 other-modules: Data.Terminfo.Parse
262 other-modules: Data.Terminfo.Parse
260 Data.Terminfo.Eval
263 Data.Terminfo.Eval
261 Data.Marshalling
264 Data.Marshalling
262− Codec.Binary.UTF8.Width
265+ Graphics.Text.Width
263 Verify
266 Verify
264
267
265 build-depends: Cabal == 1.17.*,
268 build-depends: Cabal == 1.17.*,
@@ -293,10 +296,11 @@ test-suite verify-image-ops
293 Graphics.Vty.DisplayAttributes
296 Graphics.Vty.DisplayAttributes
294 Graphics.Vty.DisplayRegion
297 Graphics.Vty.DisplayRegion
295 Graphics.Vty.Image
298 Graphics.Vty.Image
299+ Graphics.Vty.Image.Internal
296 Graphics.Vty.Picture
300 Graphics.Vty.Picture
297 Graphics.Vty.Span
301 Graphics.Vty.Span
298 Graphics.Vty.Debug.Image
302 Graphics.Vty.Debug.Image
299− Codec.Binary.UTF8.Width
303+ Graphics.Text.Width
300 Verify
304 Verify
301 Verify.Graphics.Vty.Attributes
305 Verify.Graphics.Vty.Attributes
302 Verify.Graphics.Vty.Image
306 Verify.Graphics.Vty.Image
@@ -337,7 +341,8 @@ test-suite verify-image-trans
337 other-modules: Graphics.Vty.Attributes
341 other-modules: Graphics.Vty.Attributes
338 Graphics.Vty.Debug.Image
342 Graphics.Vty.Debug.Image
339 Graphics.Vty.Image
343 Graphics.Vty.Image
340− Codec.Binary.UTF8.Width
344+ Graphics.Vty.Image.Internal
345+ Graphics.Text.Width
341 Verify
346 Verify
342 Verify.Graphics.Vty.Attributes
347 Verify.Graphics.Vty.Attributes
343 Verify.Graphics.Vty.Image
348 Verify.Graphics.Vty.Image
@@ -373,7 +378,7 @@ test-suite verify-inline
373
378
374 test-module: VerifyInline
379 test-module: VerifyInline
375
380
376− other-modules: Codec.Binary.UTF8.Width
381+ other-modules: Graphics.Text.Width
377 Data.Terminfo.Eval
382 Data.Terminfo.Eval
378 Data.Terminfo.Parse
383 Data.Terminfo.Parse
379 Data.Marshalling
384 Data.Marshalling
@@ -381,7 +386,9 @@ test-suite verify-inline
381 Graphics.Vty.DisplayAttributes
386 Graphics.Vty.DisplayAttributes
382 Graphics.Vty.DisplayRegion
387 Graphics.Vty.DisplayRegion
383 Graphics.Vty.Image
388 Graphics.Vty.Image
389+ Graphics.Vty.Image.Internal
384 Graphics.Vty.Inline
390 Graphics.Vty.Inline
391+ Graphics.Vty.Picture
385 Graphics.Vty.Span
392 Graphics.Vty.Span
386 Graphics.Vty.Terminal
393 Graphics.Vty.Terminal
387 Graphics.Vty.Terminal.Generic
394 Graphics.Vty.Terminal.Generic
@@ -492,6 +499,7 @@ test-suite verify-picture-to-span
492 Graphics.Vty.DisplayAttributes
499 Graphics.Vty.DisplayAttributes
493 Graphics.Vty.DisplayRegion
500 Graphics.Vty.DisplayRegion
494 Graphics.Vty.Image
501 Graphics.Vty.Image
502+ Graphics.Vty.Image.Internal
495 Graphics.Vty.Picture
503 Graphics.Vty.Picture
496 Graphics.Vty.Span
504 Graphics.Vty.Span
497 Graphics.Vty.Terminal
505 Graphics.Vty.Terminal
@@ -499,7 +507,7 @@ test-suite verify-picture-to-span
499 Graphics.Vty.Terminal.Debug
507 Graphics.Vty.Terminal.Debug
500 Graphics.Vty.Debug
508 Graphics.Vty.Debug
501 Graphics.Vty.Debug.Image
509 Graphics.Vty.Debug.Image
502− Codec.Binary.UTF8.Width
510+ Graphics.Text.Width
503 Verify
511 Verify
504 Verify.Graphics.Vty.Attributes
512 Verify.Graphics.Vty.Attributes
505 Verify.Graphics.Vty.DisplayRegion
513 Verify.Graphics.Vty.DisplayRegion
@@ -545,6 +553,7 @@ test-suite verify-span-ops
545 Graphics.Vty.DisplayAttributes
553 Graphics.Vty.DisplayAttributes
546 Graphics.Vty.DisplayRegion
554 Graphics.Vty.DisplayRegion
547 Graphics.Vty.Image
555 Graphics.Vty.Image
556+ Graphics.Vty.Image.Internal
548 Graphics.Vty.Picture
557 Graphics.Vty.Picture
549 Graphics.Vty.Span
558 Graphics.Vty.Span
550 Graphics.Vty.Terminal
559 Graphics.Vty.Terminal
@@ -552,7 +561,7 @@ test-suite verify-span-ops
552 Graphics.Vty.Terminal.Debug
561 Graphics.Vty.Terminal.Debug
553 Graphics.Vty.Debug
562 Graphics.Vty.Debug
554 Graphics.Vty.Debug.Image
563 Graphics.Vty.Debug.Image
555− Codec.Binary.UTF8.Width
564+ Graphics.Text.Width
556 Verify
565 Verify
557 Verify.Graphics.Vty.Attributes
566 Verify.Graphics.Vty.Attributes
558 Verify.Graphics.Vty.DisplayRegion
567 Verify.Graphics.Vty.DisplayRegion
@@ -593,9 +602,10 @@ test-suite verify-utf8-width
593
602
594 test-module: VerifyUtf8Width
603 test-module: VerifyUtf8Width
595
604
596− other-modules: Codec.Binary.UTF8.Width
605+ other-modules: Graphics.Text.Width
597 Graphics.Vty.Attributes
606 Graphics.Vty.Attributes
598 Graphics.Vty.Image
607 Graphics.Vty.Image
608+ Graphics.Vty.Image.Internal
599 Verify
609 Verify
600
610
601 c-sources: cbits/mk_wcwidth.c
611 c-sources: cbits/mk_wcwidth.c