/usr/share/doc/libghc-vty-doc/html/src/Graphics-Vty-Span.html is in libghc-vty-doc 4.7.0.10-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 | <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<!-- Generated by HsColour, http://code.haskell.org/~malcolm/hscolour/ -->
<title>src/Graphics/Vty/Span.hs</title>
<link type='text/css' rel='stylesheet' href='hscolour.css' />
</head>
<body>
<pre><a name="line-1"></a><span class='hs-comment'>-- Copyright 2009-2010 Corey O'Connor</span>
<a name="line-2"></a><span class='hs-comment'>{-# LANGUAGE BangPatterns #-}</span>
<a name="line-3"></a><span class='hs-comment'>{-# LANGUAGE ExistentialQuantification #-}</span>
<a name="line-4"></a><span class='hs-comment'>{-# LANGUAGE NamedFieldPuns #-}</span>
<a name="line-5"></a><span class='hs-comment'>{-# LANGUAGE GADTs #-}</span>
<a name="line-6"></a><span class='hs-comment'>{-# LANGUAGE ExistentialQuantification #-}</span>
<a name="line-7"></a><span class='hs-comment'>{-# LANGUAGE ScopedTypeVariables #-}</span>
<a name="line-8"></a><span class='hs-comment'>-- The ops to define the content for an output region. </span>
<a name="line-9"></a><span class='hs-keyword'>module</span> <span class='hs-conid'>Graphics</span><span class='hs-varop'>.</span><span class='hs-conid'>Vty</span><span class='hs-varop'>.</span><span class='hs-conid'>Span</span>
<a name="line-10"></a> <span class='hs-keyword'>where</span>
<a name="line-11"></a>
<a name="line-12"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Graphics</span><span class='hs-varop'>.</span><span class='hs-conid'>Vty</span><span class='hs-varop'>.</span><span class='hs-conid'>Image</span>
<a name="line-13"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Graphics</span><span class='hs-varop'>.</span><span class='hs-conid'>Vty</span><span class='hs-varop'>.</span><span class='hs-conid'>Picture</span>
<a name="line-14"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Graphics</span><span class='hs-varop'>.</span><span class='hs-conid'>Vty</span><span class='hs-varop'>.</span><span class='hs-conid'>DisplayRegion</span>
<a name="line-15"></a>
<a name="line-16"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Codec</span><span class='hs-varop'>.</span><span class='hs-conid'>Binary</span><span class='hs-varop'>.</span><span class='hs-conid'>UTF8</span><span class='hs-varop'>.</span><span class='hs-conid'>String</span> <span class='hs-layout'>(</span> <span class='hs-varid'>encode</span> <span class='hs-layout'>)</span>
<a name="line-17"></a>
<a name="line-18"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Control</span><span class='hs-varop'>.</span><span class='hs-conid'>Monad</span> <span class='hs-layout'>(</span> <span class='hs-varid'>forM_</span> <span class='hs-layout'>)</span>
<a name="line-19"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Control</span><span class='hs-varop'>.</span><span class='hs-conid'>Monad</span><span class='hs-varop'>.</span><span class='hs-conid'>ST</span><span class='hs-varop'>.</span><span class='hs-conid'>Strict</span>
<a name="line-20"></a>
<a name="line-21"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>Vector</span> <span class='hs-layout'>(</span><span class='hs-conid'>Vector</span><span class='hs-layout'>)</span>
<a name="line-22"></a><span class='hs-keyword'>import</span> <span class='hs-keyword'>qualified</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>Vector</span> <span class='hs-keyword'>as</span> <span class='hs-conid'>Vector</span> <span class='hs-varid'>hiding</span> <span class='hs-layout'>(</span> <span class='hs-varid'>take</span><span class='hs-layout'>,</span> <span class='hs-varid'>replicate</span> <span class='hs-layout'>)</span>
<a name="line-23"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>Vector</span><span class='hs-varop'>.</span><span class='hs-conid'>Mutable</span> <span class='hs-layout'>(</span> <span class='hs-conid'>MVector</span><span class='hs-layout'>(</span><span class='hs-keyglyph'>..</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span>
<a name="line-24"></a><span class='hs-keyword'>import</span> <span class='hs-keyword'>qualified</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>Vector</span><span class='hs-varop'>.</span><span class='hs-conid'>Mutable</span> <span class='hs-keyword'>as</span> <span class='hs-conid'>Vector</span>
<a name="line-25"></a>
<a name="line-26"></a><span class='hs-keyword'>import</span> <span class='hs-keyword'>qualified</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>ByteString</span> <span class='hs-keyword'>as</span> <span class='hs-conid'>B</span>
<a name="line-27"></a><span class='hs-keyword'>import</span> <span class='hs-keyword'>qualified</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>ByteString</span><span class='hs-varop'>.</span><span class='hs-conid'>Internal</span> <span class='hs-keyword'>as</span> <span class='hs-conid'>BInt</span>
<a name="line-28"></a><span class='hs-keyword'>import</span> <span class='hs-keyword'>qualified</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>Foldable</span> <span class='hs-keyword'>as</span> <span class='hs-conid'>Foldable</span>
<a name="line-29"></a><span class='hs-keyword'>import</span> <span class='hs-keyword'>qualified</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>String</span><span class='hs-varop'>.</span><span class='hs-conid'>UTF8</span> <span class='hs-keyword'>as</span> <span class='hs-conid'>UTF8</span>
<a name="line-30"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>Word</span>
<a name="line-31"></a>
<a name="line-32"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Foreign</span><span class='hs-varop'>.</span><span class='hs-conid'>Storable</span> <span class='hs-layout'>(</span> <span class='hs-varid'>pokeByteOff</span> <span class='hs-layout'>)</span>
<a name="line-33"></a>
<a name="line-34"></a><span class='hs-comment'>{- | A picture is translated into a sequences of state changes and character spans.
<a name="line-35"></a> - State changes are currently limited to new attribute values. The attribute is applied to all
<a name="line-36"></a> - following spans. Including spans of the next row. The nth element of the sequence represents the
<a name="line-37"></a> - nth row (from top to bottom) of the picture to render.
<a name="line-38"></a> -
<a name="line-39"></a> - A span op sequence will be defined for all rows and columns (and no more) of the region provided
<a name="line-40"></a> - with the picture to spans_for_pic.
<a name="line-41"></a> -
<a name="line-42"></a> - todo: Partition attribute changes into multiple categories according to the serialized
<a name="line-43"></a> - representation of the various attributes.
<a name="line-44"></a> -}</span>
<a name="line-45"></a>
<a name="line-46"></a><a name="DisplayOps"></a><span class='hs-keyword'>data</span> <span class='hs-conid'>DisplayOps</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>DisplayOps</span>
<a name="line-47"></a> <span class='hs-layout'>{</span> <span class='hs-varid'>effected_region</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>DisplayRegion</span>
<a name="line-48"></a> <span class='hs-layout'>,</span> <span class='hs-varid'>display_ops</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>RowOps</span>
<a name="line-49"></a> <span class='hs-layout'>}</span>
<a name="line-50"></a>
<a name="line-51"></a><a name="RowOps"></a><span class='hs-comment'>-- vector of span operation vectors. One per row of the screen.</span>
<a name="line-52"></a><a name="RowOps"></a><span class='hs-keyword'>type</span> <span class='hs-conid'>RowOps</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Vector</span> <span class='hs-conid'>SpanOps</span>
<a name="line-53"></a>
<a name="line-54"></a><a name="MRowOps"></a><span class='hs-keyword'>type</span> <span class='hs-conid'>MRowOps</span> <span class='hs-varid'>s</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>MVector</span> <span class='hs-varid'>s</span> <span class='hs-conid'>SpanOps</span>
<a name="line-55"></a>
<a name="line-56"></a><a name="SpanOps"></a><span class='hs-comment'>-- vector of span operations. executed in succession</span>
<a name="line-57"></a><a name="SpanOps"></a><span class='hs-keyword'>type</span> <span class='hs-conid'>SpanOps</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Vector</span> <span class='hs-conid'>SpanOp</span>
<a name="line-58"></a>
<a name="line-59"></a><a name="MSpanOps"></a><span class='hs-keyword'>type</span> <span class='hs-conid'>MSpanOps</span> <span class='hs-varid'>s</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>MVector</span> <span class='hs-varid'>s</span> <span class='hs-conid'>SpanOp</span>
<a name="line-60"></a>
<a name="line-61"></a><span class='hs-keyword'>instance</span> <span class='hs-conid'>Show</span> <span class='hs-conid'>DisplayOps</span> <span class='hs-keyword'>where</span>
<a name="line-62"></a> <span class='hs-varid'>show</span> <span class='hs-layout'>(</span><span class='hs-conid'>DisplayOps</span> <span class='hs-keyword'>_</span> <span class='hs-varid'>the_row_ops</span><span class='hs-layout'>)</span>
<a name="line-63"></a> <span class='hs-keyglyph'>=</span> <span class='hs-str'>"{ "</span> <span class='hs-varop'>++</span> <span class='hs-layout'>(</span><span class='hs-varid'>show</span> <span class='hs-varop'>$</span> <span class='hs-conid'>Vector</span><span class='hs-varop'>.</span><span class='hs-varid'>map</span> <span class='hs-layout'>(</span><span class='hs-keyglyph'>\</span><span class='hs-varid'>ops</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>show</span> <span class='hs-varid'>ops</span> <span class='hs-varop'>++</span> <span class='hs-str'>"; "</span> <span class='hs-layout'>)</span> <span class='hs-varid'>the_row_ops</span><span class='hs-layout'>)</span> <span class='hs-varop'>++</span> <span class='hs-str'>" }"</span>
<a name="line-64"></a>
<a name="line-65"></a><span class='hs-keyword'>instance</span> <span class='hs-conid'>Show</span> <span class='hs-conid'>SpanOp</span> <span class='hs-keyword'>where</span>
<a name="line-66"></a> <span class='hs-varid'>show</span> <span class='hs-layout'>(</span><span class='hs-conid'>AttributeChange</span> <span class='hs-varid'>attr</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>show</span> <span class='hs-varid'>attr</span>
<a name="line-67"></a> <span class='hs-varid'>show</span> <span class='hs-layout'>(</span><span class='hs-conid'>TextSpan</span> <span class='hs-varid'>ow</span> <span class='hs-varid'>cw</span> <span class='hs-keyword'>_</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-str'>"TextSpan "</span> <span class='hs-varop'>++</span> <span class='hs-varid'>show</span> <span class='hs-varid'>ow</span> <span class='hs-varop'>++</span> <span class='hs-str'>" "</span> <span class='hs-varop'>++</span> <span class='hs-varid'>show</span> <span class='hs-varid'>cw</span>
<a name="line-68"></a>
<a name="line-69"></a><a name="span_ops_columns"></a><span class='hs-definition'>span_ops_columns</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>DisplayOps</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Word</span>
<a name="line-70"></a><span class='hs-definition'>span_ops_columns</span> <span class='hs-varid'>ops</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>region_width</span> <span class='hs-varop'>$</span> <span class='hs-varid'>effected_region</span> <span class='hs-varid'>ops</span>
<a name="line-71"></a>
<a name="line-72"></a><a name="span_ops_rows"></a><span class='hs-definition'>span_ops_rows</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>DisplayOps</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Word</span>
<a name="line-73"></a><span class='hs-definition'>span_ops_rows</span> <span class='hs-varid'>ops</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>region_height</span> <span class='hs-varop'>$</span> <span class='hs-varid'>effected_region</span> <span class='hs-varid'>ops</span>
<a name="line-74"></a>
<a name="line-75"></a><a name="span_ops_effected_columns"></a><span class='hs-definition'>span_ops_effected_columns</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>SpanOps</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Word</span>
<a name="line-76"></a><span class='hs-definition'>span_ops_effected_columns</span> <span class='hs-varid'>in_ops</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Vector</span><span class='hs-varop'>.</span><span class='hs-varid'>foldl'</span> <span class='hs-varid'>span_ops_effected_columns'</span> <span class='hs-num'>0</span> <span class='hs-varid'>in_ops</span>
<a name="line-77"></a> <span class='hs-keyword'>where</span>
<a name="line-78"></a> <span class='hs-varid'>span_ops_effected_columns'</span> <span class='hs-varid'>t</span> <span class='hs-layout'>(</span><span class='hs-conid'>TextSpan</span> <span class='hs-varid'>w</span> <span class='hs-keyword'>_</span> <span class='hs-keyword'>_</span> <span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>t</span> <span class='hs-varop'>+</span> <span class='hs-varid'>w</span>
<a name="line-79"></a> <span class='hs-varid'>span_ops_effected_columns'</span> <span class='hs-varid'>t</span> <span class='hs-keyword'>_</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>t</span>
<a name="line-80"></a>
<a name="line-81"></a><a name="SpanOp"></a><span class='hs-comment'>-- |</span>
<a name="line-82"></a><a name="SpanOp"></a><span class='hs-comment'>-- </span>
<a name="line-83"></a><a name="SpanOp"></a><span class='hs-comment'>-- todo: This type may need to be restructured to increase sharing in the bytestring</span>
<a name="line-84"></a><a name="SpanOp"></a><span class='hs-comment'>-- </span>
<a name="line-85"></a><a name="SpanOp"></a><span class='hs-comment'>-- todo: Make foldable</span>
<a name="line-86"></a><a name="SpanOp"></a><span class='hs-keyword'>data</span> <span class='hs-conid'>SpanOp</span> <span class='hs-keyglyph'>=</span>
<a name="line-87"></a> <span class='hs-conid'>AttributeChange</span> <span class='hs-varop'>!</span><span class='hs-conid'>Attr</span>
<a name="line-88"></a> <span class='hs-comment'>-- | a span of UTF-8 text occupies a specific number of screen space columns. A single UTF</span>
<a name="line-89"></a> <span class='hs-comment'>-- character does not necessarially represent 1 colunm. See Codec.Binary.UTF8.Width</span>
<a name="line-90"></a> <span class='hs-comment'>-- TextSpan [output width in columns] [number of characters] [data]</span>
<a name="line-91"></a> <span class='hs-keyglyph'>|</span> <span class='hs-conid'>TextSpan</span> <span class='hs-varop'>!</span><span class='hs-conid'>Word</span> <span class='hs-varop'>!</span><span class='hs-conid'>Word</span> <span class='hs-layout'>(</span><span class='hs-conid'>UTF8</span><span class='hs-varop'>.</span><span class='hs-conid'>UTF8</span> <span class='hs-conid'>B</span><span class='hs-varop'>.</span><span class='hs-conid'>ByteString</span><span class='hs-layout'>)</span>
<a name="line-92"></a> <span class='hs-keyword'>deriving</span> <span class='hs-conid'>Eq</span>
<a name="line-93"></a>
<a name="line-94"></a><a name="span_op_has_width"></a><span class='hs-comment'>-- used to determine the width of a span operation , if it has one. </span>
<a name="line-95"></a><span class='hs-definition'>span_op_has_width</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>SpanOp</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Maybe</span> <span class='hs-layout'>(</span><span class='hs-conid'>Word</span><span class='hs-layout'>,</span> <span class='hs-conid'>Word</span><span class='hs-layout'>)</span>
<a name="line-96"></a><span class='hs-definition'>span_op_has_width</span> <span class='hs-layout'>(</span><span class='hs-conid'>TextSpan</span> <span class='hs-varid'>ow</span> <span class='hs-varid'>cw</span> <span class='hs-keyword'>_</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Just</span> <span class='hs-layout'>(</span><span class='hs-varid'>cw</span><span class='hs-layout'>,</span> <span class='hs-varid'>ow</span><span class='hs-layout'>)</span>
<a name="line-97"></a><span class='hs-definition'>span_op_has_width</span> <span class='hs-keyword'>_</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Nothing</span>
<a name="line-98"></a>
<a name="line-99"></a><a name="columns_to_char_offset"></a><span class='hs-comment'>-- returns the number of columns to the character at the given position in the span op</span>
<a name="line-100"></a><span class='hs-definition'>columns_to_char_offset</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Word</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>SpanOp</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Word</span>
<a name="line-101"></a><span class='hs-definition'>columns_to_char_offset</span> <span class='hs-varid'>cx</span> <span class='hs-layout'>(</span><span class='hs-conid'>TextSpan</span> <span class='hs-keyword'>_</span> <span class='hs-keyword'>_</span> <span class='hs-varid'>utf8_str</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span>
<a name="line-102"></a> <span class='hs-keyword'>let</span> <span class='hs-varid'>str</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>UTF8</span><span class='hs-varop'>.</span><span class='hs-varid'>toString</span> <span class='hs-varid'>utf8_str</span>
<a name="line-103"></a> <span class='hs-keyword'>in</span> <span class='hs-varid'>toEnum</span> <span class='hs-varop'>$!</span> <span class='hs-varid'>sum</span> <span class='hs-varop'>$!</span> <span class='hs-varid'>map</span> <span class='hs-varid'>wcwidth</span> <span class='hs-varop'>$!</span> <span class='hs-varid'>take</span> <span class='hs-layout'>(</span><span class='hs-varid'>fromEnum</span> <span class='hs-varid'>cx</span><span class='hs-layout'>)</span> <span class='hs-varid'>str</span>
<a name="line-104"></a><span class='hs-definition'>columns_to_char_offset</span> <span class='hs-sel'>_cx</span> <span class='hs-keyword'>_</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>error</span> <span class='hs-str'>"columns_to_char_offset applied to span op without width"</span>
<a name="line-105"></a>
<a name="line-106"></a><a name="spans_for_pic"></a><span class='hs-comment'>-- | Produces the span ops that will render the given picture, possibly cropped or padded, into the</span>
<a name="line-107"></a><span class='hs-comment'>-- specified region.</span>
<a name="line-108"></a><span class='hs-definition'>spans_for_pic</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Picture</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>DisplayRegion</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>DisplayOps</span>
<a name="line-109"></a><span class='hs-definition'>spans_for_pic</span> <span class='hs-varid'>pic</span> <span class='hs-varid'>r</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>DisplayOps</span> <span class='hs-varid'>r</span> <span class='hs-varop'>$</span> <span class='hs-conid'>Vector</span><span class='hs-varop'>.</span><span class='hs-varid'>create</span> <span class='hs-layout'>(</span><span class='hs-varid'>build_spans</span> <span class='hs-varid'>pic</span> <span class='hs-varid'>r</span><span class='hs-layout'>)</span>
<a name="line-110"></a>
<a name="line-111"></a><a name="build_spans"></a><span class='hs-definition'>build_spans</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Picture</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>DisplayRegion</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>ST</span> <span class='hs-varid'>s</span> <span class='hs-layout'>(</span><span class='hs-conid'>MRowOps</span> <span class='hs-varid'>s</span><span class='hs-layout'>)</span>
<a name="line-112"></a><span class='hs-definition'>build_spans</span> <span class='hs-varid'>pic</span> <span class='hs-varid'>region</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>do</span>
<a name="line-113"></a> <span class='hs-comment'>-- m for mutable! ;-)</span>
<a name="line-114"></a> <span class='hs-varid'>mrow_ops</span> <span class='hs-keyglyph'><-</span> <span class='hs-conid'>Vector</span><span class='hs-varop'>.</span><span class='hs-varid'>replicate</span> <span class='hs-layout'>(</span><span class='hs-varid'>fromEnum</span> <span class='hs-varop'>$</span> <span class='hs-varid'>region_height</span> <span class='hs-varid'>region</span><span class='hs-layout'>)</span> <span class='hs-conid'>Vector</span><span class='hs-varop'>.</span><span class='hs-varid'>empty</span>
<a name="line-115"></a> <span class='hs-comment'>-- XXX: I think building the span operations in display order would provide better performance.</span>
<a name="line-116"></a> <span class='hs-comment'>-- However, I got stuck trying to implement an algorithm that did this. This will be considered</span>
<a name="line-117"></a> <span class='hs-comment'>-- as a possible future optimization. </span>
<a name="line-118"></a> <span class='hs-comment'>--</span>
<a name="line-119"></a> <span class='hs-comment'>-- A depth first traversal of the image is performed. ordered according to the column range</span>
<a name="line-120"></a> <span class='hs-comment'>-- defined by the image from least to greatest. The output row ops will at least have the</span>
<a name="line-121"></a> <span class='hs-comment'>-- region of the image specified. Iterate over all output rows and output background fills for</span>
<a name="line-122"></a> <span class='hs-comment'>-- all unspecified columns.</span>
<a name="line-123"></a> <span class='hs-comment'>--</span>
<a name="line-124"></a> <span class='hs-comment'>-- The images are made into span operations from left to right. It's possible that this could</span>
<a name="line-125"></a> <span class='hs-comment'>-- easily be made to assure top to bottom output as well. </span>
<a name="line-126"></a> <span class='hs-keyword'>if</span> <span class='hs-varid'>region_height</span> <span class='hs-varid'>region</span> <span class='hs-varop'>></span> <span class='hs-num'>0</span>
<a name="line-127"></a> <span class='hs-keyword'>then</span> <span class='hs-keyword'>do</span>
<a name="line-128"></a> <span class='hs-comment'>-- The ops builder recursively descends the image and outputs span ops that would</span>
<a name="line-129"></a> <span class='hs-comment'>-- display that image. The number of columns remaining in this row before exceeding the</span>
<a name="line-130"></a> <span class='hs-comment'>-- bounds is also provided. This is used to clip the span ops produced to the display.</span>
<a name="line-131"></a> <span class='hs-comment'>-- The skip dimensions provided do....???</span>
<a name="line-132"></a> <span class='hs-keyword'>_</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>row_ops_for_image</span> <span class='hs-varid'>mrow_ops</span>
<a name="line-133"></a> <span class='hs-layout'>(</span><span class='hs-varid'>pic_image</span> <span class='hs-varid'>pic</span><span class='hs-layout'>)</span>
<a name="line-134"></a> <span class='hs-layout'>(</span><span class='hs-varid'>pic_background</span> <span class='hs-varid'>pic</span><span class='hs-layout'>)</span>
<a name="line-135"></a> <span class='hs-varid'>region</span>
<a name="line-136"></a> <span class='hs-layout'>(</span><span class='hs-num'>0</span><span class='hs-layout'>,</span><span class='hs-num'>0</span><span class='hs-layout'>)</span>
<a name="line-137"></a> <span class='hs-num'>0</span>
<a name="line-138"></a> <span class='hs-layout'>(</span><span class='hs-varid'>region_width</span> <span class='hs-varid'>region</span><span class='hs-layout'>)</span>
<a name="line-139"></a> <span class='hs-layout'>(</span><span class='hs-varid'>fromEnum</span> <span class='hs-varop'>$</span> <span class='hs-varid'>region_height</span> <span class='hs-varid'>region</span><span class='hs-layout'>)</span>
<a name="line-140"></a> <span class='hs-comment'>-- Fill in any unspecified columns with the background pattern.</span>
<a name="line-141"></a> <span class='hs-varid'>forM_</span> <span class='hs-keyglyph'>[</span><span class='hs-num'>0</span> <span class='hs-keyglyph'>..</span> <span class='hs-layout'>(</span><span class='hs-varid'>fromEnum</span> <span class='hs-varop'>$</span> <span class='hs-varid'>region_height</span> <span class='hs-varid'>region</span> <span class='hs-comment'>-</span> <span class='hs-num'>1</span><span class='hs-layout'>)</span><span class='hs-keyglyph'>]</span> <span class='hs-varop'>$!</span> <span class='hs-keyglyph'>\</span><span class='hs-varid'>row</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyword'>do</span>
<a name="line-142"></a> <span class='hs-varid'>end_x</span> <span class='hs-keyglyph'><-</span> <span class='hs-conid'>Vector</span><span class='hs-varop'>.</span><span class='hs-varid'>read</span> <span class='hs-varid'>mrow_ops</span> <span class='hs-varid'>row</span> <span class='hs-varop'>>>=</span> <span class='hs-varid'>return</span> <span class='hs-varop'>.</span> <span class='hs-varid'>span_ops_effected_columns</span>
<a name="line-143"></a> <span class='hs-keyword'>if</span> <span class='hs-varid'>end_x</span> <span class='hs-varop'><</span> <span class='hs-varid'>region_width</span> <span class='hs-varid'>region</span>
<a name="line-144"></a> <span class='hs-keyword'>then</span> <span class='hs-varid'>snoc_bg_fill</span> <span class='hs-varid'>mrow_ops</span> <span class='hs-layout'>(</span><span class='hs-varid'>pic_background</span> <span class='hs-varid'>pic</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span><span class='hs-varid'>region_width</span> <span class='hs-varid'>region</span> <span class='hs-comment'>-</span> <span class='hs-varid'>end_x</span><span class='hs-layout'>)</span> <span class='hs-varid'>row</span>
<a name="line-145"></a> <span class='hs-keyword'>else</span> <span class='hs-varid'>return</span> <span class='hs-conid'>()</span>
<a name="line-146"></a> <span class='hs-keyword'>else</span> <span class='hs-varid'>return</span> <span class='hs-conid'>()</span>
<a name="line-147"></a> <span class='hs-varid'>return</span> <span class='hs-varid'>mrow_ops</span>
<a name="line-148"></a>
<a name="line-149"></a><a name="row_ops_for_image"></a><span class='hs-definition'>row_ops_for_image</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>MRowOps</span> <span class='hs-varid'>s</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Image</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Background</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>DisplayRegion</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-conid'>Word</span><span class='hs-layout'>,</span> <span class='hs-conid'>Word</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Int</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Word</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Int</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>ST</span> <span class='hs-varid'>s</span> <span class='hs-layout'>(</span><span class='hs-conid'>Word</span><span class='hs-layout'>,</span> <span class='hs-conid'>Word</span><span class='hs-layout'>)</span>
<a name="line-150"></a><span class='hs-definition'>row_ops_for_image</span> <span class='hs-varid'>mrow_ops</span> <span class='hs-comment'>-- the image to output the ops to</span>
<a name="line-151"></a> <span class='hs-varid'>image</span> <span class='hs-comment'>-- the image to rasterize in column order to mrow_ops</span>
<a name="line-152"></a> <span class='hs-varid'>bg</span> <span class='hs-comment'>-- the background fill</span>
<a name="line-153"></a> <span class='hs-varid'>region</span> <span class='hs-comment'>-- ???</span>
<a name="line-154"></a> <span class='hs-varid'>skip_dim</span><span class='hs-keyglyph'>@</span><span class='hs-layout'>(</span><span class='hs-varid'>skip_row</span><span class='hs-layout'>,</span><span class='hs-varid'>skip_col</span><span class='hs-layout'>)</span> <span class='hs-comment'>-- the number of rows </span>
<a name="line-155"></a> <span class='hs-varid'>y</span> <span class='hs-comment'>-- ???</span>
<a name="line-156"></a> <span class='hs-varid'>remaining_columns</span> <span class='hs-comment'>-- ???</span>
<a name="line-157"></a> <span class='hs-varid'>remain_rows</span>
<a name="line-158"></a> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>remaining_columns</span> <span class='hs-varop'>==</span> <span class='hs-num'>0</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>return</span> <span class='hs-varid'>skip_dim</span>
<a name="line-159"></a> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>remain_rows</span> <span class='hs-varop'>==</span> <span class='hs-num'>0</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>return</span> <span class='hs-varid'>skip_dim</span>
<a name="line-160"></a> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>y</span> <span class='hs-varop'>>=</span> <span class='hs-varid'>fromEnum</span> <span class='hs-layout'>(</span><span class='hs-varid'>region_height</span> <span class='hs-varid'>region</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>return</span> <span class='hs-varid'>skip_dim</span>
<a name="line-161"></a> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>otherwise</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>case</span> <span class='hs-varid'>image</span> <span class='hs-keyword'>of</span>
<a name="line-162"></a> <span class='hs-conid'>EmptyImage</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>return</span> <span class='hs-varid'>skip_dim</span>
<a name="line-163"></a> <span class='hs-comment'>-- The width provided is the number of columns this text span will occupy when displayed.</span>
<a name="line-164"></a> <span class='hs-comment'>-- if this is greater than the number of remaining columsn the output has to be produced a</span>
<a name="line-165"></a> <span class='hs-comment'>-- character at a time.</span>
<a name="line-166"></a> <span class='hs-conid'>HorizText</span> <span class='hs-varid'>a</span> <span class='hs-varid'>text_str</span> <span class='hs-keyword'>_</span> <span class='hs-keyword'>_</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyword'>do</span>
<a name="line-167"></a> <span class='hs-keyword'>if</span> <span class='hs-varid'>skip_row</span> <span class='hs-varop'>></span> <span class='hs-num'>0</span>
<a name="line-168"></a> <span class='hs-keyword'>then</span> <span class='hs-varid'>return</span> <span class='hs-layout'>(</span><span class='hs-varid'>skip_row</span> <span class='hs-comment'>-</span> <span class='hs-num'>1</span><span class='hs-layout'>,</span> <span class='hs-varid'>skip_col</span><span class='hs-layout'>)</span>
<a name="line-169"></a> <span class='hs-keyword'>else</span> <span class='hs-keyword'>do</span>
<a name="line-170"></a> <span class='hs-varid'>skip_col'</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>snoc_text_span</span> <span class='hs-varid'>a</span> <span class='hs-varid'>text_str</span> <span class='hs-varid'>mrow_ops</span> <span class='hs-varid'>skip_col</span> <span class='hs-varid'>y</span> <span class='hs-varid'>remaining_columns</span>
<a name="line-171"></a> <span class='hs-varid'>return</span> <span class='hs-layout'>(</span><span class='hs-varid'>skip_row</span><span class='hs-layout'>,</span> <span class='hs-varid'>skip_col'</span><span class='hs-layout'>)</span>
<a name="line-172"></a> <span class='hs-conid'>VertJoin</span> <span class='hs-varid'>top_image</span> <span class='hs-varid'>bottom_image</span> <span class='hs-keyword'>_</span> <span class='hs-keyword'>_</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyword'>do</span>
<a name="line-173"></a> <span class='hs-layout'>(</span><span class='hs-varid'>skip_row'</span><span class='hs-layout'>,</span><span class='hs-varid'>skip_col'</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>row_ops_for_image</span> <span class='hs-varid'>mrow_ops</span>
<a name="line-174"></a> <span class='hs-varid'>top_image</span>
<a name="line-175"></a> <span class='hs-varid'>bg</span>
<a name="line-176"></a> <span class='hs-varid'>region</span>
<a name="line-177"></a> <span class='hs-varid'>skip_dim</span>
<a name="line-178"></a> <span class='hs-varid'>y</span>
<a name="line-179"></a> <span class='hs-varid'>remaining_columns</span>
<a name="line-180"></a> <span class='hs-varid'>remain_rows</span>
<a name="line-181"></a> <span class='hs-keyword'>let</span> <span class='hs-varid'>top_height</span> <span class='hs-keyglyph'>=</span> <span class='hs-layout'>(</span><span class='hs-varid'>fromEnum</span> <span class='hs-varop'>$!</span> <span class='hs-varid'>image_height</span> <span class='hs-varid'>top_image</span><span class='hs-layout'>)</span> <span class='hs-comment'>-</span> <span class='hs-layout'>(</span><span class='hs-varid'>fromEnum</span> <span class='hs-varop'>$!</span> <span class='hs-varid'>skip_row</span> <span class='hs-comment'>-</span> <span class='hs-varid'>skip_row'</span><span class='hs-layout'>)</span>
<a name="line-182"></a> <span class='hs-layout'>(</span><span class='hs-varid'>skip_row''</span><span class='hs-layout'>,</span><span class='hs-varid'>skip_col''</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>row_ops_for_image</span> <span class='hs-varid'>mrow_ops</span>
<a name="line-183"></a> <span class='hs-varid'>bottom_image</span>
<a name="line-184"></a> <span class='hs-varid'>bg</span>
<a name="line-185"></a> <span class='hs-varid'>region</span>
<a name="line-186"></a> <span class='hs-layout'>(</span><span class='hs-varid'>skip_row'</span><span class='hs-layout'>,</span> <span class='hs-varid'>skip_col</span><span class='hs-layout'>)</span>
<a name="line-187"></a> <span class='hs-layout'>(</span><span class='hs-varid'>y</span> <span class='hs-varop'>+</span> <span class='hs-varid'>top_height</span><span class='hs-layout'>)</span>
<a name="line-188"></a> <span class='hs-varid'>remaining_columns</span>
<a name="line-189"></a> <span class='hs-layout'>(</span><span class='hs-varid'>remain_rows</span> <span class='hs-comment'>-</span> <span class='hs-varid'>top_height</span><span class='hs-layout'>)</span>
<a name="line-190"></a> <span class='hs-varid'>return</span> <span class='hs-layout'>(</span><span class='hs-varid'>skip_row''</span><span class='hs-layout'>,</span> <span class='hs-varid'>min</span> <span class='hs-varid'>skip_col'</span> <span class='hs-varid'>skip_col''</span><span class='hs-layout'>)</span>
<a name="line-191"></a> <span class='hs-conid'>HorizJoin</span> <span class='hs-varid'>l</span> <span class='hs-varid'>r</span> <span class='hs-keyword'>_</span> <span class='hs-keyword'>_</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyword'>do</span>
<a name="line-192"></a> <span class='hs-layout'>(</span><span class='hs-varid'>skip_row'</span><span class='hs-layout'>,</span><span class='hs-varid'>skip_col'</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>row_ops_for_image</span> <span class='hs-varid'>mrow_ops</span> <span class='hs-varid'>l</span> <span class='hs-varid'>bg</span> <span class='hs-varid'>region</span> <span class='hs-varid'>skip_dim</span> <span class='hs-varid'>y</span> <span class='hs-varid'>remaining_columns</span> <span class='hs-varid'>remain_rows</span>
<a name="line-193"></a> <span class='hs-comment'>-- Don't output the right part unless there is at least a single column left after</span>
<a name="line-194"></a> <span class='hs-comment'>-- outputting the left part.</span>
<a name="line-195"></a> <span class='hs-keyword'>if</span> <span class='hs-varid'>image_width</span> <span class='hs-varid'>l</span> <span class='hs-comment'>-</span> <span class='hs-layout'>(</span><span class='hs-varid'>skip_col</span> <span class='hs-comment'>-</span> <span class='hs-varid'>skip_col'</span><span class='hs-layout'>)</span> <span class='hs-varop'>></span> <span class='hs-varid'>remaining_columns</span>
<a name="line-196"></a> <span class='hs-keyword'>then</span> <span class='hs-varid'>return</span> <span class='hs-layout'>(</span><span class='hs-varid'>skip_row</span><span class='hs-layout'>,</span><span class='hs-varid'>skip_col'</span><span class='hs-layout'>)</span>
<a name="line-197"></a> <span class='hs-keyword'>else</span> <span class='hs-keyword'>do</span>
<a name="line-198"></a> <span class='hs-layout'>(</span><span class='hs-varid'>skip_row''</span><span class='hs-layout'>,</span><span class='hs-varid'>skip_col''</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>row_ops_for_image</span> <span class='hs-varid'>mrow_ops</span> <span class='hs-varid'>r</span> <span class='hs-varid'>bg</span> <span class='hs-varid'>region</span> <span class='hs-layout'>(</span><span class='hs-varid'>skip_row</span><span class='hs-layout'>,</span> <span class='hs-varid'>skip_col'</span><span class='hs-layout'>)</span> <span class='hs-varid'>y</span> <span class='hs-layout'>(</span><span class='hs-varid'>remaining_columns</span> <span class='hs-comment'>-</span> <span class='hs-varid'>image_width</span> <span class='hs-varid'>l</span> <span class='hs-varop'>+</span> <span class='hs-layout'>(</span><span class='hs-varid'>skip_col</span> <span class='hs-comment'>-</span> <span class='hs-varid'>skip_col'</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span> <span class='hs-varid'>remain_rows</span>
<a name="line-199"></a> <span class='hs-varid'>return</span> <span class='hs-layout'>(</span><span class='hs-varid'>min</span> <span class='hs-varid'>skip_row'</span> <span class='hs-varid'>skip_row''</span><span class='hs-layout'>,</span> <span class='hs-varid'>skip_col''</span><span class='hs-layout'>)</span>
<a name="line-200"></a> <span class='hs-conid'>BGFill</span> <span class='hs-varid'>width</span> <span class='hs-varid'>height</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyword'>do</span>
<a name="line-201"></a> <span class='hs-keyword'>let</span> <span class='hs-varid'>min_height</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>if</span> <span class='hs-varid'>y</span> <span class='hs-varop'>+</span> <span class='hs-layout'>(</span><span class='hs-varid'>fromEnum</span> <span class='hs-varid'>height</span><span class='hs-layout'>)</span> <span class='hs-varop'>></span> <span class='hs-layout'>(</span><span class='hs-varid'>fromEnum</span> <span class='hs-varop'>$!</span> <span class='hs-varid'>region_height</span> <span class='hs-varid'>region</span><span class='hs-layout'>)</span>
<a name="line-202"></a> <span class='hs-keyword'>then</span> <span class='hs-varid'>region_height</span> <span class='hs-varid'>region</span> <span class='hs-comment'>-</span> <span class='hs-layout'>(</span><span class='hs-varid'>toEnum</span> <span class='hs-varid'>y</span><span class='hs-layout'>)</span>
<a name="line-203"></a> <span class='hs-keyword'>else</span> <span class='hs-varid'>min</span> <span class='hs-varid'>height</span> <span class='hs-layout'>(</span><span class='hs-varid'>toEnum</span> <span class='hs-varid'>remain_rows</span><span class='hs-layout'>)</span>
<a name="line-204"></a> <span class='hs-varid'>min_width</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>min</span> <span class='hs-varid'>width</span> <span class='hs-varid'>remaining_columns</span>
<a name="line-205"></a> <span class='hs-varid'>actual_height</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>if</span> <span class='hs-varid'>skip_row</span> <span class='hs-varop'>></span> <span class='hs-varid'>min_height</span>
<a name="line-206"></a> <span class='hs-keyword'>then</span> <span class='hs-num'>0</span>
<a name="line-207"></a> <span class='hs-keyword'>else</span> <span class='hs-varid'>min_height</span> <span class='hs-comment'>-</span> <span class='hs-varid'>skip_row</span>
<a name="line-208"></a> <span class='hs-varid'>actual_width</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>if</span> <span class='hs-varid'>skip_col</span> <span class='hs-varop'>></span> <span class='hs-varid'>min_width</span>
<a name="line-209"></a> <span class='hs-keyword'>then</span> <span class='hs-num'>0</span>
<a name="line-210"></a> <span class='hs-keyword'>else</span> <span class='hs-varid'>min_width</span> <span class='hs-comment'>-</span> <span class='hs-varid'>skip_col</span>
<a name="line-211"></a> <span class='hs-varid'>forM_</span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>y</span> <span class='hs-keyglyph'>..</span> <span class='hs-varid'>y</span> <span class='hs-varop'>+</span> <span class='hs-varid'>fromEnum</span> <span class='hs-varid'>actual_height</span> <span class='hs-comment'>-</span> <span class='hs-num'>1</span><span class='hs-keyglyph'>]</span> <span class='hs-varop'>$!</span> <span class='hs-keyglyph'>\</span><span class='hs-varid'>y'</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>snoc_bg_fill</span> <span class='hs-varid'>mrow_ops</span> <span class='hs-varid'>bg</span> <span class='hs-varid'>actual_width</span> <span class='hs-varid'>y'</span>
<a name="line-212"></a> <span class='hs-keyword'>let</span> <span class='hs-varid'>skip_row'</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>if</span> <span class='hs-varid'>actual_height</span> <span class='hs-varop'>></span> <span class='hs-varid'>skip_row</span>
<a name="line-213"></a> <span class='hs-keyword'>then</span> <span class='hs-num'>0</span>
<a name="line-214"></a> <span class='hs-keyword'>else</span> <span class='hs-varid'>skip_row</span> <span class='hs-comment'>-</span> <span class='hs-varid'>min_height</span>
<a name="line-215"></a> <span class='hs-varid'>skip_col'</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>if</span> <span class='hs-varid'>actual_width</span> <span class='hs-varop'>></span> <span class='hs-varid'>skip_col</span>
<a name="line-216"></a> <span class='hs-keyword'>then</span> <span class='hs-num'>0</span>
<a name="line-217"></a> <span class='hs-keyword'>else</span> <span class='hs-varid'>skip_col</span> <span class='hs-comment'>-</span> <span class='hs-varid'>min_width</span>
<a name="line-218"></a> <span class='hs-varid'>return</span> <span class='hs-layout'>(</span><span class='hs-varid'>skip_row'</span><span class='hs-layout'>,</span><span class='hs-varid'>skip_col'</span><span class='hs-layout'>)</span>
<a name="line-219"></a> <span class='hs-conid'>Translation</span> <span class='hs-layout'>(</span><span class='hs-varid'>dx</span><span class='hs-layout'>,</span><span class='hs-varid'>dy</span><span class='hs-layout'>)</span> <span class='hs-varid'>i</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyword'>do</span>
<a name="line-220"></a> <span class='hs-keyword'>if</span> <span class='hs-varid'>dx</span> <span class='hs-varop'><</span> <span class='hs-num'>0</span>
<a name="line-221"></a> <span class='hs-comment'>-- Translation left</span>
<a name="line-222"></a> <span class='hs-comment'>-- Extract the delta and add it to skip_col.</span>
<a name="line-223"></a> <span class='hs-keyword'>then</span> <span class='hs-varid'>row_ops_for_image</span> <span class='hs-varid'>mrow_ops</span> <span class='hs-layout'>(</span><span class='hs-varid'>translate</span> <span class='hs-layout'>(</span><span class='hs-num'>0</span><span class='hs-layout'>,</span> <span class='hs-varid'>dy</span><span class='hs-layout'>)</span> <span class='hs-varid'>i</span><span class='hs-layout'>)</span> <span class='hs-varid'>bg</span> <span class='hs-varid'>region</span> <span class='hs-layout'>(</span><span class='hs-varid'>skip_row</span><span class='hs-layout'>,</span> <span class='hs-varid'>skip_col</span> <span class='hs-varop'>+</span> <span class='hs-varid'>dw</span><span class='hs-layout'>)</span> <span class='hs-varid'>y</span> <span class='hs-varid'>remaining_columns</span> <span class='hs-varid'>remain_rows</span>
<a name="line-224"></a> <span class='hs-comment'>-- Translation right</span>
<a name="line-225"></a> <span class='hs-keyword'>else</span> <span class='hs-keyword'>if</span> <span class='hs-varid'>dy</span> <span class='hs-varop'><</span> <span class='hs-num'>0</span>
<a name="line-226"></a> <span class='hs-comment'>-- Translation up</span>
<a name="line-227"></a> <span class='hs-comment'>-- Extract the delta and add it to skip_row.</span>
<a name="line-228"></a> <span class='hs-keyword'>then</span> <span class='hs-varid'>row_ops_for_image</span> <span class='hs-varid'>mrow_ops</span> <span class='hs-layout'>(</span><span class='hs-varid'>translate</span> <span class='hs-layout'>(</span><span class='hs-varid'>dx</span><span class='hs-layout'>,</span> <span class='hs-num'>0</span><span class='hs-layout'>)</span> <span class='hs-varid'>i</span><span class='hs-layout'>)</span> <span class='hs-varid'>bg</span> <span class='hs-varid'>region</span> <span class='hs-layout'>(</span><span class='hs-varid'>skip_row</span> <span class='hs-varop'>+</span> <span class='hs-varid'>dh</span><span class='hs-layout'>,</span> <span class='hs-varid'>skip_col</span><span class='hs-layout'>)</span> <span class='hs-varid'>y</span> <span class='hs-varid'>remaining_columns</span> <span class='hs-varid'>remain_rows</span>
<a name="line-229"></a> <span class='hs-comment'>-- Translation down</span>
<a name="line-230"></a> <span class='hs-comment'>-- Pad the start of lines and above the image with a</span>
<a name="line-231"></a> <span class='hs-comment'>-- background_fill image</span>
<a name="line-232"></a> <span class='hs-keyword'>else</span> <span class='hs-varid'>row_ops_for_image</span> <span class='hs-varid'>mrow_ops</span> <span class='hs-layout'>(</span><span class='hs-varid'>background_fill</span> <span class='hs-varid'>ow</span> <span class='hs-varid'>dh</span> <span class='hs-varop'><-></span> <span class='hs-layout'>(</span><span class='hs-varid'>background_fill</span> <span class='hs-varid'>dw</span> <span class='hs-varid'>ih</span> <span class='hs-varop'><|></span> <span class='hs-varid'>i</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span> <span class='hs-varid'>bg</span> <span class='hs-varid'>region</span> <span class='hs-varid'>skip_dim</span> <span class='hs-varid'>y</span> <span class='hs-varid'>remaining_columns</span> <span class='hs-varid'>remain_rows</span>
<a name="line-233"></a> <span class='hs-keyword'>where</span>
<a name="line-234"></a> <span class='hs-varid'>dw</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>toEnum</span> <span class='hs-varop'>$</span> <span class='hs-varid'>abs</span> <span class='hs-varid'>dx</span>
<a name="line-235"></a> <span class='hs-varid'>dh</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>toEnum</span> <span class='hs-varop'>$</span> <span class='hs-varid'>abs</span> <span class='hs-varid'>dy</span>
<a name="line-236"></a> <span class='hs-varid'>ow</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>image_width</span> <span class='hs-varid'>image</span>
<a name="line-237"></a> <span class='hs-varid'>ih</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>image_height</span> <span class='hs-varid'>i</span>
<a name="line-238"></a> <span class='hs-conid'>ImageCrop</span> <span class='hs-layout'>(</span><span class='hs-varid'>max_w</span><span class='hs-layout'>,</span><span class='hs-varid'>max_h</span><span class='hs-layout'>)</span> <span class='hs-varid'>i</span> <span class='hs-keyglyph'>-></span>
<a name="line-239"></a> <span class='hs-varid'>row_ops_for_image</span> <span class='hs-varid'>mrow_ops</span> <span class='hs-varid'>i</span> <span class='hs-varid'>bg</span> <span class='hs-varid'>region</span> <span class='hs-varid'>skip_dim</span> <span class='hs-varid'>y</span> <span class='hs-layout'>(</span><span class='hs-varid'>min</span> <span class='hs-varid'>remaining_columns</span> <span class='hs-varid'>max_w</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span><span class='hs-varid'>min</span> <span class='hs-varid'>remain_rows</span> <span class='hs-varop'>$</span> <span class='hs-varid'>fromEnum</span> <span class='hs-varid'>max_h</span><span class='hs-layout'>)</span>
<a name="line-240"></a> <span class='hs-conid'>ImagePad</span> <span class='hs-layout'>(</span><span class='hs-varid'>min_w</span><span class='hs-layout'>,</span><span class='hs-varid'>min_h</span><span class='hs-layout'>)</span> <span class='hs-varid'>i</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyword'>do</span>
<a name="line-241"></a> <span class='hs-keyword'>let</span> <span class='hs-varid'>hpad</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>if</span> <span class='hs-varid'>image_width</span> <span class='hs-varid'>i</span> <span class='hs-varop'><</span> <span class='hs-varid'>min_w</span>
<a name="line-242"></a> <span class='hs-keyword'>then</span> <span class='hs-varid'>background_fill</span> <span class='hs-layout'>(</span><span class='hs-varid'>min_w</span> <span class='hs-comment'>-</span> <span class='hs-varid'>image_width</span> <span class='hs-varid'>i</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span><span class='hs-varid'>image_height</span> <span class='hs-varid'>i</span><span class='hs-layout'>)</span>
<a name="line-243"></a> <span class='hs-keyword'>else</span> <span class='hs-varid'>empty_image</span>
<a name="line-244"></a> <span class='hs-keyword'>let</span> <span class='hs-varid'>vpad</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>if</span> <span class='hs-varid'>image_height</span> <span class='hs-varid'>i</span> <span class='hs-varop'><</span> <span class='hs-varid'>min_h</span>
<a name="line-245"></a> <span class='hs-keyword'>then</span> <span class='hs-varid'>background_fill</span> <span class='hs-layout'>(</span><span class='hs-varid'>image_width</span> <span class='hs-varid'>i</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span><span class='hs-varid'>min_h</span> <span class='hs-comment'>-</span> <span class='hs-varid'>image_height</span> <span class='hs-varid'>i</span><span class='hs-layout'>)</span>
<a name="line-246"></a> <span class='hs-keyword'>else</span> <span class='hs-varid'>empty_image</span>
<a name="line-247"></a> <span class='hs-varid'>row_ops_for_image</span> <span class='hs-varid'>mrow_ops</span> <span class='hs-layout'>(</span><span class='hs-layout'>(</span><span class='hs-varid'>i</span> <span class='hs-varop'><|></span> <span class='hs-varid'>hpad</span><span class='hs-layout'>)</span> <span class='hs-varop'><-></span> <span class='hs-varid'>vpad</span><span class='hs-layout'>)</span> <span class='hs-varid'>bg</span> <span class='hs-varid'>region</span> <span class='hs-varid'>skip_dim</span> <span class='hs-varid'>y</span> <span class='hs-varid'>remaining_columns</span> <span class='hs-varid'>remain_rows</span>
<a name="line-248"></a>
<a name="line-249"></a><a name="snoc_text_span"></a><span class='hs-definition'>snoc_text_span</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Attr</span> <span class='hs-comment'>-- the display attributes of the text span</span>
<a name="line-250"></a> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>DisplayString</span> <span class='hs-comment'>-- the text to output</span>
<a name="line-251"></a> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>MRowOps</span> <span class='hs-varid'>s</span> <span class='hs-comment'>-- the display operations to add to</span>
<a name="line-252"></a> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Word</span> <span class='hs-comment'>-- the number of display columns in the text span to </span>
<a name="line-253"></a> <span class='hs-comment'>-- skip before outputting</span>
<a name="line-254"></a> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Int</span> <span class='hs-comment'>-- the row of the display operations to add to</span>
<a name="line-255"></a> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Word</span> <span class='hs-comment'>-- the number of columns from the next column to be </span>
<a name="line-256"></a> <span class='hs-comment'>-- defined to the end of the display for the row.</span>
<a name="line-257"></a> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>ST</span> <span class='hs-varid'>s</span> <span class='hs-conid'>Word</span>
<a name="line-258"></a><span class='hs-definition'>snoc_text_span</span> <span class='hs-varid'>a</span> <span class='hs-varid'>text_str</span> <span class='hs-varid'>mrow_ops</span> <span class='hs-varid'>columns_to_skip</span> <span class='hs-varid'>y</span> <span class='hs-varid'>remaining_columns</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>do</span>
<a name="line-259"></a> <span class='hs-comment'>{-# SCC "snoc_text_span-pre" #-}</span> <span class='hs-varid'>snoc_op</span> <span class='hs-varid'>mrow_ops</span> <span class='hs-varid'>y</span> <span class='hs-varop'>$!</span> <span class='hs-conid'>AttributeChange</span> <span class='hs-varid'>a</span>
<a name="line-260"></a> <span class='hs-comment'>-- At most a text span will consist of remaining_columns characters</span>
<a name="line-261"></a> <span class='hs-comment'>-- we keep track of the position of the next character.</span>
<a name="line-262"></a> <span class='hs-keyword'>let</span> <span class='hs-varid'>max_len</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Int</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>fromEnum</span> <span class='hs-varid'>remaining_columns</span>
<a name="line-263"></a> <span class='hs-varid'>mspan_chars</span> <span class='hs-keyglyph'><-</span> <span class='hs-conid'>Vector</span><span class='hs-varop'>.</span><span class='hs-varid'>new</span> <span class='hs-varid'>max_len</span>
<a name="line-264"></a> <span class='hs-layout'>(</span> <span class='hs-varid'>used_display_columns</span><span class='hs-layout'>,</span> <span class='hs-varid'>display_columns_skipped</span><span class='hs-layout'>,</span> <span class='hs-varid'>used_char_count</span> <span class='hs-layout'>)</span>
<a name="line-265"></a> <span class='hs-keyglyph'><-</span> <span class='hs-comment'>{-# SCC "snoc_text_span-foldlM" #-}</span> <span class='hs-conid'>Foldable</span><span class='hs-varop'>.</span><span class='hs-varid'>foldlM</span> <span class='hs-layout'>(</span><span class='hs-varid'>build_text_span</span> <span class='hs-varid'>mspan_chars</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span> <span class='hs-num'>0</span><span class='hs-layout'>,</span> <span class='hs-num'>0</span><span class='hs-layout'>,</span> <span class='hs-num'>0</span> <span class='hs-layout'>)</span> <span class='hs-varid'>text_str</span>
<a name="line-266"></a> <span class='hs-comment'>-- once all characters have been output to mspan_chars we grab the used head </span>
<a name="line-267"></a> <span class='hs-varid'>out_text</span> <span class='hs-keyglyph'><-</span> <span class='hs-conid'>Vector</span><span class='hs-varop'>.</span><span class='hs-varid'>unsafeFreeze</span> <span class='hs-varop'>$!</span> <span class='hs-conid'>Vector</span><span class='hs-varop'>.</span><span class='hs-varid'>take</span> <span class='hs-varid'>used_char_count</span> <span class='hs-varid'>mspan_chars</span>
<a name="line-268"></a> <span class='hs-comment'>-- convert to UTF8 bytestring.</span>
<a name="line-269"></a> <span class='hs-comment'>-- This could be made faster. Hopefully the optimizer does a fair job at fusing the fold</span>
<a name="line-270"></a> <span class='hs-comment'>-- contained in fromString with the unfold in toList. No biggy right now then.</span>
<a name="line-271"></a> <span class='hs-comment'>{-# SCC "snoc_text_span-post" #-}</span> <span class='hs-varid'>snoc_op</span> <span class='hs-varid'>mrow_ops</span> <span class='hs-varid'>y</span> <span class='hs-varop'>$!</span> <span class='hs-conid'>TextSpan</span> <span class='hs-varid'>used_display_columns</span> <span class='hs-layout'>(</span><span class='hs-varid'>toEnum</span> <span class='hs-varid'>used_char_count</span><span class='hs-layout'>)</span>
<a name="line-272"></a> <span class='hs-varop'>$!</span> <span class='hs-conid'>UTF8</span><span class='hs-varop'>.</span><span class='hs-varid'>fromString</span>
<a name="line-273"></a> <span class='hs-varop'>$!</span> <span class='hs-conid'>Vector</span><span class='hs-varop'>.</span><span class='hs-varid'>toList</span> <span class='hs-varid'>out_text</span>
<a name="line-274"></a> <span class='hs-varid'>return</span> <span class='hs-varop'>$</span> <span class='hs-varid'>columns_to_skip</span> <span class='hs-comment'>-</span> <span class='hs-varid'>display_columns_skipped</span>
<a name="line-275"></a> <span class='hs-keyword'>where</span>
<a name="line-276"></a> <span class='hs-varid'>build_text_span</span> <span class='hs-varid'>mspan_chars</span> <span class='hs-layout'>(</span><span class='hs-varop'>!</span><span class='hs-varid'>used_display_columns</span><span class='hs-layout'>,</span> <span class='hs-varop'>!</span><span class='hs-varid'>display_columns_skipped</span><span class='hs-layout'>,</span> <span class='hs-varop'>!</span><span class='hs-varid'>used_char_count</span><span class='hs-layout'>)</span>
<a name="line-277"></a> <span class='hs-layout'>(</span><span class='hs-varid'>out_char</span><span class='hs-layout'>,</span> <span class='hs-varid'>char_display_width</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-comment'>{-# SCC "build_text_span" #-}</span>
<a name="line-278"></a> <span class='hs-comment'>-- Only valid if the maximum width of a character is 2 display columns.</span>
<a name="line-279"></a> <span class='hs-comment'>-- XXX: Optimize into a skip pass then clipped fill pass</span>
<a name="line-280"></a> <span class='hs-keyword'>if</span> <span class='hs-varid'>display_columns_skipped</span> <span class='hs-varop'>==</span> <span class='hs-varid'>columns_to_skip</span>
<a name="line-281"></a> <span class='hs-keyword'>then</span> <span class='hs-keyword'>if</span> <span class='hs-varid'>used_display_columns</span> <span class='hs-varop'>==</span> <span class='hs-varid'>remaining_columns</span>
<a name="line-282"></a> <span class='hs-keyword'>then</span> <span class='hs-varid'>return</span> <span class='hs-varop'>$!</span> <span class='hs-layout'>(</span> <span class='hs-varid'>used_display_columns</span><span class='hs-layout'>,</span> <span class='hs-varid'>display_columns_skipped</span><span class='hs-layout'>,</span> <span class='hs-varid'>used_char_count</span> <span class='hs-layout'>)</span>
<a name="line-283"></a> <span class='hs-keyword'>else</span> <span class='hs-keyword'>if</span> <span class='hs-layout'>(</span> <span class='hs-varid'>used_display_columns</span> <span class='hs-varop'>+</span> <span class='hs-varid'>char_display_width</span> <span class='hs-layout'>)</span> <span class='hs-varop'>></span> <span class='hs-varid'>remaining_columns</span>
<a name="line-284"></a> <span class='hs-keyword'>then</span> <span class='hs-keyword'>do</span>
<a name="line-285"></a> <span class='hs-conid'>Vector</span><span class='hs-varop'>.</span><span class='hs-varid'>unsafeWrite</span> <span class='hs-varid'>mspan_chars</span> <span class='hs-varid'>used_char_count</span> <span class='hs-chr'>'…'</span>
<a name="line-286"></a> <span class='hs-varid'>return</span> <span class='hs-varop'>$!</span> <span class='hs-layout'>(</span> <span class='hs-varid'>used_display_columns</span> <span class='hs-varop'>+</span> <span class='hs-num'>1</span>
<a name="line-287"></a> <span class='hs-layout'>,</span> <span class='hs-varid'>display_columns_skipped</span>
<a name="line-288"></a> <span class='hs-layout'>,</span> <span class='hs-varid'>used_char_count</span> <span class='hs-varop'>+</span> <span class='hs-num'>1</span>
<a name="line-289"></a> <span class='hs-layout'>)</span>
<a name="line-290"></a> <span class='hs-keyword'>else</span> <span class='hs-keyword'>do</span>
<a name="line-291"></a> <span class='hs-conid'>Vector</span><span class='hs-varop'>.</span><span class='hs-varid'>unsafeWrite</span> <span class='hs-varid'>mspan_chars</span> <span class='hs-varid'>used_char_count</span> <span class='hs-varid'>out_char</span>
<a name="line-292"></a> <span class='hs-varid'>return</span> <span class='hs-varop'>$!</span> <span class='hs-layout'>(</span> <span class='hs-varid'>used_display_columns</span> <span class='hs-varop'>+</span> <span class='hs-varid'>char_display_width</span>
<a name="line-293"></a> <span class='hs-layout'>,</span> <span class='hs-varid'>display_columns_skipped</span>
<a name="line-294"></a> <span class='hs-layout'>,</span> <span class='hs-varid'>used_char_count</span> <span class='hs-varop'>+</span> <span class='hs-num'>1</span>
<a name="line-295"></a> <span class='hs-layout'>)</span>
<a name="line-296"></a> <span class='hs-keyword'>else</span> <span class='hs-keyword'>if</span> <span class='hs-layout'>(</span><span class='hs-varid'>display_columns_skipped</span> <span class='hs-varop'>+</span> <span class='hs-varid'>char_display_width</span><span class='hs-layout'>)</span> <span class='hs-varop'>></span> <span class='hs-varid'>columns_to_skip</span>
<a name="line-297"></a> <span class='hs-keyword'>then</span> <span class='hs-keyword'>do</span>
<a name="line-298"></a> <span class='hs-conid'>Vector</span><span class='hs-varop'>.</span><span class='hs-varid'>unsafeWrite</span> <span class='hs-varid'>mspan_chars</span> <span class='hs-varid'>used_char_count</span> <span class='hs-chr'>'…'</span>
<a name="line-299"></a> <span class='hs-varid'>return</span> <span class='hs-varop'>$!</span> <span class='hs-layout'>(</span> <span class='hs-varid'>used_display_columns</span> <span class='hs-varop'>+</span> <span class='hs-num'>1</span>
<a name="line-300"></a> <span class='hs-layout'>,</span> <span class='hs-varid'>columns_to_skip</span>
<a name="line-301"></a> <span class='hs-layout'>,</span> <span class='hs-varid'>used_char_count</span> <span class='hs-varop'>+</span> <span class='hs-num'>1</span>
<a name="line-302"></a> <span class='hs-layout'>)</span>
<a name="line-303"></a> <span class='hs-keyword'>else</span> <span class='hs-varid'>return</span> <span class='hs-varop'>$</span> <span class='hs-layout'>(</span> <span class='hs-varid'>used_display_columns</span>
<a name="line-304"></a> <span class='hs-layout'>,</span> <span class='hs-varid'>display_columns_skipped</span> <span class='hs-varop'>+</span> <span class='hs-varid'>char_display_width</span>
<a name="line-305"></a> <span class='hs-layout'>,</span> <span class='hs-varid'>used_char_count</span>
<a name="line-306"></a> <span class='hs-layout'>)</span>
<a name="line-307"></a>
<a name="line-308"></a><a name="snoc_bg_fill"></a><span class='hs-definition'>snoc_bg_fill</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>MRowOps</span> <span class='hs-varid'>s</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Background</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Word</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Int</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>ST</span> <span class='hs-varid'>s</span> <span class='hs-conid'>()</span>
<a name="line-309"></a><span class='hs-definition'>snoc_bg_fill</span> <span class='hs-sel'>_row_ops</span> <span class='hs-sel'>_bg</span> <span class='hs-num'>0</span> <span class='hs-sel'>_row</span>
<a name="line-310"></a> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>return</span> <span class='hs-conid'>()</span>
<a name="line-311"></a><span class='hs-definition'>snoc_bg_fill</span> <span class='hs-varid'>mrow_ops</span> <span class='hs-layout'>(</span><span class='hs-conid'>Background</span> <span class='hs-varid'>c</span> <span class='hs-varid'>back_attr</span><span class='hs-layout'>)</span> <span class='hs-varid'>fill_length</span> <span class='hs-varid'>row</span>
<a name="line-312"></a> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>do</span>
<a name="line-313"></a> <span class='hs-varid'>snoc_op</span> <span class='hs-varid'>mrow_ops</span> <span class='hs-varid'>row</span> <span class='hs-varop'>$</span> <span class='hs-conid'>AttributeChange</span> <span class='hs-varid'>back_attr</span>
<a name="line-314"></a> <span class='hs-comment'>-- By all likelyhood the background character will be an ASCII character. Which is a single</span>
<a name="line-315"></a> <span class='hs-comment'>-- byte in utf8. Optimize for this special case.</span>
<a name="line-316"></a> <span class='hs-varid'>utf8_bs</span> <span class='hs-keyglyph'><-</span> <span class='hs-keyword'>if</span> <span class='hs-varid'>c</span> <span class='hs-varop'><=</span> <span class='hs-layout'>(</span><span class='hs-varid'>toEnum</span> <span class='hs-num'>255</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Char</span><span class='hs-layout'>)</span>
<a name="line-317"></a> <span class='hs-keyword'>then</span>
<a name="line-318"></a> <span class='hs-keyword'>let</span> <span class='hs-varop'>!</span><span class='hs-layout'>(</span><span class='hs-varid'>c_byte</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Word8</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>BInt</span><span class='hs-varop'>.</span><span class='hs-varid'>c2w</span> <span class='hs-varid'>c</span>
<a name="line-319"></a> <span class='hs-keyword'>in</span> <span class='hs-varid'>unsafeIOToST</span> <span class='hs-varop'>$</span> <span class='hs-keyword'>do</span>
<a name="line-320"></a> <span class='hs-conid'>BInt</span><span class='hs-varop'>.</span><span class='hs-varid'>create</span> <span class='hs-layout'>(</span> <span class='hs-varid'>fromEnum</span> <span class='hs-varid'>fill_length</span> <span class='hs-layout'>)</span>
<a name="line-321"></a> <span class='hs-varop'>$</span> <span class='hs-keyglyph'>\</span><span class='hs-varid'>ptr</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>mapM_</span> <span class='hs-layout'>(</span><span class='hs-keyglyph'>\</span><span class='hs-varid'>i</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>pokeByteOff</span> <span class='hs-varid'>ptr</span> <span class='hs-varid'>i</span> <span class='hs-varid'>c_byte</span><span class='hs-layout'>)</span>
<a name="line-322"></a> <span class='hs-keyglyph'>[</span><span class='hs-num'>0</span> <span class='hs-keyglyph'>..</span> <span class='hs-varid'>fromEnum</span> <span class='hs-layout'>(</span><span class='hs-varid'>fill_length</span> <span class='hs-comment'>-</span> <span class='hs-num'>1</span><span class='hs-layout'>)</span><span class='hs-keyglyph'>]</span>
<a name="line-323"></a> <span class='hs-keyword'>else</span>
<a name="line-324"></a> <span class='hs-keyword'>let</span> <span class='hs-varop'>!</span><span class='hs-layout'>(</span><span class='hs-varid'>c_bytes</span> <span class='hs-keyglyph'>::</span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>Word8</span><span class='hs-keyglyph'>]</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>encode</span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>c</span><span class='hs-keyglyph'>]</span>
<a name="line-325"></a> <span class='hs-keyword'>in</span> <span class='hs-varid'>unsafeIOToST</span> <span class='hs-varop'>$</span> <span class='hs-keyword'>do</span>
<a name="line-326"></a> <span class='hs-conid'>BInt</span><span class='hs-varop'>.</span><span class='hs-varid'>create</span> <span class='hs-layout'>(</span><span class='hs-varid'>fromEnum</span> <span class='hs-varid'>fill_length</span> <span class='hs-varop'>*</span> <span class='hs-varid'>length</span> <span class='hs-varid'>c_bytes</span><span class='hs-layout'>)</span>
<a name="line-327"></a> <span class='hs-varop'>$</span> <span class='hs-keyglyph'>\</span><span class='hs-varid'>ptr</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>mapM_</span> <span class='hs-layout'>(</span><span class='hs-keyglyph'>\</span><span class='hs-layout'>(</span><span class='hs-varid'>i</span><span class='hs-layout'>,</span><span class='hs-varid'>b</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>pokeByteOff</span> <span class='hs-varid'>ptr</span> <span class='hs-varid'>i</span> <span class='hs-varid'>b</span><span class='hs-layout'>)</span>
<a name="line-328"></a> <span class='hs-varop'>$</span> <span class='hs-varid'>zip</span> <span class='hs-keyglyph'>[</span><span class='hs-num'>0</span> <span class='hs-keyglyph'>..</span> <span class='hs-varid'>fromEnum</span> <span class='hs-layout'>(</span><span class='hs-varid'>fill_length</span> <span class='hs-comment'>-</span> <span class='hs-num'>1</span><span class='hs-layout'>)</span><span class='hs-keyglyph'>]</span> <span class='hs-layout'>(</span><span class='hs-varid'>cycle</span> <span class='hs-varid'>c_bytes</span><span class='hs-layout'>)</span>
<a name="line-329"></a> <span class='hs-varid'>snoc_op</span> <span class='hs-varid'>mrow_ops</span> <span class='hs-varid'>row</span> <span class='hs-varop'>$</span> <span class='hs-conid'>TextSpan</span> <span class='hs-varid'>fill_length</span> <span class='hs-varid'>fill_length</span> <span class='hs-layout'>(</span><span class='hs-conid'>UTF8</span><span class='hs-varop'>.</span><span class='hs-varid'>fromRep</span> <span class='hs-varid'>utf8_bs</span><span class='hs-layout'>)</span>
<a name="line-330"></a>
<a name="line-331"></a><a name="snoc_op"></a><span class='hs-definition'>snoc_op</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>MRowOps</span> <span class='hs-varid'>s</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Int</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>SpanOp</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>ST</span> <span class='hs-varid'>s</span> <span class='hs-conid'>()</span>
<a name="line-332"></a><a name="!"></a><span class='hs-definition'>snoc_op</span> <span class='hs-varop'>!</span><span class='hs-varid'>mrow_ops</span> <span class='hs-varop'>!</span><span class='hs-varid'>row</span> <span class='hs-varop'>!</span><span class='hs-varid'>op</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>do</span>
<a name="line-333"></a> <span class='hs-varid'>ops</span> <span class='hs-keyglyph'><-</span> <span class='hs-conid'>Vector</span><span class='hs-varop'>.</span><span class='hs-varid'>read</span> <span class='hs-varid'>mrow_ops</span> <span class='hs-varid'>row</span>
<a name="line-334"></a> <span class='hs-keyword'>let</span> <span class='hs-varid'>ops'</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Vector</span><span class='hs-varop'>.</span><span class='hs-varid'>snoc</span> <span class='hs-varid'>ops</span> <span class='hs-varid'>op</span>
<a name="line-335"></a> <span class='hs-conid'>Vector</span><span class='hs-varop'>.</span><span class='hs-varid'>write</span> <span class='hs-varid'>mrow_ops</span> <span class='hs-varid'>row</span> <span class='hs-varid'>ops'</span>
<a name="line-336"></a>
</pre></body>
</html>
|