@@ -9,8 +9,6 @@
9module Graphics.Vty.Span
9module Graphics.Vty.Span
12−import Codec.Binary.UTF8.Width ( wcwidth )
14import Graphics.Vty.Image
12import Graphics.Vty.Image
15import Graphics.Vty.Picture
13import Graphics.Vty.Picture
16import Graphics.Vty.DisplayRegion
14import Graphics.Vty.DisplayRegion
@@ -25,9 +23,8 @@ import qualified Data.ByteString as B
25import qualified Data.ByteString.Internal as BInt
23import qualified Data.ByteString.Internal as BInt
26import qualified Data.Foldable as Foldable
24import qualified Data.Foldable as Foldable
27import Data.List
25import Data.List
29−import qualified Data.ByteString.UTF8 as BSUTF8
30import qualified Data.String.UTF8 as UTF8
26import qualified Data.String.UTF8 as UTF8
32import Foreign.Storable ( pokeByteOff )
29import Foreign.Storable ( pokeByteOff )
@@ -53,6 +50,14 @@ data SpanOpSequence = SpanOpSequence
53type RowOps = Array Word SpanOps
50type RowOps = Array Word SpanOps
54type SpanOps = [SpanOp]
51type SpanOps = [SpanOp]
53+instance Show SpanOpSequence where
54+ show (SpanOpSequence _ the_row_ops)
55+ = concat $ ["{ "] ++ map (\ops -> show ops ++ "; " ) (elems the_row_ops) ++ [" }"]
57+instance Show SpanOp where
58+ show (AttributeChange attr) = show attr
59+ show (TextSpan ow cw _) = "TextSpan " ++ show ow ++ " " ++ show cw
56span_ops_columns :: SpanOpSequence -> Word
61span_ops_columns :: SpanOpSequence -> Word
57span_ops_columns ops = region_width $ effected_region ops
62span_ops_columns ops = region_width $ effected_region ops
@@ -204,9 +209,8 @@ ops_for_row mrow_ops bg region image skip_dim@(skip_row,skip_col) y remaining_co
204 else empty_image
209 else empty_image
205 ops_for_row mrow_ops bg region ((i <|> hpad) <-> vpad) skip_dim y remaining_columns
210 ops_for_row mrow_ops bg region ((i <|> hpad) <-> vpad) skip_dim y remaining_columns
207−snoc_text_span :: (Foldable.Foldable t)
212+snoc_text_span :: Attr
208− => Attr
213+ -> DisplayString
210 -> MRowOps s
214 -> MRowOps s
@@ -215,30 +219,22 @@ snoc_text_span :: (Foldable.Foldable t)
215snoc_text_span a text_str mrow_ops skip_col y remaining_columns = do
219snoc_text_span a text_str mrow_ops skip_col y remaining_columns = do
216 snoc_op mrow_ops y $ AttributeChange a
220 snoc_op mrow_ops y $ AttributeChange a
217 let (ow', dw', cw', txt) = Foldable.foldl'
221 let (ow', dw', cw', txt) = Foldable.foldl'
218− build_cropped_txt
222+ build_text_span
219 ( 0, 0, 0, B.empty )
223 ( 0, 0, 0, B.empty )
221 snoc_op mrow_ops y $ TextSpan ow' cw' (UTF8.fromRep txt)
225 snoc_op mrow_ops y $ TextSpan ow' cw' (UTF8.fromRep txt)
222 return $ skip_col - dw'
226 return $ skip_col - dw'
224− build_cropped_txt (ow', dw', char_count', b0) c = {-# SCC "build_cropped_txt" #-}
228+ build_text_span (ow', dw', char_count', b0) (c,w) = {-# SCC "build_text_span" #-}
226− -- Characters with unknown widths occupy 1 column.
228− -- todo: Not sure if this is actually correct.
229− -- I presume there is a replacement character that is output by the terminal instead of
230− -- the character. If so then this replacement process may need to be implemented
231− -- manually for consistent behavior across terminals.
232− w' = toEnum $ if w < 0 then 1 else w
233− in if dw' == skip_col
229+ if dw' == skip_col
234 then if ow' == remaining_columns
230 then if ow' == remaining_columns
235 then ( ow', dw', char_count', b0 )
231 then ( ow', dw', char_count', b0 )
236− else if (w' + ow') > remaining_columns
232+ else if (w + ow') > remaining_columns
237 then ( remaining_columns, dw', char_count' + ooverflow, B.append b0 $ B.pack $ encode $ genericReplicate ooverflow '…' )
233 then ( remaining_columns, dw', char_count' + ooverflow, B.append b0 $ B.pack $ encode $ genericReplicate ooverflow '…' )
238− else ( ow' + w', dw', char_count' + 1, B.append b0 $ B.pack $ encode [c] )
234+ else ( ow' + w, dw', char_count' + 1, B.append b0 $ B.pack $ encode [c] )
239− else if (w' + dw') > skip_col
235+ else if (w + dw') > skip_col
240 then ( doverflow, skip_col, doverflow, B.append b0 $ B.pack $ encode $ genericReplicate doverflow '…' )
236 then ( doverflow, skip_col, doverflow, B.append b0 $ B.pack $ encode $ genericReplicate doverflow '…' )
241− else ( ow', w' + dw', char_count', b0 )
237+ else ( ow', w + dw', char_count', b0 )
243 doverflow = skip_col - dw'
239 doverflow = skip_col - dw'
244 ooverflow = remaining_columns - ow'
240 ooverflow = remaining_columns - ow'