@@ -16,7 +16,8 @@ import Graphics.Vty.DisplayRegion
1616import Codec.Binary.UTF8.String ( encode )
1717
1818import Control.Monad ( forM_ )
19−import Control.Monad.ST.Strict
19+import Control.Monad.ST.Strict hiding ( unsafeIOToST )
20+import Control.Monad.ST.Unsafe ( unsafeIOToST )
2021
2122import Data.Vector (Vector)
2223import qualified Data.Vector as Vector hiding ( take, replicate )
@@ -48,12 +49,15 @@ data DisplayOps = DisplayOps
4849 , display_ops :: RowOps
4950 }
5051
51−-- vector of span operation vectors. One per row of the screen.
52+-- | vector of span operation vectors. One per row of the screen.
5253type RowOps = Vector SpanOps
5354
5455type MRowOps s = MVector s SpanOps
5556
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
60+-- color is changed.
5761type SpanOps = Vector SpanOp
5862
5963type MSpanOps s = MVector s SpanOp
@@ -66,19 +70,23 @@ instance Show SpanOp where
6670 show (AttributeChange attr) = show attr
6771 show (TextSpan ow cw _) = "TextSpan " ++ show ow ++ " " ++ show cw
6872
73+-- | Number of columns the DisplayOps are defined for
6974span_ops_columns :: DisplayOps -> Word
7075span_ops_columns ops = region_width $ effected_region ops
7176
77+-- | Number of rows the DisplayOps are defined for
7278span_ops_rows :: DisplayOps -> Word
7379span_ops_rows ops = region_height $ effected_region ops
7480
81+-- | The number of columns a SpanOps effects.
7582span_ops_effected_columns :: SpanOps -> Word
7683span_ops_effected_columns in_ops = Vector.foldl' span_ops_effected_columns' 0 in_ops
7784 where
7885 span_ops_effected_columns' t (TextSpan w _ _ ) = t + w
7986 span_ops_effected_columns' t _ = t
8087
81−-- |
88+-- | This represents an operation on the terminal. Either an attribute change or the output of a
89+-- text string.
8290--
8391-- todo: This type may need to be restructured to increase sharing in the bytestring
8492--
@@ -91,12 +99,12 @@ data SpanOp =
9199 | TextSpan !Word !Word (UTF8.UTF8 B.ByteString)
92100 deriving Eq
93101
94−-- used to determine the width of a span operation , if it has one.
102+-- | The width of a single SpanOp in columns
95103span_op_has_width :: SpanOp -> Maybe (Word, Word)
96104span_op_has_width (TextSpan ow cw _) = Just (cw, ow)
97105span_op_has_width _ = Nothing
98106
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
100108columns_to_char_offset :: Word -> SpanOp -> Word
101109columns_to_char_offset cx (TextSpan _ _ utf8_str) =
102110 let str = UTF8.toString utf8_str