@@ -215,7 +215,7 @@ instance DisplayTerminal DisplayContext where
215215 serialize_hide_cursor d out_ptr
216216 = liftIO $ serialize_cap_expression (civis $ term d) [] out_ptr
217217
218− -- Instead of evaluating all the rules related to setting display attributes twice (once in
218+ -- | Instead of evaluating all the rules related to setting display attributes twice (once in
219219 -- required bytes and again in serialize) or some memoization scheme just return a size
220220 -- requirement as big the longest possible control string.
221221 --
@@ -224,14 +224,16 @@ instance DisplayTerminal DisplayContext where
224224 -- \todo Not verified as safe and wastes memory.
225225 attr_required_bytes _d _prev_attr _req_attr _diffs = 512
226226
227− -- Portably setting the display attributes is a giant pain in the ass.
227+ -- | Portably setting the display attributes is a giant pain in the ass.
228+ --
228229 -- If the terminal supports the sgr capability (which sets the on/off state of each style
229− -- directly ; and, for no good reason, resets the colors to the default) this always works:
230+ -- directly ; and, for no good reason, resets the colors to the default) this procedure is used:
231+ --
230232 -- 0. set the style attributes. This resets the fore and back color.
231233 -- 1, If a foreground color is to be set then set the foreground color
232234 -- 2. likewise with the background color
233235 --
234− -- If the terminal does not support the sgr then
236+ -- If the terminal does not support the sgr cap then:
235237 -- if there is a change from an applied color to the default (in either the fore or back color)
236238 -- then:
237239 -- 0. reset all display attributes (sgr0)
@@ -242,7 +244,7 @@ instance DisplayTerminal DisplayContext where
242244 -- Entering the required style modes could require a reset of the display attributes. If this is
243245 -- the case then the back and fore colors always need to be set if not default.
244246 --
245− -- All this (I think) is satisfied by the following logic:
247+ -- This equation implements the above logic.
246248 serialize_set_attr d prev_attr req_attr diffs out_ptr = do
247249 case (fore_color_diff diffs == ColorToDefault) || (back_color_diff diffs == ColorToDefault) of
248250 -- The only way to reset either color, portably, to the default is to use either the set
@@ -321,11 +323,16 @@ instance DisplayTerminal DisplayContext where
321323 serialize_default_attr d out_ptr = do
322324 liftIO $ serialize_cap_expression ( set_default_attr $ term d ) [] out_ptr
323325
326+-- | The color table used by a terminal is a 16 color set followed by a 240 color set that might not
327+-- be supported by the terminal.
328+--
329+-- This takes a Color which clearly identifies which pallete to use and computes the index
330+-- into the full 256 color pallete.
324331ansi_color_index :: Color -> Word
325332ansi_color_index (ISOColor v) = toEnum $ fromEnum v
326333ansi_color_index (Color240 v) = 16 + ( toEnum $ fromEnum v )
327334
328−{- The sequence of terminfo caps to apply a given style are determined according to these rules.
335+{- | The sequence of terminfo caps to apply a given style are determined according to these rules.
329336 -
330337 - 1. The assumption is that it's preferable to use the simpler enter/exit mode capabilities than
331338 - the full set display attribute state capability.
@@ -340,7 +347,6 @@ ansi_color_index (Color240 v) = 16 + ( toEnum $ fromEnum v )
340347 - apply/remove.
341348 -
342349 -}
343−
344350data DisplayAttrSeq
345351 = EnterExitSeq [CapExpression]
346352 | SetState DisplayAttrState