@@ -16,7 +16,8 @@ import Graphics.Vty.DisplayRegion
16import Codec.Binary.UTF8.String ( encode )
16import Codec.Binary.UTF8.String ( encode )
18import Control.Monad ( forM_ )
18import Control.Monad ( forM_ )
19−import Control.Monad.ST.Strict
19+import Control.Monad.ST.Strict hiding ( unsafeIOToST )
20+import Control.Monad.ST.Unsafe ( unsafeIOToST )
21import Data.Vector (Vector)
22import Data.Vector (Vector)
22import qualified Data.Vector as Vector hiding ( take, replicate )
23import qualified Data.Vector as Vector hiding ( take, replicate )
@@ -48,12 +49,15 @@ data DisplayOps = DisplayOps
48 , display_ops :: RowOps
49 , display_ops :: RowOps
51−-- vector of span operation vectors. One per row of the screen.
52+-- | vector of span operation vectors. One per row of the screen.
52type RowOps = Vector SpanOps
53type RowOps = Vector SpanOps
54type MRowOps s = MVector s SpanOps
55type MRowOps s = MVector s SpanOps
56−-- vector of span operations. executed in succession
57+-- | vector of span operations. executed in succession. This represents the operations required to
58+-- render a row of the terminal. The operations in one row may effect subsequent rows.
59+-- EG: Setting the foreground color in one row will effect all subsequent rows until the foreground
57type SpanOps = Vector SpanOp
61type SpanOps = Vector SpanOp
59type MSpanOps s = MVector s SpanOp
63type MSpanOps s = MVector s SpanOp
@@ -66,19 +70,23 @@ instance Show SpanOp where
66 show (AttributeChange attr) = show attr
70 show (AttributeChange attr) = show attr
67 show (TextSpan ow cw _) = "TextSpan " ++ show ow ++ " " ++ show cw
71 show (TextSpan ow cw _) = "TextSpan " ++ show ow ++ " " ++ show cw
73+-- | Number of columns the DisplayOps are defined for
69span_ops_columns :: DisplayOps -> Word
74span_ops_columns :: DisplayOps -> Word
70span_ops_columns ops = region_width $ effected_region ops
75span_ops_columns ops = region_width $ effected_region ops
77+-- | Number of rows the DisplayOps are defined for
72span_ops_rows :: DisplayOps -> Word
78span_ops_rows :: DisplayOps -> Word
73span_ops_rows ops = region_height $ effected_region ops
79span_ops_rows ops = region_height $ effected_region ops
81+-- | The number of columns a SpanOps effects.
75span_ops_effected_columns :: SpanOps -> Word
82span_ops_effected_columns :: SpanOps -> Word
76span_ops_effected_columns in_ops = Vector.foldl' span_ops_effected_columns' 0 in_ops
83span_ops_effected_columns in_ops = Vector.foldl' span_ops_effected_columns' 0 in_ops
78 span_ops_effected_columns' t (TextSpan w _ _ ) = t + w
85 span_ops_effected_columns' t (TextSpan w _ _ ) = t + w
79 span_ops_effected_columns' t _ = t
86 span_ops_effected_columns' t _ = t
81−-- |
88+-- | This represents an operation on the terminal. Either an attribute change or the output of a
83-- todo: This type may need to be restructured to increase sharing in the bytestring
91-- todo: This type may need to be restructured to increase sharing in the bytestring
@@ -91,12 +99,12 @@ data SpanOp =
91 | TextSpan !Word !Word (UTF8.UTF8 B.ByteString)
99 | TextSpan !Word !Word (UTF8.UTF8 B.ByteString)
92 deriving Eq
100 deriving Eq
94−-- used to determine the width of a span operation , if it has one.
102+-- | The width of a single SpanOp in columns
95span_op_has_width :: SpanOp -> Maybe (Word, Word)
103span_op_has_width :: SpanOp -> Maybe (Word, Word)
96span_op_has_width (TextSpan ow cw _) = Just (cw, ow)
104span_op_has_width (TextSpan ow cw _) = Just (cw, ow)
97span_op_has_width _ = Nothing
105span_op_has_width _ = Nothing
99−-- returns the number of columns to the character at the given position in the span op
107+-- | returns the number of columns to the character at the given position in the span op
100columns_to_char_offset :: Word -> SpanOp -> Word
108columns_to_char_offset :: Word -> SpanOp -> Word
101columns_to_char_offset cx (TextSpan _ _ utf8_str) =
109columns_to_char_offset cx (TextSpan _ _ utf8_str) =
102 let str = UTF8.toString utf8_str
110 let str = UTF8.toString utf8_str