on master help sign in
compiling again. fails testing tho
commitcd6747cfa6407b8e8ee1149fce79f22bce1b5a8b authorCorey O'Connor <corey@ooyala.com> dateSat 1 Jun 2013, 05:18 (13 years ago) parent81c65e2
11 files changed+131−103
src/Data/Terminfo/Eval.hs+2−2 src/Graphics/Vty/Debug.hs+4−4 src/Graphics/Vty/DisplayRegion.hs+2−2 src/Graphics/Vty/Picture.hs+1−1 src/Graphics/Vty/Span.hs+69−44 src/Graphics/Vty/Terminal.hs+6−3 src/Graphics/Vty/Terminal/Generic.hs+23−24 src/Graphics/Vty/Terminal/TerminfoBased.hs+9−9 src/Graphics/Vty/Terminal/XTermColor.hs+3−2 test/BenchVerticalScroll.hs+10−10 test/Verify/Graphics/Vty/Image.hs+2−2
src/Data/Terminfo/Eval.hs+2−2
@@ -66,11 +66,11 @@ apply_param_ops cap params = foldl apply_param_op params (param_ops cap)
6666apply_param_op :: [CapParam] -> ParamOp -> [CapParam]
6767apply_param_op params IncFirstTwo = map (+ 1) params
6868
69−cap_expression_required_bytes :: CapExpression -> [CapParam] -> Word
69+cap_expression_required_bytes :: CapExpression -> [CapParam] -> Int
7070cap_expression_required_bytes cap params =
7171 let params' = apply_param_ops cap params
7272 s_0 = EvalState [] cap params'
73− in fst $! runIdentity $! runStateT ( cap_ops_required_bytes $! cap_ops cap ) s_0
73+ in fromEnum $! fst $! runIdentity $! runStateT ( cap_ops_required_bytes $! cap_ops cap ) s_0
7474
7575cap_ops_required_bytes :: CapOps -> Eval Word
7676cap_ops_required_bytes ops = do
src/Graphics/Vty/Debug.hs+4−4
@@ -13,15 +13,15 @@ import Graphics.Vty.DisplayRegion
1313import qualified Data.Vector as Vector
1414import Data.Word
1515
16−row_ops_effected_columns :: DisplayOps -> [Word]
16+row_ops_effected_columns :: DisplayOps -> [Int]
1717row_ops_effected_columns spans
1818 = Vector.toList $ Vector.map span_ops_effected_columns $ display_ops spans
1919
20−all_spans_have_width :: DisplayOps -> Word -> Bool
20+all_spans_have_width :: DisplayOps -> Int -> Bool
2121all_spans_have_width spans expected
2222 = all (== expected) $ Vector.toList $ Vector.map span_ops_effected_columns $ display_ops spans
2323
24−span_ops_effected_rows :: DisplayOps -> Word
24+span_ops_effected_rows :: DisplayOps -> Int
2525span_ops_effected_rows (DisplayOps _ the_row_ops)
2626 = toEnum $ length (filter (not . null . Vector.toList) (Vector.toList the_row_ops))
2727
@@ -33,7 +33,7 @@ is_set_attr expected_attr (SpanSetAttr in_attr)
3333 | in_attr == expected_attr = True
3434is_set_attr _attr _event = False
3535
36−data DebugWindow = DebugWindow Word Word
36+data DebugWindow = DebugWindow Int Int
3737 deriving (Show, Eq)
3838
3939region_for_window :: DebugWindow -> DisplayRegion
src/Graphics/Vty/DisplayRegion.hs+2−2
@@ -6,7 +6,7 @@ import Data.Word
66
77-- | Region of the terminal that vty will output to. Units are columns not characters.
88data DisplayRegion = DisplayRegion
9− { region_width :: !Word
10− , region_height :: !Word
9+ { region_width :: !Int
10+ , region_height :: !Int
1111 } deriving ( Show, Eq )
1212
src/Graphics/Vty/Picture.hs+1−1
@@ -68,7 +68,7 @@ pic_for_image i = Picture
6868-- output region. In this case the cursor will not be shown.
6969data Cursor =
7070 NoCursor
71− | Cursor Word Word
71+ | Cursor Int Int
7272
7373instance NFData Cursor where
7474 rnf NoCursor = ()
src/Graphics/Vty/Span.hs+69−44
@@ -1,3 +1,4 @@
1+{-# LANGUAGE RankNTypes #-}
12-- Copyright Corey O'Connor
23{-# LANGUAGE TemplateHaskell #-}
34{-# LANGUAGE BangPatterns #-}
@@ -25,6 +26,7 @@ import Graphics.Vty.Picture
2526import Graphics.Vty.DisplayRegion
2627import Graphics.Text.Width
2728
29+import Control.Applicative
2830import Control.Lens
2931import Control.Monad ( forM_ )
3032import Control.Monad.Reader
@@ -38,9 +40,12 @@ import qualified Data.Vector as Vector hiding ( take, replicate )
3840import Data.Vector.Mutable ( MVector(..))
3941import qualified Data.Vector.Mutable as Vector
4042
43+import qualified Data.ByteString as BS
4144import qualified Data.ByteString.Lazy as BL
42−import qualified Data.ByteString.Lazy.Internal as BLInt
45+import qualified Data.ByteString.Lazy.Internal as BL
4346import qualified Data.Foldable as Foldable
47+import qualified Data.Text as T
48+import qualified Data.Text.Encoding as T
4449import qualified Data.Text.Lazy as TL
4550import qualified Data.Text.Lazy.Encoding as TL
4651import Data.Word
@@ -58,7 +63,7 @@ data SpanOp =
5863 -- | a span of UTF-8 text occupies a specific number of screen space columns. A single UTF
5964 -- character does not necessarially represent 1 colunm. See Codec.Binary.UTF8.Width
6065 -- TextSpan [output width in columns] [number of characters] [data]
61− | TextSpan !Int !Int BL.ByteString
66+ | TextSpan !Int !Int BS.ByteString
6267 deriving Eq
6368
6469-- | vector of span operations. executed in succession. This represents the operations required to
@@ -67,7 +72,6 @@ data SpanOp =
6772-- color is changed.
6873type SpanOps = Vector SpanOp
6974
70−
7175data DisplayOps = DisplayOps
7276 { effected_region :: DisplayRegion
7377 , display_ops :: RowOps
@@ -91,7 +95,8 @@ instance Show SpanOp where
9195-- transform plus clip. More or less.
9296data BlitState = BlitState
9397 -- we always snoc to the operation vectors. Thus the column_offset = length of row at row_offset
94− { _row_offset :: Int
98+ { _column_offset :: Int
99+ , _row_offset :: Int
95100 -- clip coordinate space is in image space. Which means it's >= 0 and < image_width.
96101 , _skip_columns :: Int
97102 -- >= 0 and < image_height
@@ -117,15 +122,15 @@ makeLenses ''BlitEnv
117122type BlitM s a = ReaderT (BlitEnv s) (StateT BlitState (ST s)) a
118123
119124-- | Number of columns the DisplayOps are defined for
120−span_ops_columns :: DisplayOps -> Word
125+span_ops_columns :: DisplayOps -> Int
121126span_ops_columns ops = region_width $ effected_region ops
122127
123128-- | Number of rows the DisplayOps are defined for
124−span_ops_rows :: DisplayOps -> Word
129+span_ops_rows :: DisplayOps -> Int
125130span_ops_rows ops = region_height $ effected_region ops
126131
127132-- | The number of columns a SpanOps effects.
128−span_ops_effected_columns :: SpanOps -> Word
133+span_ops_effected_columns :: SpanOps -> Int
129134span_ops_effected_columns in_ops = Vector.foldl' span_ops_effected_columns' 0 in_ops
130135 where
131136 span_ops_effected_columns' t (TextSpan w _ _ ) = t + w
@@ -139,7 +144,7 @@ span_op_has_width _ = Nothing
139144-- | returns the number of columns to the character at the given position in the span op
140145columns_to_char_offset :: Int -> SpanOp -> Int
141146columns_to_char_offset cx (TextSpan _ _ utf8_str) =
142− let str = TL.unpack (TL.decodeUtf8 utf8_str)
147+ let str = T.unpack (T.decodeUtf8 utf8_str)
143148 in wcswidth (take cx str)
144149columns_to_char_offset _cx _ = error "columns_to_char_offset applied to span op without width"
145150
@@ -166,24 +171,18 @@ build_spans pic region = do
166171 --
167172 -- The images are made into span operations from left to right. It's possible that this could
168173 -- easily be made to assure top to bottom output as well.
169− if region_height region > 0
170− then do
171− -- The ops builder recursively descends the image and outputs span ops that would
172− -- display that image. The number of columns remaining in this row before exceeding the
173− -- bounds is also provided. This is used to clip the span ops produced to the display.
174− -- The skip dimensions provided do....???
175− _ <- runStateT (runReaderT (start_image_build $ pic_image pic)
176− (BlitEnv (pic_background pic) region mrow_ops)
177− )
178− (BlitState 0 0 0 0 (region_width region) (region_height region))
179− -- Fill in any unspecified columns with the background pattern.
180− -- todo: If there is no background pattern defined then skip
181− forM_ [0 .. (region_height region - 1)] $! \row -> do
182− end_x <- Vector.read mrow_ops row >>= return . span_ops_effected_columns
183− if end_x < region_width region
184− then snoc_bg_fill mrow_ops (pic_background pic) (region_width region - end_x) row
185− else return ()
186− else return ()
174+ when (region_height region > 0 && region_width region > 0) $ do
175+ -- 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
177+ -- bounds is also provided. This is used to clip the span ops produced to the display.
178+ let full_build = do
179+ start_image_build $ pic_image pic
180+ -- 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)
184+ _ <- runStateT (runReaderT full_build init_env) init_state
185+ return ()
187186 return mrow_ops
188187
189188-- | Add the operations required to build a given image to the current set of row operations
@@ -191,14 +190,12 @@ build_spans pic region = do
191190start_image_build :: Image -> BlitM s ()
192191start_image_build image = do
193192 out_of_bounds <- is_out_of_bounds image <$> get
194− if out_of_bounds
195− then return (0,0)
196− else add_maybe_clipped image
193+ when (not out_of_bounds) $ add_maybe_clipped image
197194
198195is_out_of_bounds :: Image -> BlitState -> Bool
199196is_out_of_bounds image s
200197 | s ^. remaining_columns <= 0 = True
201− | s ^. remain_rows <= 0 = True
198+ | s ^. remaining_rows <= 0 = True
202199 | otherwise = False
203200
204201-- TODO: prove skip_columns, skip_rows == 0
@@ -206,7 +203,7 @@ is_out_of_bounds image s
206203-- TODO: prove remaining_rows >= image_height
207204add_unclipped :: Image -> BlitM s ()
208205add_unclipped EmptyImage = return ()
209−add_unclipped (HorizText text_str _ow _cw) = do
206+add_unclipped (HorizText a text_str _ow _cw) = do
210207 use row_offset >>= snoc_op (AttributeChange a)
211208 add_unclipped_text text_str
212209add_unclipped (HorizJoin part_left part_right _ow _oh) = do
@@ -224,8 +221,10 @@ add_unclipped (VertJoin part_top part_bottom _ow _oh) = do
224221add_unclipped (BGFill ow oh) = do
225222 Background c a <- view bg
226223 y <- use row_offset
227− let op = TextSpan ow ow (TL.replicate (fromIntegral ow) c)
228− forM_ [y..y+oh] $ snoc_op op
224+ let op = TextSpan ow ow (T.encodeUtf8 $ T.replicate (fromIntegral ow) (T.singleton c))
225+ forM_ [y..y+oh] $ \row -> do
226+ snoc_op (AttributeChange a) row
227+ snoc_op op row
229228-- TODO: we know it's clipped actually, the equations that are exposed that introduce a
230229-- Crop all assure the image exceeds the crop in the relevant direction.
231230add_unclipped CropRight {cropped_image, output_width} = do
@@ -242,9 +241,9 @@ add_unclipped CropTop {cropped_image, top_skip} = do
242241 add_maybe_clipped cropped_image
243242
244243-- TODO: prove this cannot be called in an out of bounds case.
245−add_maybe_clipped :: Image -> BlitM s ()
244+add_maybe_clipped :: forall s . Image -> BlitM s ()
246245add_maybe_clipped EmptyImage = return ()
247−add_maybe_clipped (HorizText text_str ow _cw) = do
246+add_maybe_clipped (HorizText a text_str ow _cw) = do
248247 -- TODO: assumption that text spans are only 1 row high.
249248 s <- use skip_rows
250249 when (s < 1) $ do
@@ -254,7 +253,7 @@ add_maybe_clipped (HorizText text_str ow _cw) = do
254253 let left_clipped = left_clip > 0
255254 right_clipped = (ow - left_clip) > right_clip
256255 if left_clipped || right_clipped
257− then let text_str' = clip_text left_clip right_clip
256+ then let text_str' = clip_text text_str left_clip right_clip
258257 in add_unclipped_text text_str'
259258 else add_unclipped_text text_str
260259add_maybe_clipped (VertJoin top_image bottom_image _ow oh) = do
@@ -264,15 +263,15 @@ add_maybe_clipped (VertJoin top_image bottom_image _ow oh) = do
264263 bottom_image
265264 oh
266265add_maybe_clipped (HorizJoin left_image right_image ow _oh) = do
267− add_maybe_clipped_join "horiz_join" skip_columns remaining_columns devoid
266+ add_maybe_clipped_join "horiz_join" skip_columns remaining_columns column_offset
268267 (image_width right_image)
269268 left_image
270269 right_image
271270 ow
272271add_maybe_clipped BGFill {output_width, output_height} = do
273272 s <- get
274− let output_width' = min (output_width - s.^skip_columns) s.^remaining_columns
275− output_height' = min (output_height - s.^skip_rows ) s.^remaining_rows
273+ let output_width' = min (output_width - s^.skip_columns) (s^.remaining_columns)
274+ output_height' = min (output_height - s^.skip_rows ) (s^.remaining_rows)
276275 add_unclipped (BGFill output_width' output_height')
277276add_maybe_clipped CropRight {cropped_image, output_width} = do
278277 remaining_columns .= output_width
@@ -287,6 +286,15 @@ add_maybe_clipped CropTop {cropped_image, top_skip} = do
287286 skip_rows += top_skip
288287 add_maybe_clipped cropped_image
289288
289+add_maybe_clipped_join :: forall s . String
290+ -> Lens BlitState BlitState Int Int
291+ -> Lens BlitState BlitState Int Int
292+ -> Lens BlitState BlitState Int Int
293+ -> Int
294+ -> Image
295+ -> Image
296+ -> Int
297+ -> BlitM s ()
290298add_maybe_clipped_join name skip remaining offset i0_dim i0 i1 size = do
291299 state <- get
292300 when (state^.remaining == 0) $ fail $ name ++ " with remaining == 0"
@@ -313,7 +321,7 @@ add_maybe_clipped_join name skip remaining offset i0_dim i0 i1 size = do
313321-- TODO: represent display strings containing chars that are not 1 column chars as a separate
314322-- display string value?
315323-- TODO: assumes max column width is 2
316−clip_text :: DisplayString -> Int -> Int -> DisplayString
324+clip_text :: DisplayText -> Int -> Int -> DisplayText
317325clip_text txt left_skip right_clip =
318326 -- CPS would clarify this I think
319327 let (to_drop,pad_prefix) = clip_for_char_width left_skip txt 0
@@ -324,21 +332,38 @@ clip_text txt left_skip right_clip =
324332 clip_for_char_width w t n
325333 | w < cw = (n, True)
326334 | w == cw = (n+1, False)
327− | w > cw = clip_for_char_width (w - cw) (TL.rest t) (n + 1)
335+ | w > cw = clip_for_char_width (w - cw) (TL.tail t) (n + 1)
328336 where cw = safe_wcwidth (TL.head t)
329337 in txt''
330338
331−add_unclipped_text :: DisplayString -> BlitM ()
339+add_unclipped_text :: DisplayText -> BlitM s ()
332340add_unclipped_text txt = do
333− let op = TextSpan used_display_columns (TL.length txt) (TL.encodeUtf8 txt)
341+ let op = TextSpan used_display_columns
342+ (fromIntegral $ TL.length txt)
343+ (T.encodeUtf8 $ TL.toStrict txt)
334344 used_display_columns = wcswidth $ TL.unpack txt
335345 use row_offset >>= snoc_op op
336346
347+-- todo: If there is no background pattern defined then skip to next line.
348+-- todo: assumes background character is 1 column
349+add_row_completion :: Int -> BlitM s ()
350+add_row_completion row = do
351+ all_row_ops <- view mrow_ops
352+ Background c a <- view bg
353+ display_region <- view region
354+ row_ops <- lift $ lift $ Vector.read all_row_ops row
355+ let end_x = span_ops_effected_columns row_ops
356+ when (end_x < region_width display_region) $ do
357+ let ow = region_width display_region - end_x
358+ op = TextSpan ow ow (T.encodeUtf8 $ T.replicate (fromIntegral ow) (T.singleton c))
359+ snoc_op (AttributeChange a) row
360+ snoc_op op row
361+
337362-- | snocs the operation to the operations for the given row.
338363snoc_op :: SpanOp -> Int -> BlitM s ()
339364snoc_op !op !row = do
340365 the_mrow_ops <- view mrow_ops
341− lift $ do
366+ lift $ lift $ do
342367 ops <- Vector.read the_mrow_ops row
343368 let ops' = Vector.snoc ops op
344369 Vector.write the_mrow_ops row ops'
src/Graphics/Vty/Terminal.hs+6−3
@@ -29,6 +29,7 @@ module Graphics.Vty.Terminal ( module Graphics.Vty.Terminal
2929 where
3030
3131
32+import Graphics.Vty.DisplayRegion
3233import Graphics.Vty.Terminal.Generic
3334import Graphics.Vty.Terminal.MacOSX as MacOSX
3435import Graphics.Vty.Terminal.XTermColor as XTermColor
@@ -36,6 +37,7 @@ import Graphics.Vty.Terminal.TerminfoBased as TerminfoBased
3637
3738import Control.Applicative
3839import Control.Exception ( SomeException, try )
40+import Control.Monad
3941import Control.Monad.Trans
4042
4143import Data.List ( isPrefixOf )
@@ -115,11 +117,12 @@ terminal_handle = do
115117--
116118-- Currently, the only way to set the cursor position to a given character coordinate is to specify
117119-- the coordinate in the Picture instance provided to output_picture or refresh.
118−set_cursor_pos :: MonadIO m => TerminalHandle -> Word -> Word -> m ()
120+set_cursor_pos :: MonadIO m => TerminalHandle -> Int -> Int -> m ()
119121set_cursor_pos t x y = do
120122 bounds <- display_bounds t
121− d <- display_context t bounds
122− liftIO $ marshall_to_terminal t (move_cursor_required_bytes d x y) (serialize_move_cursor d x y)
123+ when (x >= 0 && x < region_width bounds && y >= 0 && y < region_height bounds) $ do
124+ d <- display_context t bounds
125+ liftIO $ marshall_to_terminal t (move_cursor_required_bytes d x y) (serialize_move_cursor d x y)
123126
124127-- | Hides the cursor
125128hide_cursor :: MonadIO m => TerminalHandle -> m ()
src/Graphics/Vty/Terminal/Generic.hs+23−24
@@ -21,9 +21,8 @@ import Graphics.Vty.DisplayAttributes
2121import Control.Monad ( liftM )
2222import Control.Monad.Trans
2323
24−import qualified Data.ByteString.Internal as BSCore
24+import qualified Data.ByteString.Internal as BS
2525import Data.IORef
26−import Data.String.UTF8 hiding ( foldl )
2726import qualified Data.Vector as Vector
2827
2928import System.IO
@@ -84,7 +83,7 @@ class Terminal t where
8483
8584 -- | Output the byte buffer of the specified size to the terminal device. The size is equal to
8685 -- end_ptr - start_ptr
87− output_byte_buffer :: t -> OutputBuffer -> Word -> IO ()
86+ output_byte_buffer :: t -> OutputBuffer -> Int -> IO ()
8887
8988 -- | Handle of output device
9089 output_handle :: t -> IO Handle
@@ -122,17 +121,17 @@ class DisplayTerminal d where
122121 context_region :: d -> DisplayRegion
123122
124123 -- | Maximum number of colors supported by the context.
125− context_color_count :: d -> Word
124+ context_color_count :: d -> Int
126125
127126 -- | sets the output position to the specified row and column. Where the number of bytes
128127 -- required for the control codes can be specified seperate from the actual byte sequence.
129− move_cursor_required_bytes :: d -> Word -> Word -> Word
130− serialize_move_cursor :: MonadIO m => d -> Word -> Word -> OutputBuffer -> m OutputBuffer
128+ move_cursor_required_bytes :: d -> Int -> Int -> Int
129+ serialize_move_cursor :: MonadIO m => d -> Int -> Int -> OutputBuffer -> m OutputBuffer
131130
132− show_cursor_required_bytes :: d -> Word
131+ show_cursor_required_bytes :: d -> Int
133132 serialize_show_cursor :: MonadIO m => d -> OutputBuffer -> m OutputBuffer
134133
135− hide_cursor_required_bytes :: d -> Word
134+ hide_cursor_required_bytes :: d -> Int
136135 serialize_hide_cursor :: MonadIO m => d -> OutputBuffer -> m OutputBuffer
137136
138137 -- | Assure the specified output attributes will be applied to all the following text until the
@@ -146,11 +145,11 @@ class DisplayTerminal d where
146145 -- attributes. In order to support this the currently applied display attributes are required.
147146 -- In addition it may be possible to optimize the state changes based off the currently applied
148147 -- display attributes.
149− attr_required_bytes :: d -> FixedAttr -> Attr -> DisplayAttrDiff -> Word
148+ attr_required_bytes :: d -> FixedAttr -> Attr -> DisplayAttrDiff -> Int
150149 serialize_set_attr :: MonadIO m => d -> FixedAttr -> Attr -> DisplayAttrDiff -> OutputBuffer -> m OutputBuffer
151150
152151 -- | Reset the display attributes to the default display attributes
153− default_attr_required_bytes :: d -> Word
152+ default_attr_required_bytes :: d -> Int
154153 serialize_default_attr :: MonadIO m => d -> OutputBuffer -> m OutputBuffer
155154
156155 -- | See Graphics.Vty.Terminal.XTermColor.inline_hack
@@ -174,18 +173,18 @@ instance DisplayTerminal DisplayHandle where
174173 inline_hack (DisplayHandle d _ _) = inline_hack d
175174
176175-- | All terminals serialize UTF8 text to the terminal device exactly as serialized in memory.
177−utf8_text_required_bytes :: UTF8 BSCore.ByteString -> Word
176+utf8_text_required_bytes :: BS.ByteString -> Int
178177utf8_text_required_bytes str =
179− let (_, _, src_bytes_length) = BSCore.toForeignPtr (toRep str)
180− in toEnum src_bytes_length
178+ let (_, _, src_bytes_length) = BS.toForeignPtr str
179+ in src_bytes_length
181180
182181-- | All terminals serialize UTF8 text to the terminal device exactly as serialized in memory.
183−serialize_utf8_text :: MonadIO m => UTF8 BSCore.ByteString -> OutputBuffer -> m OutputBuffer
184−serialize_utf8_text str dest_ptr =
185− let (src_fptr, src_ptr_offset, src_bytes_length) = BSCore.toForeignPtr (toRep str)
182+serialize_utf8_text :: MonadIO m => BS.ByteString -> OutputBuffer -> m OutputBuffer
183+serialize_utf8_text str dest_ptr =
184+ let (src_fptr, src_ptr_offset, src_bytes_length) = BS.toForeignPtr str
186185 in liftIO $ withForeignPtr src_fptr $ \src_ptr -> do
187186 let src_ptr' = src_ptr `plusPtr` src_ptr_offset
188− BSCore.memcpy dest_ptr src_ptr' (toEnum src_bytes_length)
187+ BS.memcpy dest_ptr src_ptr' (toEnum src_bytes_length)
189188 return (dest_ptr `plusPtr` src_bytes_length)
190189
191190
@@ -255,7 +254,7 @@ output_picture (DisplayHandle d t s) pic = do
255254 liftIO $ writeIORef (previous_output_ref s) (Just ops)
256255 return ()
257256
258−required_bytes :: DisplayTerminal d => d -> FixedAttr -> [Bool] -> DisplayOps -> Word
257+required_bytes :: DisplayTerminal d => d -> FixedAttr -> [Bool] -> DisplayOps -> Int
259258required_bytes d in_fattr diffs ops =
260259 let (_, n, _, _) = Vector.foldl' required_bytes' (0, 0, in_fattr, diffs) ( display_ops ops )
261260 in n
@@ -268,7 +267,7 @@ required_bytes d in_fattr diffs ops =
268267 required_bytes' (_y, _current_sum, _fattr, [] ) _span_ops
269268 = error "shouldn't be possible"
270269
271−span_ops_required_bytes :: DisplayTerminal d => d -> Word -> FixedAttr -> SpanOps -> (Word, FixedAttr)
270+span_ops_required_bytes :: DisplayTerminal d => d -> Int -> FixedAttr -> SpanOps -> (Int, FixedAttr)
272271span_ops_required_bytes d y in_fattr span_ops =
273272 -- The first operation is to set the cursor to the start of the row
274273 let header_required_bytes = move_cursor_required_bytes d 0 y
@@ -279,7 +278,7 @@ span_ops_required_bytes d y in_fattr span_ops =
279278 (header_required_bytes, in_fattr)
280279 span_ops
281280
282−span_op_required_bytes :: DisplayTerminal d => d -> FixedAttr -> SpanOp -> (Word, FixedAttr)
281+span_op_required_bytes :: DisplayTerminal d => d -> FixedAttr -> SpanOp -> (Int, FixedAttr)
283282span_op_required_bytes d fattr (AttributeChange attr) =
284283 let attr' = limit_attr_for_display d attr
285284 diffs = display_attr_diffs fattr fattr'
@@ -311,7 +310,7 @@ serialize_output_ops d start_ptr in_fattr diffs ops = do
311310
312311serialize_span_ops :: ( MonadIO m, DisplayTerminal d )
313312 => d
314− -> Word
313+ -> Int
315314 -> OutputBuffer
316315 -> FixedAttr
317316 -> SpanOps
@@ -341,7 +340,7 @@ serialize_span_op _d (TextSpan _ _ str) out_ptr fattr = do
341340 return (out_ptr', fattr)
342341
343342marshall_to_terminal :: ( Terminal t )
344− => t -> Word -> (Ptr Word8 -> IO (Ptr Word8)) -> IO ()
343+ => t -> Int -> (Ptr Word8 -> IO (Ptr Word8)) -> IO ()
345344marshall_to_terminal t c f = do
346345 start_ptr <- mallocBytes (fromEnum c)
347346 --
@@ -357,7 +356,7 @@ marshall_to_terminal t c f = do
357356-- | The cursor position is given in X,Y character offsets. Due to multi-column characters this
358357-- needs to be translated to column, row positions.
359358data CursorOutputMap = CursorOutputMap
360− { char_to_output_pos :: (Word, Word) -> (Word, Word)
359+ { char_to_output_pos :: (Int, Int) -> (Int, Int)
361360 }
362361
363362cursor_output_map :: DisplayOps -> Cursor -> CursorOutputMap
@@ -365,7 +364,7 @@ cursor_output_map span_ops _cursor = CursorOutputMap
365364 { char_to_output_pos = \(cx, cy) -> (cursor_column_offset span_ops cx cy, cy)
366365 }
367366
368−cursor_column_offset :: DisplayOps -> Word -> Word -> Word
367+cursor_column_offset :: DisplayOps -> Int -> Int -> Int
369368cursor_column_offset span_ops cx cy =
370369 let cursor_row_ops = Vector.unsafeIndex (display_ops span_ops) (fromEnum cy)
371370 (out_offset, _, _)
src/Graphics/Vty/Terminal/TerminfoBased.hs+9−9
@@ -192,7 +192,7 @@ get_window_size = do
192192data DisplayContext = DisplayContext
193193 { bounds :: DisplayRegion
194194 , term :: Term
195− , supported_colors :: Word
195+ , supported_colors :: Int
196196 }
197197
198198instance DisplayTerminal DisplayContext where
@@ -201,9 +201,9 @@ instance DisplayTerminal DisplayContext where
201201 context_color_count d = supported_colors d
202202
203203 move_cursor_required_bytes d x y
204− = cap_expression_required_bytes (cup $ term d) [y, x]
204+ = cap_expression_required_bytes (cup $ term d) [toEnum y, toEnum x]
205205 serialize_move_cursor d x y out_ptr
206− = liftIO $ serialize_cap_expression (cup $ term d) [y, x] out_ptr
206+ = liftIO $ serialize_cap_expression (cup $ term d) [toEnum y, toEnum x] out_ptr
207207
208208 show_cursor_required_bytes d
209209 = cap_expression_required_bytes (cnorm $ term d) []
@@ -300,12 +300,12 @@ instance DisplayTerminal DisplayContext where
300300 set_colors ptr = do
301301 ptr' <- case fixed_fore_color attr of
302302 Just c -> liftIO $ serialize_cap_expression ( set_fore_color $ term d )
303− [ ansi_color_index c ]
303+ [ toEnum $ ansi_color_index c ]
304304 ptr
305305 Nothing -> return ptr
306306 ptr'' <- case fixed_back_color attr of
307307 Just c -> liftIO $ serialize_cap_expression ( set_back_color $ term d )
308− [ ansi_color_index c ]
308+ [ toEnum $ ansi_color_index c ]
309309 ptr'
310310 Nothing -> return ptr'
311311 return ptr''
@@ -315,7 +315,7 @@ instance DisplayTerminal DisplayContext where
315315 = fail "ColorToDefault is not a possible case for apply_color_diffs"
316316 apply_color_diff f ( SetColor c ) ptr
317317 = liftIO $ serialize_cap_expression ( f $ term d )
318− [ ansi_color_index c ]
318+ [ toEnum $ ansi_color_index c ]
319319 ptr
320320
321321 default_attr_required_bytes d
@@ -328,9 +328,9 @@ instance DisplayTerminal DisplayContext where
328328--
329329-- This takes a Color which clearly identifies which pallete to use and computes the index
330330-- into the full 256 color pallete.
331−ansi_color_index :: Color -> Word
332−ansi_color_index (ISOColor v) = toEnum $ fromEnum v
333−ansi_color_index (Color240 v) = 16 + ( toEnum $ fromEnum v )
331+ansi_color_index :: Color -> Int
332+ansi_color_index (ISOColor v) = fromEnum v
333+ansi_color_index (Color240 v) = 16 + fromEnum v
334334
335335{- | The sequence of terminfo caps to apply a given style are determined according to these rules.
336336 -
src/Graphics/Vty/Terminal/XTermColor.hs+3−2
@@ -14,7 +14,8 @@ import qualified Graphics.Vty.Terminal.TerminfoBased as TerminfoBased
1414import Control.Applicative
1515import Control.Monad.Trans
1616
17−import qualified Data.String.UTF8 as UTF8
17+import qualified Data.Text as T
18+import qualified Data.Text.Encoding as T
1819
1920import System.IO
2021
@@ -103,7 +104,7 @@ instance DisplayTerminal DisplayContext where
103104 inline_hack d = do
104105 let t = case super_display d of
105106 DisplayHandle _ t_ _ -> t_
106− let s_utf8 = UTF8.fromString "\ESC[K"
107+ let s_utf8 = T.encodeUtf8 $ T.pack "\ESC[K"
107108 liftIO $ marshall_to_terminal t ( utf8_text_required_bytes s_utf8)
108109 ( serialize_utf8_text s_utf8 )
109110
test/BenchVerticalScroll.hs+10−10
@@ -21,21 +21,21 @@ bench_0 = do
2121run vt = mapM_ (\p -> update vt p) . benchgen =<< display_bounds (terminal vt)
2222
2323-- Currently, we just do scrolling.
24−takem :: (a -> Word) -> Word -> [a] -> ([a],[a])
24+takem :: (a -> Int) -> Int -> [a] -> ([a],[a])
2525takem len n [] = ([],[])
2626takem len n (x:xs) | lx > n = ([], x:xs)
2727 | True = let (tk,dp) = takem len (n - lx) xs in (x:tk,dp)
2828 where lx = len x
2929
30−fold :: (a -> Word) -> [Word] -> [a] -> [[a]]
30+fold :: (a -> Int) -> [Int] -> [a] -> [[a]]
3131fold len [] xs = []
3232fold len (ll:lls) xs = let (tk,dp) = takem len ll xs in tk : fold len lls dp
3333
34−lengths :: Word -> StdGen -> [Word]
35−lengths ml g =
36− let (x,g2) = randomR (0,fromEnum ml) g
37− (y,g3) = randomR (0,x) g2
38− in (toEnum y) : lengths ml g3
34+lengths :: Int -> StdGen -> [Int]
35+lengths ml g =
36+ let (x,g2) = randomR (0,ml) g
37+ (y,g3) = randomR (0,x) g2
38+ in y : lengths ml g3
3939
4040nums :: StdGen -> [(Attr, String)]
4141nums g = let (x,g2) = (random g :: (Int, StdGen))
@@ -44,12 +44,12 @@ nums g = let (x,g2) = (random g :: (Int, StdGen))
4444 , shows x " "
4545 ) : nums g3
4646
47−pad :: Word -> Image -> Image
47+pad :: Int -> Image -> Image
4848pad ml img = img <|> char_fill def_attr ' ' (ml - image_width img) 1
4949
50−clines :: StdGen -> Word -> [Image]
50+clines :: StdGen -> Int -> [Image]
5151clines g maxll = map (pad maxll . horiz_cat . map (uncurry string))
52− $ fold (toEnum . length . snd) (lengths maxll g1) (nums g2)
52+ $ fold (length . snd) (lengths maxll g1) (nums g2)
5353 where (g1,g2) = split g
5454
5555benchgen :: DisplayRegion -> [Picture]
test/Verify/Graphics/Vty/Image.hs+2−2
@@ -51,7 +51,7 @@ instance Arbitrary SingleRowSingleAttrImage where
5151 -- The text must contain at least one character. Otherwise the image simplifies to the
5252 -- IdImage which has a height of 0. If this is to represent a single row then the height
5353 -- must be 1
54− single_column_row_text <- resize 128 (listOf1 arbitrary)
54+ single_column_row_text <- Verify.resize 128 (listOf1 arbitrary)
5555 a <- arbitrary
5656 return $ SingleRowSingleAttrImage
5757 a
@@ -81,7 +81,7 @@ data SingleAttrSingleSpanStack = SingleAttrSingleSpanStack
8181
8282instance Arbitrary SingleAttrSingleSpanStack where
8383 arbitrary = do
84− image_list <- resize 128 (listOf1 arbitrary)
84+ image_list <- Verify.resize 128 (listOf1 arbitrary)
8585 let image = vert_cat [ i | SingleRowSingleAttrImage { row_image = i } <- image_list ]
8686 return $ SingleAttrSingleSpanStack
8787 image