/usr/share/doc/libghc-vty-doc/html/src/Graphics-Vty-Terminal-Generic.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 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 | <?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/Terminal/Generic.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-2011 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 RankNTypes #-}</span>
<a name="line-4"></a><span class='hs-comment'>{-# LANGUAGE ScopedTypeVariables #-}</span>
<a name="line-5"></a><span class='hs-comment'>{-# LANGUAGE ExistentialQuantification #-}</span>
<a name="line-6"></a><span class='hs-comment'>{-# LANGUAGE GADTs #-}</span>
<a name="line-7"></a><span class='hs-comment'>{-# LANGUAGE FlexibleContexts #-}</span>
<a name="line-8"></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'>Terminal</span><span class='hs-varop'>.</span><span class='hs-conid'>Generic</span> <span class='hs-layout'>(</span> <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'>Terminal</span><span class='hs-varop'>.</span><span class='hs-conid'>Generic</span>
<a name="line-9"></a> <span class='hs-layout'>,</span> <span class='hs-conid'>OutputBuffer</span>
<a name="line-10"></a> <span class='hs-layout'>)</span>
<a name="line-11"></a> <span class='hs-keyword'>where</span>
<a name="line-12"></a>
<a name="line-13"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>Marshalling</span>
<a name="line-14"></a>
<a name="line-15"></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-16"></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'>Span</span>
<a name="line-17"></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-18"></a>
<a name="line-19"></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'>DisplayAttributes</span>
<a name="line-20"></a>
<a name="line-21"></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'>liftM</span> <span class='hs-layout'>)</span>
<a name="line-22"></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'>Trans</span>
<a name="line-23"></a>
<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'>ByteString</span><span class='hs-varop'>.</span><span class='hs-conid'>Internal</span> <span class='hs-keyword'>as</span> <span class='hs-conid'>BSCore</span>
<a name="line-25"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>IORef</span>
<a name="line-26"></a><span class='hs-keyword'>import</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-varid'>hiding</span> <span class='hs-layout'>(</span> <span class='hs-varid'>foldl</span> <span class='hs-layout'>)</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'>Vector</span> <span class='hs-keyword'>as</span> <span class='hs-conid'>Vector</span>
<a name="line-28"></a>
<a name="line-29"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>System</span><span class='hs-varop'>.</span><span class='hs-conid'>IO</span>
<a name="line-30"></a>
<a name="line-31"></a><span class='hs-keyword'>data</span> <span class='hs-conid'>TerminalHandle</span> <span class='hs-keyword'>where</span>
<a name="line-32"></a> <span class='hs-conid'>TerminalHandle</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Terminal</span> <span class='hs-varid'>t</span> <span class='hs-keyglyph'>=></span> <span class='hs-varid'>t</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IORef</span> <span class='hs-conid'>TerminalState</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>TerminalHandle</span>
<a name="line-33"></a>
<a name="line-34"></a><a name="state_ref"></a><span class='hs-definition'>state_ref</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>TerminalHandle</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IORef</span> <span class='hs-conid'>TerminalState</span>
<a name="line-35"></a><span class='hs-definition'>state_ref</span> <span class='hs-layout'>(</span><span class='hs-conid'>TerminalHandle</span> <span class='hs-keyword'>_</span> <span class='hs-varid'>s_ref</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>s_ref</span>
<a name="line-36"></a>
<a name="line-37"></a><a name="new_terminal_handle"></a><span class='hs-definition'>new_terminal_handle</span> <span class='hs-keyglyph'>::</span> <span class='hs-keyword'>forall</span> <span class='hs-varid'>m</span> <span class='hs-varid'>t</span><span class='hs-varop'>.</span> <span class='hs-layout'>(</span> <span class='hs-conid'>MonadIO</span> <span class='hs-varid'>m</span><span class='hs-layout'>,</span> <span class='hs-conid'>Terminal</span> <span class='hs-varid'>t</span> <span class='hs-layout'>)</span> <span class='hs-keyglyph'>=></span> <span class='hs-varid'>t</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>m</span> <span class='hs-conid'>TerminalHandle</span>
<a name="line-38"></a><span class='hs-definition'>new_terminal_handle</span> <span class='hs-varid'>t</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>do</span>
<a name="line-39"></a> <span class='hs-varid'>s_ref</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>liftIO</span> <span class='hs-varop'>$</span> <span class='hs-varid'>newIORef</span> <span class='hs-varid'>initial_terminal_state</span>
<a name="line-40"></a> <span class='hs-varid'>return</span> <span class='hs-varop'>$</span> <span class='hs-conid'>TerminalHandle</span> <span class='hs-varid'>t</span> <span class='hs-varid'>s_ref</span>
<a name="line-41"></a>
<a name="line-42"></a><a name="TerminalState"></a><span class='hs-keyword'>data</span> <span class='hs-conid'>TerminalState</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>TerminalState</span>
<a name="line-43"></a> <span class='hs-layout'>{</span> <span class='hs-comment'>-- | The current terminal display attributes or Nothing if they are not known.</span>
<a name="line-44"></a> <span class='hs-varid'>known_fattr</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Maybe</span> <span class='hs-conid'>FixedAttr</span>
<a name="line-45"></a> <span class='hs-layout'>}</span>
<a name="line-46"></a>
<a name="line-47"></a><a name="initial_terminal_state"></a><span class='hs-definition'>initial_terminal_state</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>TerminalState</span>
<a name="line-48"></a><span class='hs-definition'>initial_terminal_state</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>TerminalState</span> <span class='hs-conid'>Nothing</span>
<a name="line-49"></a>
<a name="line-50"></a><span class='hs-keyword'>class</span> <span class='hs-conid'>Terminal</span> <span class='hs-varid'>t</span> <span class='hs-keyword'>where</span>
<a name="line-51"></a> <span class='hs-comment'>-- | Text identifier for the terminal. Used for debugging.</span>
<a name="line-52"></a> <span class='hs-varid'>terminal_ID</span> <span class='hs-keyglyph'>::</span> <span class='hs-varid'>t</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>String</span>
<a name="line-53"></a> <span class='hs-comment'>-- | </span>
<a name="line-54"></a> <span class='hs-varid'>release_terminal</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>MonadIO</span> <span class='hs-varid'>m</span> <span class='hs-keyglyph'>=></span> <span class='hs-varid'>t</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>m</span> <span class='hs-conid'>()</span>
<a name="line-55"></a> <span class='hs-comment'>-- | Clear the display and initialize the terminal to some initial display state. </span>
<a name="line-56"></a> <span class='hs-comment'>--</span>
<a name="line-57"></a> <span class='hs-comment'>-- The expectation of a program is that the display starts in some initial state. </span>
<a name="line-58"></a> <span class='hs-comment'>-- The initial state would consist of fixed values:</span>
<a name="line-59"></a> <span class='hs-comment'>-- - cursor at top left</span>
<a name="line-60"></a> <span class='hs-comment'>-- - UTF-8 character encoding</span>
<a name="line-61"></a> <span class='hs-comment'>-- - drawing characteristics are the default</span>
<a name="line-62"></a> <span class='hs-comment'>-- The abstract operation I think all these behaviors are instances of is reserving exclusive</span>
<a name="line-63"></a> <span class='hs-comment'>-- access to a display such that:</span>
<a name="line-64"></a> <span class='hs-comment'>-- - The previous state cannot be determined</span>
<a name="line-65"></a> <span class='hs-comment'>-- - When exclusive access to a display is release the display returns to the previous state.</span>
<a name="line-66"></a> <span class='hs-varid'>reserve_display</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>MonadIO</span> <span class='hs-varid'>m</span> <span class='hs-keyglyph'>=></span> <span class='hs-varid'>t</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>m</span> <span class='hs-conid'>()</span>
<a name="line-67"></a>
<a name="line-68"></a> <span class='hs-comment'>-- | Return the display to the state before reserve_display</span>
<a name="line-69"></a> <span class='hs-comment'>-- If no previous state then set the display state to the initial state.</span>
<a name="line-70"></a> <span class='hs-varid'>release_display</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>MonadIO</span> <span class='hs-varid'>m</span> <span class='hs-keyglyph'>=></span> <span class='hs-varid'>t</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>m</span> <span class='hs-conid'>()</span>
<a name="line-71"></a>
<a name="line-72"></a> <span class='hs-comment'>-- | Returns the current display bounds.</span>
<a name="line-73"></a> <span class='hs-varid'>display_bounds</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>MonadIO</span> <span class='hs-varid'>m</span> <span class='hs-keyglyph'>=></span> <span class='hs-varid'>t</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>m</span> <span class='hs-conid'>DisplayRegion</span>
<a name="line-74"></a>
<a name="line-75"></a> <span class='hs-comment'>-- Internal method used to provide the DisplayTerminal instance to the DisplayHandle</span>
<a name="line-76"></a> <span class='hs-comment'>-- constructor.</span>
<a name="line-77"></a> <span class='hs-varid'>display_terminal_instance</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>MonadIO</span> <span class='hs-varid'>m</span>
<a name="line-78"></a> <span class='hs-keyglyph'>=></span> <span class='hs-varid'>t</span>
<a name="line-79"></a> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>DisplayRegion</span>
<a name="line-80"></a> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-keyword'>forall</span> <span class='hs-varid'>d</span><span class='hs-varop'>.</span> <span class='hs-conid'>DisplayTerminal</span> <span class='hs-varid'>d</span> <span class='hs-keyglyph'>=></span> <span class='hs-varid'>d</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>DisplayHandle</span><span class='hs-layout'>)</span>
<a name="line-81"></a> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>m</span> <span class='hs-conid'>DisplayHandle</span>
<a name="line-82"></a>
<a name="line-83"></a> <span class='hs-comment'>-- | Output the byte buffer of the specified size to the terminal device. The size is equal to</span>
<a name="line-84"></a> <span class='hs-comment'>-- end_ptr - start_ptr</span>
<a name="line-85"></a> <span class='hs-varid'>output_byte_buffer</span> <span class='hs-keyglyph'>::</span> <span class='hs-varid'>t</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>OutputBuffer</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Word</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-conid'>()</span>
<a name="line-86"></a>
<a name="line-87"></a> <span class='hs-comment'>-- | Handle of output device</span>
<a name="line-88"></a> <span class='hs-varid'>output_handle</span> <span class='hs-keyglyph'>::</span> <span class='hs-varid'>t</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-conid'>Handle</span>
<a name="line-89"></a>
<a name="line-90"></a><span class='hs-keyword'>instance</span> <span class='hs-conid'>Terminal</span> <span class='hs-conid'>TerminalHandle</span> <span class='hs-keyword'>where</span>
<a name="line-91"></a> <span class='hs-varid'>terminal_ID</span> <span class='hs-layout'>(</span><span class='hs-conid'>TerminalHandle</span> <span class='hs-varid'>t</span> <span class='hs-keyword'>_</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>terminal_ID</span> <span class='hs-varid'>t</span>
<a name="line-92"></a> <span class='hs-varid'>release_terminal</span> <span class='hs-layout'>(</span><span class='hs-conid'>TerminalHandle</span> <span class='hs-varid'>t</span> <span class='hs-keyword'>_</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>release_terminal</span> <span class='hs-varid'>t</span>
<a name="line-93"></a> <span class='hs-varid'>reserve_display</span> <span class='hs-layout'>(</span><span class='hs-conid'>TerminalHandle</span> <span class='hs-varid'>t</span> <span class='hs-keyword'>_</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>reserve_display</span> <span class='hs-varid'>t</span>
<a name="line-94"></a> <span class='hs-varid'>release_display</span> <span class='hs-layout'>(</span><span class='hs-conid'>TerminalHandle</span> <span class='hs-varid'>t</span> <span class='hs-keyword'>_</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>release_display</span> <span class='hs-varid'>t</span>
<a name="line-95"></a> <span class='hs-varid'>display_bounds</span> <span class='hs-layout'>(</span><span class='hs-conid'>TerminalHandle</span> <span class='hs-varid'>t</span> <span class='hs-keyword'>_</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>display_bounds</span> <span class='hs-varid'>t</span>
<a name="line-96"></a> <span class='hs-varid'>display_terminal_instance</span> <span class='hs-layout'>(</span><span class='hs-conid'>TerminalHandle</span> <span class='hs-varid'>t</span> <span class='hs-keyword'>_</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>display_terminal_instance</span> <span class='hs-varid'>t</span>
<a name="line-97"></a> <span class='hs-varid'>output_byte_buffer</span> <span class='hs-layout'>(</span><span class='hs-conid'>TerminalHandle</span> <span class='hs-varid'>t</span> <span class='hs-keyword'>_</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>output_byte_buffer</span> <span class='hs-varid'>t</span>
<a name="line-98"></a> <span class='hs-varid'>output_handle</span> <span class='hs-layout'>(</span><span class='hs-conid'>TerminalHandle</span> <span class='hs-varid'>t</span> <span class='hs-keyword'>_</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>output_handle</span> <span class='hs-varid'>t</span>
<a name="line-99"></a>
<a name="line-100"></a><span class='hs-keyword'>data</span> <span class='hs-conid'>DisplayHandle</span> <span class='hs-keyword'>where</span>
<a name="line-101"></a> <span class='hs-conid'>DisplayHandle</span> <span class='hs-keyglyph'>::</span> <span class='hs-keyword'>forall</span> <span class='hs-varid'>d</span> <span class='hs-varop'>.</span> <span class='hs-conid'>DisplayTerminal</span> <span class='hs-varid'>d</span> <span class='hs-keyglyph'>=></span> <span class='hs-varid'>d</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>TerminalHandle</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>DisplayState</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>DisplayHandle</span>
<a name="line-102"></a>
<a name="line-103"></a><a name="display_context"></a><span class='hs-comment'>-- | Acquire display access to the given region of the display.</span>
<a name="line-104"></a><span class='hs-comment'>-- Currently all regions have the upper left corner of (0,0) and the lower right corner at </span>
<a name="line-105"></a><span class='hs-comment'>-- (max display_width provided_width, max display_height provided_height)</span>
<a name="line-106"></a><span class='hs-definition'>display_context</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>MonadIO</span> <span class='hs-varid'>m</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>TerminalHandle</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>DisplayRegion</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>m</span> <span class='hs-conid'>DisplayHandle</span>
<a name="line-107"></a><span class='hs-definition'>display_context</span> <span class='hs-varid'>t</span> <span class='hs-varid'>b</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>do</span>
<a name="line-108"></a> <span class='hs-varid'>s</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>initial_display_state</span>
<a name="line-109"></a> <span class='hs-varid'>display_terminal_instance</span> <span class='hs-varid'>t</span> <span class='hs-varid'>b</span> <span class='hs-layout'>(</span><span class='hs-keyglyph'>\</span> <span class='hs-varid'>d</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>DisplayHandle</span> <span class='hs-varid'>d</span> <span class='hs-varid'>t</span> <span class='hs-varid'>s</span><span class='hs-layout'>)</span>
<a name="line-110"></a>
<a name="line-111"></a><a name="DisplayState"></a><span class='hs-keyword'>data</span> <span class='hs-conid'>DisplayState</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>DisplayState</span>
<a name="line-112"></a> <span class='hs-layout'>{</span> <span class='hs-varid'>previous_output_ref</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>IORef</span> <span class='hs-layout'>(</span><span class='hs-conid'>Maybe</span> <span class='hs-conid'>DisplayOps</span><span class='hs-layout'>)</span>
<a name="line-113"></a> <span class='hs-layout'>}</span>
<a name="line-114"></a>
<a name="line-115"></a><a name="initial_display_state"></a><span class='hs-definition'>initial_display_state</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>MonadIO</span> <span class='hs-varid'>m</span> <span class='hs-keyglyph'>=></span> <span class='hs-varid'>m</span> <span class='hs-conid'>DisplayState</span>
<a name="line-116"></a><span class='hs-definition'>initial_display_state</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>liftM</span> <span class='hs-conid'>DisplayState</span> <span class='hs-varop'>$</span> <span class='hs-varid'>liftIO</span> <span class='hs-varop'>$</span> <span class='hs-varid'>newIORef</span> <span class='hs-conid'>Nothing</span>
<a name="line-117"></a>
<a name="line-118"></a><span class='hs-keyword'>class</span> <span class='hs-conid'>DisplayTerminal</span> <span class='hs-varid'>d</span> <span class='hs-keyword'>where</span>
<a name="line-119"></a> <span class='hs-comment'>-- | Provide the bounds of the display context. </span>
<a name="line-120"></a> <span class='hs-varid'>context_region</span> <span class='hs-keyglyph'>::</span> <span class='hs-varid'>d</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>DisplayRegion</span>
<a name="line-121"></a>
<a name="line-122"></a> <span class='hs-comment'>-- | Maximum number of colors supported by the context.</span>
<a name="line-123"></a> <span class='hs-varid'>context_color_count</span> <span class='hs-keyglyph'>::</span> <span class='hs-varid'>d</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Word</span>
<a name="line-124"></a>
<a name="line-125"></a> <span class='hs-comment'>-- | sets the output position to the specified row and column. Where the number of bytes</span>
<a name="line-126"></a> <span class='hs-comment'>-- required for the control codes can be specified seperate from the actual byte sequence.</span>
<a name="line-127"></a> <span class='hs-varid'>move_cursor_required_bytes</span> <span class='hs-keyglyph'>::</span> <span class='hs-varid'>d</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Word</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Word</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Word</span>
<a name="line-128"></a> <span class='hs-varid'>serialize_move_cursor</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>MonadIO</span> <span class='hs-varid'>m</span> <span class='hs-keyglyph'>=></span> <span class='hs-varid'>d</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Word</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Word</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>OutputBuffer</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>m</span> <span class='hs-conid'>OutputBuffer</span>
<a name="line-129"></a>
<a name="line-130"></a> <span class='hs-varid'>show_cursor_required_bytes</span> <span class='hs-keyglyph'>::</span> <span class='hs-varid'>d</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Word</span>
<a name="line-131"></a> <span class='hs-varid'>serialize_show_cursor</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>MonadIO</span> <span class='hs-varid'>m</span> <span class='hs-keyglyph'>=></span> <span class='hs-varid'>d</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>OutputBuffer</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>m</span> <span class='hs-conid'>OutputBuffer</span>
<a name="line-132"></a>
<a name="line-133"></a> <span class='hs-varid'>hide_cursor_required_bytes</span> <span class='hs-keyglyph'>::</span> <span class='hs-varid'>d</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Word</span>
<a name="line-134"></a> <span class='hs-varid'>serialize_hide_cursor</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>MonadIO</span> <span class='hs-varid'>m</span> <span class='hs-keyglyph'>=></span> <span class='hs-varid'>d</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>OutputBuffer</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>m</span> <span class='hs-conid'>OutputBuffer</span>
<a name="line-135"></a>
<a name="line-136"></a> <span class='hs-comment'>-- | Assure the specified output attributes will be applied to all the following text until the</span>
<a name="line-137"></a> <span class='hs-comment'>-- next output attribute change. Where the number of bytes required for the control codes can</span>
<a name="line-138"></a> <span class='hs-comment'>-- be specified seperate from the actual byte sequence. The required number of bytes must be</span>
<a name="line-139"></a> <span class='hs-comment'>-- at least the maximum number of bytes required by any attribute changes. The serialization</span>
<a name="line-140"></a> <span class='hs-comment'>-- equations must provide the ptr to the next byte to be specified in the output buffer.</span>
<a name="line-141"></a> <span class='hs-comment'>--</span>
<a name="line-142"></a> <span class='hs-comment'>-- The currently applied display attributes are provided as well. The Attr data type can</span>
<a name="line-143"></a> <span class='hs-comment'>-- specify the style or color should not be changed from the currently applied display</span>
<a name="line-144"></a> <span class='hs-comment'>-- attributes. In order to support this the currently applied display attributes are required.</span>
<a name="line-145"></a> <span class='hs-comment'>-- In addition it may be possible to optimize the state changes based off the currently applied</span>
<a name="line-146"></a> <span class='hs-comment'>-- display attributes.</span>
<a name="line-147"></a> <span class='hs-varid'>attr_required_bytes</span> <span class='hs-keyglyph'>::</span> <span class='hs-varid'>d</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>FixedAttr</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Attr</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>DisplayAttrDiff</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Word</span>
<a name="line-148"></a> <span class='hs-varid'>serialize_set_attr</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>MonadIO</span> <span class='hs-varid'>m</span> <span class='hs-keyglyph'>=></span> <span class='hs-varid'>d</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>FixedAttr</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Attr</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>DisplayAttrDiff</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>OutputBuffer</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>m</span> <span class='hs-conid'>OutputBuffer</span>
<a name="line-149"></a>
<a name="line-150"></a> <span class='hs-comment'>-- | Reset the display attributes to the default display attributes</span>
<a name="line-151"></a> <span class='hs-varid'>default_attr_required_bytes</span> <span class='hs-keyglyph'>::</span> <span class='hs-varid'>d</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Word</span>
<a name="line-152"></a> <span class='hs-varid'>serialize_default_attr</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>MonadIO</span> <span class='hs-varid'>m</span> <span class='hs-keyglyph'>=></span> <span class='hs-varid'>d</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>OutputBuffer</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>m</span> <span class='hs-conid'>OutputBuffer</span>
<a name="line-153"></a>
<a name="line-154"></a> <span class='hs-comment'>-- | See Graphics.Vty.Terminal.XTermColor.inline_hack</span>
<a name="line-155"></a> <span class='hs-varid'>inline_hack</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>MonadIO</span> <span class='hs-varid'>m</span> <span class='hs-keyglyph'>=></span> <span class='hs-varid'>d</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>m</span> <span class='hs-conid'>()</span>
<a name="line-156"></a> <span class='hs-varid'>inline_hack</span> <span class='hs-sel'>_d</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>return</span> <span class='hs-conid'>()</span>
<a name="line-157"></a>
<a name="line-158"></a>
<a name="line-159"></a><span class='hs-keyword'>instance</span> <span class='hs-conid'>DisplayTerminal</span> <span class='hs-conid'>DisplayHandle</span> <span class='hs-keyword'>where</span>
<a name="line-160"></a> <span class='hs-varid'>context_region</span> <span class='hs-layout'>(</span><span class='hs-conid'>DisplayHandle</span> <span class='hs-varid'>d</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'>context_region</span> <span class='hs-varid'>d</span>
<a name="line-161"></a> <span class='hs-varid'>context_color_count</span> <span class='hs-layout'>(</span><span class='hs-conid'>DisplayHandle</span> <span class='hs-varid'>d</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'>context_color_count</span> <span class='hs-varid'>d</span>
<a name="line-162"></a> <span class='hs-varid'>move_cursor_required_bytes</span> <span class='hs-layout'>(</span><span class='hs-conid'>DisplayHandle</span> <span class='hs-varid'>d</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'>move_cursor_required_bytes</span> <span class='hs-varid'>d</span>
<a name="line-163"></a> <span class='hs-varid'>serialize_move_cursor</span> <span class='hs-layout'>(</span><span class='hs-conid'>DisplayHandle</span> <span class='hs-varid'>d</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'>serialize_move_cursor</span> <span class='hs-varid'>d</span>
<a name="line-164"></a> <span class='hs-varid'>show_cursor_required_bytes</span> <span class='hs-layout'>(</span><span class='hs-conid'>DisplayHandle</span> <span class='hs-varid'>d</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'>show_cursor_required_bytes</span> <span class='hs-varid'>d</span>
<a name="line-165"></a> <span class='hs-varid'>serialize_show_cursor</span> <span class='hs-layout'>(</span><span class='hs-conid'>DisplayHandle</span> <span class='hs-varid'>d</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'>serialize_show_cursor</span> <span class='hs-varid'>d</span>
<a name="line-166"></a> <span class='hs-varid'>hide_cursor_required_bytes</span> <span class='hs-layout'>(</span><span class='hs-conid'>DisplayHandle</span> <span class='hs-varid'>d</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'>hide_cursor_required_bytes</span> <span class='hs-varid'>d</span>
<a name="line-167"></a> <span class='hs-varid'>serialize_hide_cursor</span> <span class='hs-layout'>(</span><span class='hs-conid'>DisplayHandle</span> <span class='hs-varid'>d</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'>serialize_hide_cursor</span> <span class='hs-varid'>d</span>
<a name="line-168"></a> <span class='hs-varid'>attr_required_bytes</span> <span class='hs-layout'>(</span><span class='hs-conid'>DisplayHandle</span> <span class='hs-varid'>d</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'>attr_required_bytes</span> <span class='hs-varid'>d</span>
<a name="line-169"></a> <span class='hs-varid'>serialize_set_attr</span> <span class='hs-layout'>(</span><span class='hs-conid'>DisplayHandle</span> <span class='hs-varid'>d</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'>serialize_set_attr</span> <span class='hs-varid'>d</span>
<a name="line-170"></a> <span class='hs-varid'>default_attr_required_bytes</span> <span class='hs-layout'>(</span><span class='hs-conid'>DisplayHandle</span> <span class='hs-varid'>d</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'>default_attr_required_bytes</span> <span class='hs-varid'>d</span>
<a name="line-171"></a> <span class='hs-varid'>serialize_default_attr</span> <span class='hs-layout'>(</span><span class='hs-conid'>DisplayHandle</span> <span class='hs-varid'>d</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'>serialize_default_attr</span> <span class='hs-varid'>d</span>
<a name="line-172"></a> <span class='hs-varid'>inline_hack</span> <span class='hs-layout'>(</span><span class='hs-conid'>DisplayHandle</span> <span class='hs-varid'>d</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'>inline_hack</span> <span class='hs-varid'>d</span>
<a name="line-173"></a>
<a name="line-174"></a><a name="utf8_text_required_bytes"></a><span class='hs-comment'>-- | All terminals serialize UTF8 text to the terminal device exactly as serialized in memory.</span>
<a name="line-175"></a><span class='hs-definition'>utf8_text_required_bytes</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>UTF8</span> <span class='hs-conid'>BSCore</span><span class='hs-varop'>.</span><span class='hs-conid'>ByteString</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Word</span>
<a name="line-176"></a><span class='hs-definition'>utf8_text_required_bytes</span> <span class='hs-varid'>str</span> <span class='hs-keyglyph'>=</span>
<a name="line-177"></a> <span class='hs-keyword'>let</span> <span class='hs-layout'>(</span><span class='hs-keyword'>_</span><span class='hs-layout'>,</span> <span class='hs-keyword'>_</span><span class='hs-layout'>,</span> <span class='hs-varid'>src_bytes_length</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>BSCore</span><span class='hs-varop'>.</span><span class='hs-varid'>toForeignPtr</span> <span class='hs-layout'>(</span><span class='hs-varid'>toRep</span> <span class='hs-varid'>str</span><span class='hs-layout'>)</span>
<a name="line-178"></a> <span class='hs-keyword'>in</span> <span class='hs-varid'>toEnum</span> <span class='hs-varid'>src_bytes_length</span>
<a name="line-179"></a>
<a name="line-180"></a><a name="serialize_utf8_text"></a><span class='hs-comment'>-- | All terminals serialize UTF8 text to the terminal device exactly as serialized in memory.</span>
<a name="line-181"></a><span class='hs-definition'>serialize_utf8_text</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>MonadIO</span> <span class='hs-varid'>m</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>UTF8</span> <span class='hs-conid'>BSCore</span><span class='hs-varop'>.</span><span class='hs-conid'>ByteString</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>OutputBuffer</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>m</span> <span class='hs-conid'>OutputBuffer</span>
<a name="line-182"></a><span class='hs-definition'>serialize_utf8_text</span> <span class='hs-varid'>str</span> <span class='hs-varid'>dest_ptr</span> <span class='hs-keyglyph'>=</span>
<a name="line-183"></a> <span class='hs-keyword'>let</span> <span class='hs-layout'>(</span><span class='hs-varid'>src_fptr</span><span class='hs-layout'>,</span> <span class='hs-varid'>src_ptr_offset</span><span class='hs-layout'>,</span> <span class='hs-varid'>src_bytes_length</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>BSCore</span><span class='hs-varop'>.</span><span class='hs-varid'>toForeignPtr</span> <span class='hs-layout'>(</span><span class='hs-varid'>toRep</span> <span class='hs-varid'>str</span><span class='hs-layout'>)</span>
<a name="line-184"></a> <span class='hs-keyword'>in</span> <span class='hs-varid'>liftIO</span> <span class='hs-varop'>$</span> <span class='hs-varid'>withForeignPtr</span> <span class='hs-varid'>src_fptr</span> <span class='hs-varop'>$</span> <span class='hs-keyglyph'>\</span><span class='hs-varid'>src_ptr</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyword'>do</span>
<a name="line-185"></a> <span class='hs-keyword'>let</span> <span class='hs-varid'>src_ptr'</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>src_ptr</span> <span class='hs-varop'>`plusPtr`</span> <span class='hs-varid'>src_ptr_offset</span>
<a name="line-186"></a> <span class='hs-conid'>BSCore</span><span class='hs-varop'>.</span><span class='hs-varid'>memcpy</span> <span class='hs-varid'>dest_ptr</span> <span class='hs-varid'>src_ptr'</span> <span class='hs-layout'>(</span><span class='hs-varid'>toEnum</span> <span class='hs-varid'>src_bytes_length</span><span class='hs-layout'>)</span>
<a name="line-187"></a> <span class='hs-varid'>return</span> <span class='hs-layout'>(</span><span class='hs-varid'>dest_ptr</span> <span class='hs-varop'>`plusPtr`</span> <span class='hs-varid'>src_bytes_length</span><span class='hs-layout'>)</span>
<a name="line-188"></a>
<a name="line-189"></a>
<a name="line-190"></a><a name="output_picture"></a><span class='hs-comment'>-- | Displays the given `Picture`.</span>
<a name="line-191"></a><span class='hs-comment'>--</span>
<a name="line-192"></a><span class='hs-comment'>-- 0. The image is cropped to the display size. </span>
<a name="line-193"></a><span class='hs-comment'>--</span>
<a name="line-194"></a><span class='hs-comment'>-- 1. Converted into a sequence of attribute changes and text spans.</span>
<a name="line-195"></a><span class='hs-comment'>-- </span>
<a name="line-196"></a><span class='hs-comment'>-- 2. The cursor is hidden.</span>
<a name="line-197"></a><span class='hs-comment'>--</span>
<a name="line-198"></a><span class='hs-comment'>-- 3. Serialized to the display.</span>
<a name="line-199"></a><span class='hs-comment'>--</span>
<a name="line-200"></a><span class='hs-comment'>-- 4. The cursor is then shown and positioned or kept hidden.</span>
<a name="line-201"></a><span class='hs-comment'>--</span>
<a name="line-202"></a><span class='hs-comment'>-- </span>
<a name="line-203"></a><span class='hs-comment'>-- todo: specify possible IO exceptions.</span>
<a name="line-204"></a><span class='hs-comment'>-- abstract from IO monad to a MonadIO instance.</span>
<a name="line-205"></a><span class='hs-definition'>output_picture</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>MonadIO</span> <span class='hs-varid'>m</span> <span class='hs-keyglyph'>=></span> <span class='hs-conid'>DisplayHandle</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Picture</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>m</span> <span class='hs-conid'>()</span>
<a name="line-206"></a><span class='hs-definition'>output_picture</span> <span class='hs-layout'>(</span><span class='hs-conid'>DisplayHandle</span> <span class='hs-varid'>d</span> <span class='hs-varid'>t</span> <span class='hs-varid'>s</span><span class='hs-layout'>)</span> <span class='hs-varid'>pic</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>do</span>
<a name="line-207"></a> <span class='hs-keyword'>let</span> <span class='hs-varop'>!</span><span class='hs-varid'>r</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>context_region</span> <span class='hs-varid'>d</span>
<a name="line-208"></a> <span class='hs-keyword'>let</span> <span class='hs-varop'>!</span><span class='hs-varid'>ops</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>spans_for_pic</span> <span class='hs-varid'>pic</span> <span class='hs-varid'>r</span>
<a name="line-209"></a> <span class='hs-keyword'>let</span> <span class='hs-varop'>!</span><span class='hs-varid'>initial_attr</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>FixedAttr</span> <span class='hs-varid'>default_style_mask</span> <span class='hs-conid'>Nothing</span> <span class='hs-conid'>Nothing</span>
<a name="line-210"></a> <span class='hs-comment'>-- Diff the previous output against the requested output. Differences are currently on a per-row</span>
<a name="line-211"></a> <span class='hs-comment'>-- basis.</span>
<a name="line-212"></a> <span class='hs-varid'>diffs</span> <span class='hs-keyglyph'>::</span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>Bool</span><span class='hs-keyglyph'>]</span>
<a name="line-213"></a> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>liftIO</span> <span class='hs-layout'>(</span> <span class='hs-varid'>readIORef</span> <span class='hs-layout'>(</span><span class='hs-varid'>previous_output_ref</span> <span class='hs-varid'>s</span><span class='hs-layout'>)</span> <span class='hs-layout'>)</span>
<a name="line-214"></a> <span class='hs-varop'>>>=</span> <span class='hs-keyglyph'>\</span><span class='hs-varid'>mprevious_ops</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyword'>case</span> <span class='hs-varid'>mprevious_ops</span> <span class='hs-keyword'>of</span>
<a name="line-215"></a> <span class='hs-conid'>Nothing</span>
<a name="line-216"></a> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>return</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-varop'>$</span> <span class='hs-varid'>effected_region</span> <span class='hs-varid'>ops</span> <span class='hs-layout'>)</span>
<a name="line-217"></a> <span class='hs-conid'>True</span>
<a name="line-218"></a> <span class='hs-conid'>Just</span> <span class='hs-varid'>previous_ops</span>
<a name="line-219"></a> <span class='hs-keyglyph'>-></span> <span class='hs-keyword'>if</span> <span class='hs-varid'>effected_region</span> <span class='hs-varid'>previous_ops</span> <span class='hs-varop'>/=</span> <span class='hs-varid'>effected_region</span> <span class='hs-varid'>ops</span>
<a name="line-220"></a> <span class='hs-keyword'>then</span> <span class='hs-varid'>return</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-varop'>$</span> <span class='hs-varid'>effected_region</span> <span class='hs-varid'>ops</span> <span class='hs-layout'>)</span>
<a name="line-221"></a> <span class='hs-conid'>True</span>
<a name="line-222"></a> <span class='hs-keyword'>else</span> <span class='hs-varid'>return</span> <span class='hs-varop'>$</span> <span class='hs-varid'>zipWith</span> <span class='hs-layout'>(</span><span class='hs-varop'>/=</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span> <span class='hs-conid'>Vector</span><span class='hs-varop'>.</span><span class='hs-varid'>toList</span> <span class='hs-varop'>$</span> <span class='hs-varid'>display_ops</span> <span class='hs-varid'>previous_ops</span> <span class='hs-layout'>)</span>
<a name="line-223"></a> <span class='hs-layout'>(</span> <span class='hs-conid'>Vector</span><span class='hs-varop'>.</span><span class='hs-varid'>toList</span> <span class='hs-varop'>$</span> <span class='hs-varid'>display_ops</span> <span class='hs-varid'>ops</span> <span class='hs-layout'>)</span>
<a name="line-224"></a>
<a name="line-225"></a> <span class='hs-comment'>-- determine the number of bytes required to completely serialize the output ops.</span>
<a name="line-226"></a> <span class='hs-keyword'>let</span> <span class='hs-varid'>total</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>hide_cursor_required_bytes</span> <span class='hs-varid'>d</span>
<a name="line-227"></a> <span class='hs-varop'>+</span> <span class='hs-varid'>default_attr_required_bytes</span> <span class='hs-varid'>d</span>
<a name="line-228"></a> <span class='hs-varop'>+</span> <span class='hs-varid'>required_bytes</span> <span class='hs-varid'>d</span> <span class='hs-varid'>initial_attr</span> <span class='hs-varid'>diffs</span> <span class='hs-varid'>ops</span>
<a name="line-229"></a> <span class='hs-varop'>+</span> <span class='hs-keyword'>case</span> <span class='hs-varid'>pic_cursor</span> <span class='hs-varid'>pic</span> <span class='hs-keyword'>of</span>
<a name="line-230"></a> <span class='hs-conid'>NoCursor</span> <span class='hs-keyglyph'>-></span> <span class='hs-num'>0</span>
<a name="line-231"></a> <span class='hs-conid'>Cursor</span> <span class='hs-varid'>x</span> <span class='hs-varid'>y</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyword'>let</span> <span class='hs-varid'>m</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>cursor_output_map</span> <span class='hs-varid'>ops</span> <span class='hs-varop'>$</span> <span class='hs-varid'>pic_cursor</span> <span class='hs-varid'>pic</span>
<a name="line-232"></a> <span class='hs-layout'>(</span> <span class='hs-varid'>ox</span><span class='hs-layout'>,</span> <span class='hs-varid'>oy</span> <span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>char_to_output_pos</span> <span class='hs-varid'>m</span> <span class='hs-layout'>(</span> <span class='hs-varid'>x</span><span class='hs-layout'>,</span> <span class='hs-varid'>y</span> <span class='hs-layout'>)</span>
<a name="line-233"></a> <span class='hs-keyword'>in</span> <span class='hs-varid'>show_cursor_required_bytes</span> <span class='hs-varid'>d</span>
<a name="line-234"></a> <span class='hs-varop'>+</span> <span class='hs-varid'>move_cursor_required_bytes</span> <span class='hs-varid'>d</span> <span class='hs-varid'>ox</span> <span class='hs-varid'>oy</span>
<a name="line-235"></a>
<a name="line-236"></a> <span class='hs-comment'>-- ... then serialize</span>
<a name="line-237"></a> <span class='hs-varid'>liftIO</span> <span class='hs-varop'>$</span> <span class='hs-varid'>allocaBytes</span> <span class='hs-layout'>(</span><span class='hs-varid'>fromEnum</span> <span class='hs-varid'>total</span><span class='hs-layout'>)</span> <span class='hs-varop'>$</span> <span class='hs-keyglyph'>\</span><span class='hs-varid'>start_ptr</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyword'>do</span>
<a name="line-238"></a> <span class='hs-varid'>ptr</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>serialize_hide_cursor</span> <span class='hs-varid'>d</span> <span class='hs-varid'>start_ptr</span>
<a name="line-239"></a> <span class='hs-varid'>ptr'</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>serialize_default_attr</span> <span class='hs-varid'>d</span> <span class='hs-varid'>ptr</span>
<a name="line-240"></a> <span class='hs-varid'>ptr''</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>serialize_output_ops</span> <span class='hs-varid'>d</span> <span class='hs-varid'>ptr'</span> <span class='hs-varid'>initial_attr</span> <span class='hs-varid'>diffs</span> <span class='hs-varid'>ops</span>
<a name="line-241"></a> <span class='hs-varid'>end_ptr</span> <span class='hs-keyglyph'><-</span> <span class='hs-keyword'>case</span> <span class='hs-varid'>pic_cursor</span> <span class='hs-varid'>pic</span> <span class='hs-keyword'>of</span>
<a name="line-242"></a> <span class='hs-conid'>NoCursor</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>return</span> <span class='hs-varid'>ptr''</span>
<a name="line-243"></a> <span class='hs-conid'>Cursor</span> <span class='hs-varid'>x</span> <span class='hs-varid'>y</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyword'>do</span>
<a name="line-244"></a> <span class='hs-keyword'>let</span> <span class='hs-varid'>m</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>cursor_output_map</span> <span class='hs-varid'>ops</span> <span class='hs-varop'>$</span> <span class='hs-varid'>pic_cursor</span> <span class='hs-varid'>pic</span>
<a name="line-245"></a> <span class='hs-layout'>(</span><span class='hs-varid'>ox</span><span class='hs-layout'>,</span> <span class='hs-varid'>oy</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>char_to_output_pos</span> <span class='hs-varid'>m</span> <span class='hs-layout'>(</span><span class='hs-varid'>x</span><span class='hs-layout'>,</span><span class='hs-varid'>y</span><span class='hs-layout'>)</span>
<a name="line-246"></a> <span class='hs-varid'>serialize_show_cursor</span> <span class='hs-varid'>d</span> <span class='hs-varid'>ptr''</span> <span class='hs-varop'>>>=</span> <span class='hs-varid'>serialize_move_cursor</span> <span class='hs-varid'>d</span> <span class='hs-varid'>ox</span> <span class='hs-varid'>oy</span>
<a name="line-247"></a> <span class='hs-comment'>-- todo: How to handle exceptions?</span>
<a name="line-248"></a> <span class='hs-keyword'>case</span> <span class='hs-varid'>end_ptr</span> <span class='hs-varop'>`minusPtr`</span> <span class='hs-varid'>start_ptr</span> <span class='hs-keyword'>of</span>
<a name="line-249"></a> <span class='hs-varid'>count</span> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>count</span> <span class='hs-varop'><</span> <span class='hs-num'>0</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>fail</span> <span class='hs-str'>"End pointer before start of buffer."</span>
<a name="line-250"></a> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>toEnum</span> <span class='hs-varid'>count</span> <span class='hs-varop'>></span> <span class='hs-varid'>total</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>fail</span> <span class='hs-varop'>$</span> <span class='hs-str'>"End pointer past end of buffer by "</span> <span class='hs-varop'>++</span> <span class='hs-varid'>show</span> <span class='hs-layout'>(</span><span class='hs-varid'>toEnum</span> <span class='hs-varid'>count</span> <span class='hs-comment'>-</span> <span class='hs-varid'>total</span><span class='hs-layout'>)</span>
<a name="line-251"></a> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>otherwise</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>output_byte_buffer</span> <span class='hs-varid'>t</span> <span class='hs-varid'>start_ptr</span> <span class='hs-layout'>(</span><span class='hs-varid'>toEnum</span> <span class='hs-varid'>count</span><span class='hs-layout'>)</span>
<a name="line-252"></a> <span class='hs-comment'>-- Cache the output spans.</span>
<a name="line-253"></a> <span class='hs-varid'>liftIO</span> <span class='hs-varop'>$</span> <span class='hs-varid'>writeIORef</span> <span class='hs-layout'>(</span><span class='hs-varid'>previous_output_ref</span> <span class='hs-varid'>s</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span><span class='hs-conid'>Just</span> <span class='hs-varid'>ops</span><span class='hs-layout'>)</span>
<a name="line-254"></a> <span class='hs-varid'>return</span> <span class='hs-conid'>()</span>
<a name="line-255"></a>
<a name="line-256"></a><a name="required_bytes"></a><span class='hs-definition'>required_bytes</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>DisplayTerminal</span> <span class='hs-varid'>d</span> <span class='hs-keyglyph'>=></span> <span class='hs-varid'>d</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>FixedAttr</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>Bool</span><span class='hs-keyglyph'>]</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-257"></a><span class='hs-definition'>required_bytes</span> <span class='hs-varid'>d</span> <span class='hs-varid'>in_fattr</span> <span class='hs-varid'>diffs</span> <span class='hs-varid'>ops</span> <span class='hs-keyglyph'>=</span>
<a name="line-258"></a> <span class='hs-keyword'>let</span> <span class='hs-layout'>(</span><span class='hs-keyword'>_</span><span class='hs-layout'>,</span> <span class='hs-varid'>n</span><span class='hs-layout'>,</span> <span class='hs-keyword'>_</span><span class='hs-layout'>,</span> <span class='hs-keyword'>_</span><span class='hs-layout'>)</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'>required_bytes'</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'>in_fattr</span><span class='hs-layout'>,</span> <span class='hs-varid'>diffs</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span> <span class='hs-varid'>display_ops</span> <span class='hs-varid'>ops</span> <span class='hs-layout'>)</span>
<a name="line-259"></a> <span class='hs-keyword'>in</span> <span class='hs-varid'>n</span>
<a name="line-260"></a> <span class='hs-keyword'>where</span>
<a name="line-261"></a> <span class='hs-varid'>required_bytes'</span> <span class='hs-layout'>(</span><span class='hs-varid'>y</span><span class='hs-layout'>,</span> <span class='hs-varid'>current_sum</span><span class='hs-layout'>,</span> <span class='hs-varid'>fattr</span><span class='hs-layout'>,</span> <span class='hs-conid'>True</span> <span class='hs-conop'>:</span> <span class='hs-varid'>diffs'</span><span class='hs-layout'>)</span> <span class='hs-varid'>span_ops</span>
<a name="line-262"></a> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>let</span> <span class='hs-layout'>(</span><span class='hs-varid'>s</span><span class='hs-layout'>,</span> <span class='hs-varid'>fattr'</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>span_ops_required_bytes</span> <span class='hs-varid'>d</span> <span class='hs-varid'>y</span> <span class='hs-varid'>fattr</span> <span class='hs-varid'>span_ops</span>
<a name="line-263"></a> <span class='hs-keyword'>in</span> <span class='hs-layout'>(</span> <span class='hs-varid'>y</span> <span class='hs-varop'>+</span> <span class='hs-num'>1</span><span class='hs-layout'>,</span> <span class='hs-varid'>s</span> <span class='hs-varop'>+</span> <span class='hs-varid'>current_sum</span><span class='hs-layout'>,</span> <span class='hs-varid'>fattr'</span><span class='hs-layout'>,</span> <span class='hs-varid'>diffs'</span> <span class='hs-layout'>)</span>
<a name="line-264"></a> <span class='hs-varid'>required_bytes'</span> <span class='hs-layout'>(</span><span class='hs-varid'>y</span><span class='hs-layout'>,</span> <span class='hs-varid'>current_sum</span><span class='hs-layout'>,</span> <span class='hs-varid'>fattr</span><span class='hs-layout'>,</span> <span class='hs-conid'>False</span> <span class='hs-conop'>:</span> <span class='hs-varid'>diffs'</span><span class='hs-layout'>)</span> <span class='hs-sel'>_span_ops</span>
<a name="line-265"></a> <span class='hs-keyglyph'>=</span> <span class='hs-layout'>(</span> <span class='hs-varid'>y</span> <span class='hs-varop'>+</span> <span class='hs-num'>1</span><span class='hs-layout'>,</span> <span class='hs-varid'>current_sum</span><span class='hs-layout'>,</span> <span class='hs-varid'>fattr</span><span class='hs-layout'>,</span> <span class='hs-varid'>diffs'</span> <span class='hs-layout'>)</span>
<a name="line-266"></a> <span class='hs-varid'>required_bytes'</span> <span class='hs-layout'>(</span><span class='hs-sel'>_y</span><span class='hs-layout'>,</span> <span class='hs-sel'>_current_sum</span><span class='hs-layout'>,</span> <span class='hs-sel'>_fattr</span><span class='hs-layout'>,</span> <span class='hs-conid'>[]</span> <span class='hs-layout'>)</span> <span class='hs-sel'>_span_ops</span>
<a name="line-267"></a> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>error</span> <span class='hs-str'>"shouldn't be possible"</span>
<a name="line-268"></a>
<a name="line-269"></a><a name="span_ops_required_bytes"></a><span class='hs-definition'>span_ops_required_bytes</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>DisplayTerminal</span> <span class='hs-varid'>d</span> <span class='hs-keyglyph'>=></span> <span class='hs-varid'>d</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Word</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>FixedAttr</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>SpanOps</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'>FixedAttr</span><span class='hs-layout'>)</span>
<a name="line-270"></a><span class='hs-definition'>span_ops_required_bytes</span> <span class='hs-varid'>d</span> <span class='hs-varid'>y</span> <span class='hs-varid'>in_fattr</span> <span class='hs-varid'>span_ops</span> <span class='hs-keyglyph'>=</span>
<a name="line-271"></a> <span class='hs-comment'>-- The first operation is to set the cursor to the start of the row</span>
<a name="line-272"></a> <span class='hs-keyword'>let</span> <span class='hs-varid'>header_required_bytes</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>move_cursor_required_bytes</span> <span class='hs-varid'>d</span> <span class='hs-num'>0</span> <span class='hs-varid'>y</span>
<a name="line-273"></a> <span class='hs-comment'>-- then the span ops are serialized in the order specified</span>
<a name="line-274"></a> <span class='hs-keyword'>in</span> <span class='hs-conid'>Vector</span><span class='hs-varop'>.</span><span class='hs-varid'>foldl'</span> <span class='hs-layout'>(</span> <span class='hs-keyglyph'>\</span><span class='hs-layout'>(</span><span class='hs-varid'>current_sum</span><span class='hs-layout'>,</span> <span class='hs-varid'>fattr</span><span class='hs-layout'>)</span> <span class='hs-varid'>op</span> <span class='hs-keyglyph'>-></span> <span class='hs-keyword'>let</span> <span class='hs-layout'>(</span><span class='hs-varid'>c</span><span class='hs-layout'>,</span> <span class='hs-varid'>fattr'</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>span_op_required_bytes</span> <span class='hs-varid'>d</span> <span class='hs-varid'>fattr</span> <span class='hs-varid'>op</span>
<a name="line-275"></a> <span class='hs-keyword'>in</span> <span class='hs-layout'>(</span><span class='hs-varid'>c</span> <span class='hs-varop'>+</span> <span class='hs-varid'>current_sum</span><span class='hs-layout'>,</span> <span class='hs-varid'>fattr'</span><span class='hs-layout'>)</span>
<a name="line-276"></a> <span class='hs-layout'>)</span>
<a name="line-277"></a> <span class='hs-layout'>(</span><span class='hs-varid'>header_required_bytes</span><span class='hs-layout'>,</span> <span class='hs-varid'>in_fattr</span><span class='hs-layout'>)</span>
<a name="line-278"></a> <span class='hs-varid'>span_ops</span>
<a name="line-279"></a>
<a name="line-280"></a><a name="span_op_required_bytes"></a><span class='hs-definition'>span_op_required_bytes</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>DisplayTerminal</span> <span class='hs-varid'>d</span> <span class='hs-keyglyph'>=></span> <span class='hs-varid'>d</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>FixedAttr</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>SpanOp</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'>FixedAttr</span><span class='hs-layout'>)</span>
<a name="line-281"></a><span class='hs-definition'>span_op_required_bytes</span> <span class='hs-varid'>d</span> <span class='hs-varid'>fattr</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>
<a name="line-282"></a> <span class='hs-keyword'>let</span> <span class='hs-varid'>attr'</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>limit_attr_for_display</span> <span class='hs-varid'>d</span> <span class='hs-varid'>attr</span>
<a name="line-283"></a> <span class='hs-varid'>diffs</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>display_attr_diffs</span> <span class='hs-varid'>fattr</span> <span class='hs-varid'>fattr'</span>
<a name="line-284"></a> <span class='hs-varid'>c</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>attr_required_bytes</span> <span class='hs-varid'>d</span> <span class='hs-varid'>fattr</span> <span class='hs-varid'>attr'</span> <span class='hs-varid'>diffs</span>
<a name="line-285"></a> <span class='hs-varid'>fattr'</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>fix_display_attr</span> <span class='hs-varid'>fattr</span> <span class='hs-varid'>attr'</span>
<a name="line-286"></a> <span class='hs-keyword'>in</span> <span class='hs-layout'>(</span><span class='hs-varid'>c</span><span class='hs-layout'>,</span> <span class='hs-varid'>fattr'</span><span class='hs-layout'>)</span>
<a name="line-287"></a><span class='hs-definition'>span_op_required_bytes</span> <span class='hs-sel'>_d</span> <span class='hs-varid'>fattr</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'>str</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-layout'>(</span><span class='hs-varid'>utf8_text_required_bytes</span> <span class='hs-varid'>str</span><span class='hs-layout'>,</span> <span class='hs-varid'>fattr</span><span class='hs-layout'>)</span>
<a name="line-288"></a>
<a name="line-289"></a><a name="serialize_output_ops"></a><span class='hs-definition'>serialize_output_ops</span> <span class='hs-keyglyph'>::</span> <span class='hs-layout'>(</span> <span class='hs-conid'>MonadIO</span> <span class='hs-varid'>m</span><span class='hs-layout'>,</span> <span class='hs-conid'>DisplayTerminal</span> <span class='hs-varid'>d</span> <span class='hs-layout'>)</span>
<a name="line-290"></a> <span class='hs-keyglyph'>=></span> <span class='hs-varid'>d</span>
<a name="line-291"></a> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>OutputBuffer</span>
<a name="line-292"></a> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>FixedAttr</span>
<a name="line-293"></a> <span class='hs-keyglyph'>-></span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>Bool</span><span class='hs-keyglyph'>]</span>
<a name="line-294"></a> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>DisplayOps</span>
<a name="line-295"></a> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>m</span> <span class='hs-conid'>OutputBuffer</span>
<a name="line-296"></a><span class='hs-definition'>serialize_output_ops</span> <span class='hs-varid'>d</span> <span class='hs-varid'>start_ptr</span> <span class='hs-varid'>in_fattr</span> <span class='hs-varid'>diffs</span> <span class='hs-varid'>ops</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>do</span>
<a name="line-297"></a> <span class='hs-layout'>(</span><span class='hs-keyword'>_</span><span class='hs-layout'>,</span> <span class='hs-varid'>end_ptr</span><span class='hs-layout'>,</span> <span class='hs-keyword'>_</span><span class='hs-layout'>,</span> <span class='hs-keyword'>_</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'><-</span> <span class='hs-conid'>Vector</span><span class='hs-varop'>.</span><span class='hs-varid'>foldM'</span> <span class='hs-varid'>serialize_output_ops'</span>
<a name="line-298"></a> <span class='hs-layout'>(</span> <span class='hs-num'>0</span><span class='hs-layout'>,</span> <span class='hs-varid'>start_ptr</span><span class='hs-layout'>,</span> <span class='hs-varid'>in_fattr</span><span class='hs-layout'>,</span> <span class='hs-varid'>diffs</span> <span class='hs-layout'>)</span>
<a name="line-299"></a> <span class='hs-layout'>(</span> <span class='hs-varid'>display_ops</span> <span class='hs-varid'>ops</span> <span class='hs-layout'>)</span>
<a name="line-300"></a> <span class='hs-varid'>return</span> <span class='hs-varid'>end_ptr</span>
<a name="line-301"></a> <span class='hs-keyword'>where</span>
<a name="line-302"></a> <span class='hs-varid'>serialize_output_ops'</span> <span class='hs-layout'>(</span> <span class='hs-varid'>y</span><span class='hs-layout'>,</span> <span class='hs-varid'>out_ptr</span><span class='hs-layout'>,</span> <span class='hs-varid'>fattr</span><span class='hs-layout'>,</span> <span class='hs-conid'>True</span> <span class='hs-conop'>:</span> <span class='hs-varid'>diffs'</span> <span class='hs-layout'>)</span> <span class='hs-varid'>span_ops</span>
<a name="line-303"></a> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>serialize_span_ops</span> <span class='hs-varid'>d</span> <span class='hs-varid'>y</span> <span class='hs-varid'>out_ptr</span> <span class='hs-varid'>fattr</span> <span class='hs-varid'>span_ops</span>
<a name="line-304"></a> <span class='hs-varop'>>>=</span> <span class='hs-varid'>return</span> <span class='hs-varop'>.</span> <span class='hs-layout'>(</span> <span class='hs-keyglyph'>\</span><span class='hs-layout'>(</span><span class='hs-varid'>out_ptr'</span><span class='hs-layout'>,</span> <span class='hs-varid'>fattr'</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span> <span class='hs-varid'>y</span> <span class='hs-varop'>+</span> <span class='hs-num'>1</span><span class='hs-layout'>,</span> <span class='hs-varid'>out_ptr'</span><span class='hs-layout'>,</span> <span class='hs-varid'>fattr'</span><span class='hs-layout'>,</span> <span class='hs-varid'>diffs'</span> <span class='hs-layout'>)</span> <span class='hs-layout'>)</span>
<a name="line-305"></a> <span class='hs-varid'>serialize_output_ops'</span> <span class='hs-layout'>(</span> <span class='hs-varid'>y</span><span class='hs-layout'>,</span> <span class='hs-varid'>out_ptr</span><span class='hs-layout'>,</span> <span class='hs-varid'>fattr</span><span class='hs-layout'>,</span> <span class='hs-conid'>False</span> <span class='hs-conop'>:</span> <span class='hs-varid'>diffs'</span> <span class='hs-layout'>)</span> <span class='hs-sel'>_span_ops</span>
<a name="line-306"></a> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>return</span> <span class='hs-layout'>(</span> <span class='hs-varid'>y</span> <span class='hs-varop'>+</span> <span class='hs-num'>1</span><span class='hs-layout'>,</span> <span class='hs-varid'>out_ptr</span><span class='hs-layout'>,</span> <span class='hs-varid'>fattr</span><span class='hs-layout'>,</span> <span class='hs-varid'>diffs'</span> <span class='hs-layout'>)</span>
<a name="line-307"></a> <span class='hs-varid'>serialize_output_ops'</span> <span class='hs-layout'>(</span><span class='hs-sel'>_y</span><span class='hs-layout'>,</span> <span class='hs-sel'>_out_ptr</span><span class='hs-layout'>,</span> <span class='hs-sel'>_fattr</span><span class='hs-layout'>,</span> <span class='hs-conid'>[]</span> <span class='hs-layout'>)</span> <span class='hs-sel'>_span_ops</span>
<a name="line-308"></a> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>error</span> <span class='hs-str'>"shouldn't be possible"</span>
<a name="line-309"></a>
<a name="line-310"></a><a name="serialize_span_ops"></a><span class='hs-definition'>serialize_span_ops</span> <span class='hs-keyglyph'>::</span> <span class='hs-layout'>(</span> <span class='hs-conid'>MonadIO</span> <span class='hs-varid'>m</span><span class='hs-layout'>,</span> <span class='hs-conid'>DisplayTerminal</span> <span class='hs-varid'>d</span> <span class='hs-layout'>)</span>
<a name="line-311"></a> <span class='hs-keyglyph'>=></span> <span class='hs-varid'>d</span>
<a name="line-312"></a> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Word</span>
<a name="line-313"></a> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>OutputBuffer</span>
<a name="line-314"></a> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>FixedAttr</span>
<a name="line-315"></a> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>SpanOps</span>
<a name="line-316"></a> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>m</span> <span class='hs-layout'>(</span><span class='hs-conid'>OutputBuffer</span><span class='hs-layout'>,</span> <span class='hs-conid'>FixedAttr</span><span class='hs-layout'>)</span>
<a name="line-317"></a><span class='hs-definition'>serialize_span_ops</span> <span class='hs-varid'>d</span> <span class='hs-varid'>y</span> <span class='hs-varid'>out_ptr</span> <span class='hs-varid'>in_fattr</span> <span class='hs-varid'>span_ops</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>do</span>
<a name="line-318"></a> <span class='hs-comment'>-- The first operation is to set the cursor to the start of the row</span>
<a name="line-319"></a> <span class='hs-varid'>out_ptr'</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>serialize_move_cursor</span> <span class='hs-varid'>d</span> <span class='hs-num'>0</span> <span class='hs-varid'>y</span> <span class='hs-varid'>out_ptr</span>
<a name="line-320"></a> <span class='hs-comment'>-- then the span ops are serialized in the order specified</span>
<a name="line-321"></a> <span class='hs-conid'>Vector</span><span class='hs-varop'>.</span><span class='hs-varid'>foldM</span> <span class='hs-layout'>(</span> <span class='hs-keyglyph'>\</span><span class='hs-layout'>(</span><span class='hs-varid'>out_ptr''</span><span class='hs-layout'>,</span> <span class='hs-varid'>fattr</span><span class='hs-layout'>)</span> <span class='hs-varid'>op</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>serialize_span_op</span> <span class='hs-varid'>d</span> <span class='hs-varid'>op</span> <span class='hs-varid'>out_ptr''</span> <span class='hs-varid'>fattr</span> <span class='hs-layout'>)</span>
<a name="line-322"></a> <span class='hs-layout'>(</span><span class='hs-varid'>out_ptr'</span><span class='hs-layout'>,</span> <span class='hs-varid'>in_fattr</span><span class='hs-layout'>)</span>
<a name="line-323"></a> <span class='hs-varid'>span_ops</span>
<a name="line-324"></a>
<a name="line-325"></a><a name="serialize_span_op"></a><span class='hs-definition'>serialize_span_op</span> <span class='hs-keyglyph'>::</span> <span class='hs-layout'>(</span> <span class='hs-conid'>MonadIO</span> <span class='hs-varid'>m</span><span class='hs-layout'>,</span> <span class='hs-conid'>DisplayTerminal</span> <span class='hs-varid'>d</span> <span class='hs-layout'>)</span>
<a name="line-326"></a> <span class='hs-keyglyph'>=></span> <span class='hs-varid'>d</span>
<a name="line-327"></a> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>SpanOp</span>
<a name="line-328"></a> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>OutputBuffer</span>
<a name="line-329"></a> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>FixedAttr</span>
<a name="line-330"></a> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>m</span> <span class='hs-layout'>(</span><span class='hs-conid'>OutputBuffer</span><span class='hs-layout'>,</span> <span class='hs-conid'>FixedAttr</span><span class='hs-layout'>)</span>
<a name="line-331"></a><span class='hs-definition'>serialize_span_op</span> <span class='hs-varid'>d</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-varid'>out_ptr</span> <span class='hs-varid'>fattr</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>do</span>
<a name="line-332"></a> <span class='hs-keyword'>let</span> <span class='hs-varid'>attr'</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>limit_attr_for_display</span> <span class='hs-varid'>d</span> <span class='hs-varid'>attr</span>
<a name="line-333"></a> <span class='hs-varid'>fattr'</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>fix_display_attr</span> <span class='hs-varid'>fattr</span> <span class='hs-varid'>attr'</span>
<a name="line-334"></a> <span class='hs-varid'>diffs</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>display_attr_diffs</span> <span class='hs-varid'>fattr</span> <span class='hs-varid'>fattr'</span>
<a name="line-335"></a> <span class='hs-varid'>out_ptr'</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>serialize_set_attr</span> <span class='hs-varid'>d</span> <span class='hs-varid'>fattr</span> <span class='hs-varid'>attr'</span> <span class='hs-varid'>diffs</span> <span class='hs-varid'>out_ptr</span>
<a name="line-336"></a> <span class='hs-varid'>return</span> <span class='hs-layout'>(</span><span class='hs-varid'>out_ptr'</span><span class='hs-layout'>,</span> <span class='hs-varid'>fattr'</span><span class='hs-layout'>)</span>
<a name="line-337"></a><span class='hs-definition'>serialize_span_op</span> <span class='hs-sel'>_d</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'>str</span><span class='hs-layout'>)</span> <span class='hs-varid'>out_ptr</span> <span class='hs-varid'>fattr</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>do</span>
<a name="line-338"></a> <span class='hs-varid'>out_ptr'</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>serialize_utf8_text</span> <span class='hs-varid'>str</span> <span class='hs-varid'>out_ptr</span>
<a name="line-339"></a> <span class='hs-varid'>return</span> <span class='hs-layout'>(</span><span class='hs-varid'>out_ptr'</span><span class='hs-layout'>,</span> <span class='hs-varid'>fattr</span><span class='hs-layout'>)</span>
<a name="line-340"></a>
<a name="line-341"></a><a name="marshall_to_terminal"></a><span class='hs-definition'>marshall_to_terminal</span> <span class='hs-keyglyph'>::</span> <span class='hs-layout'>(</span> <span class='hs-conid'>Terminal</span> <span class='hs-varid'>t</span> <span class='hs-layout'>)</span>
<a name="line-342"></a> <span class='hs-keyglyph'>=></span> <span class='hs-varid'>t</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Word</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-conid'>Ptr</span> <span class='hs-conid'>Word8</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-layout'>(</span><span class='hs-conid'>Ptr</span> <span class='hs-conid'>Word8</span><span class='hs-layout'>)</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>IO</span> <span class='hs-conid'>()</span>
<a name="line-343"></a><span class='hs-definition'>marshall_to_terminal</span> <span class='hs-varid'>t</span> <span class='hs-varid'>c</span> <span class='hs-varid'>f</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>do</span>
<a name="line-344"></a> <span class='hs-varid'>start_ptr</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>mallocBytes</span> <span class='hs-layout'>(</span><span class='hs-varid'>fromEnum</span> <span class='hs-varid'>c</span><span class='hs-layout'>)</span>
<a name="line-345"></a> <span class='hs-comment'>-- </span>
<a name="line-346"></a> <span class='hs-comment'>-- todo: capture exceptions?</span>
<a name="line-347"></a> <span class='hs-varid'>end_ptr</span> <span class='hs-keyglyph'><-</span> <span class='hs-varid'>f</span> <span class='hs-varid'>start_ptr</span>
<a name="line-348"></a> <span class='hs-keyword'>case</span> <span class='hs-varid'>end_ptr</span> <span class='hs-varop'>`minusPtr`</span> <span class='hs-varid'>start_ptr</span> <span class='hs-keyword'>of</span>
<a name="line-349"></a> <span class='hs-varid'>count</span> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>count</span> <span class='hs-varop'><</span> <span class='hs-num'>0</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>fail</span> <span class='hs-str'>"End pointer before start pointer."</span>
<a name="line-350"></a> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>toEnum</span> <span class='hs-varid'>count</span> <span class='hs-varop'>></span> <span class='hs-varid'>c</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>fail</span> <span class='hs-varop'>$</span> <span class='hs-str'>"End pointer past end of buffer by "</span> <span class='hs-varop'>++</span> <span class='hs-varid'>show</span> <span class='hs-layout'>(</span><span class='hs-varid'>toEnum</span> <span class='hs-varid'>count</span> <span class='hs-comment'>-</span> <span class='hs-varid'>c</span><span class='hs-layout'>)</span>
<a name="line-351"></a> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>otherwise</span> <span class='hs-keyglyph'>-></span> <span class='hs-varid'>output_byte_buffer</span> <span class='hs-varid'>t</span> <span class='hs-varid'>start_ptr</span> <span class='hs-layout'>(</span><span class='hs-varid'>toEnum</span> <span class='hs-varid'>count</span><span class='hs-layout'>)</span>
<a name="line-352"></a> <span class='hs-varid'>free</span> <span class='hs-varid'>start_ptr</span>
<a name="line-353"></a> <span class='hs-varid'>return</span> <span class='hs-conid'>()</span>
<a name="line-354"></a>
<a name="line-355"></a><a name="CursorOutputMap"></a><span class='hs-keyword'>data</span> <span class='hs-conid'>CursorOutputMap</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>CursorOutputMap</span>
<a name="line-356"></a> <span class='hs-layout'>{</span> <span class='hs-varid'>char_to_output_pos</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-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-357"></a> <span class='hs-layout'>}</span>
<a name="line-358"></a>
<a name="line-359"></a><a name="cursor_output_map"></a><span class='hs-definition'>cursor_output_map</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>DisplayOps</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Cursor</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>CursorOutputMap</span>
<a name="line-360"></a><span class='hs-definition'>cursor_output_map</span> <span class='hs-varid'>span_ops</span> <span class='hs-sel'>_cursor</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>CursorOutputMap</span>
<a name="line-361"></a> <span class='hs-layout'>{</span> <span class='hs-varid'>char_to_output_pos</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyglyph'>\</span><span class='hs-layout'>(</span><span class='hs-varid'>cx</span><span class='hs-layout'>,</span> <span class='hs-varid'>cy</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-varid'>cursor_column_offset</span> <span class='hs-varid'>span_ops</span> <span class='hs-varid'>cx</span> <span class='hs-varid'>cy</span><span class='hs-layout'>,</span> <span class='hs-varid'>cy</span><span class='hs-layout'>)</span>
<a name="line-362"></a> <span class='hs-layout'>}</span>
<a name="line-363"></a>
<a name="line-364"></a><a name="cursor_column_offset"></a><span class='hs-definition'>cursor_column_offset</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>DisplayOps</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Word</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Word</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Word</span>
<a name="line-365"></a><span class='hs-definition'>cursor_column_offset</span> <span class='hs-varid'>span_ops</span> <span class='hs-varid'>cx</span> <span class='hs-varid'>cy</span> <span class='hs-keyglyph'>=</span>
<a name="line-366"></a> <span class='hs-keyword'>let</span> <span class='hs-varid'>cursor_row_ops</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Vector</span><span class='hs-varop'>.</span><span class='hs-varid'>unsafeIndex</span> <span class='hs-layout'>(</span><span class='hs-varid'>display_ops</span> <span class='hs-varid'>span_ops</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span><span class='hs-varid'>fromEnum</span> <span class='hs-varid'>cy</span><span class='hs-layout'>)</span>
<a name="line-367"></a> <span class='hs-layout'>(</span><span class='hs-varid'>out_offset</span><span class='hs-layout'>,</span> <span class='hs-keyword'>_</span><span class='hs-layout'>,</span> <span class='hs-keyword'>_</span><span class='hs-layout'>)</span>
<a name="line-368"></a> <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-layout'>(</span> <span class='hs-keyglyph'>\</span><span class='hs-layout'>(</span><span class='hs-varid'>d</span><span class='hs-layout'>,</span> <span class='hs-varid'>current_cx</span><span class='hs-layout'>,</span> <span class='hs-varid'>done</span><span class='hs-layout'>)</span> <span class='hs-varid'>op</span> <span class='hs-keyglyph'>-></span>
<a name="line-369"></a> <span class='hs-keyword'>if</span> <span class='hs-varid'>done</span> <span class='hs-keyword'>then</span> <span class='hs-layout'>(</span><span class='hs-varid'>d</span><span class='hs-layout'>,</span> <span class='hs-varid'>current_cx</span><span class='hs-layout'>,</span> <span class='hs-varid'>done</span><span class='hs-layout'>)</span> <span class='hs-keyword'>else</span> <span class='hs-keyword'>case</span> <span class='hs-varid'>span_op_has_width</span> <span class='hs-varid'>op</span> <span class='hs-keyword'>of</span>
<a name="line-370"></a> <span class='hs-conid'>Nothing</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span><span class='hs-varid'>d</span><span class='hs-layout'>,</span> <span class='hs-varid'>current_cx</span><span class='hs-layout'>,</span> <span class='hs-conid'>False</span><span class='hs-layout'>)</span>
<a name="line-371"></a> <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> <span class='hs-keyglyph'>-></span> <span class='hs-keyword'>case</span> <span class='hs-varid'>compare</span> <span class='hs-varid'>cx</span> <span class='hs-layout'>(</span><span class='hs-varid'>current_cx</span> <span class='hs-varop'>+</span> <span class='hs-varid'>cw</span><span class='hs-layout'>)</span> <span class='hs-keyword'>of</span>
<a name="line-372"></a> <span class='hs-conid'>GT</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span> <span class='hs-varid'>d</span> <span class='hs-varop'>+</span> <span class='hs-varid'>ow</span>
<a name="line-373"></a> <span class='hs-layout'>,</span> <span class='hs-varid'>current_cx</span> <span class='hs-varop'>+</span> <span class='hs-varid'>cw</span>
<a name="line-374"></a> <span class='hs-layout'>,</span> <span class='hs-conid'>False</span>
<a name="line-375"></a> <span class='hs-layout'>)</span>
<a name="line-376"></a> <span class='hs-conid'>EQ</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span> <span class='hs-varid'>d</span> <span class='hs-varop'>+</span> <span class='hs-varid'>ow</span>
<a name="line-377"></a> <span class='hs-layout'>,</span> <span class='hs-varid'>current_cx</span> <span class='hs-varop'>+</span> <span class='hs-varid'>cw</span>
<a name="line-378"></a> <span class='hs-layout'>,</span> <span class='hs-conid'>True</span>
<a name="line-379"></a> <span class='hs-layout'>)</span>
<a name="line-380"></a> <span class='hs-conid'>LT</span> <span class='hs-keyglyph'>-></span> <span class='hs-layout'>(</span> <span class='hs-varid'>d</span> <span class='hs-varop'>+</span> <span class='hs-varid'>columns_to_char_offset</span> <span class='hs-layout'>(</span><span class='hs-varid'>cx</span> <span class='hs-comment'>-</span> <span class='hs-varid'>current_cx</span><span class='hs-layout'>)</span> <span class='hs-varid'>op</span>
<a name="line-381"></a> <span class='hs-layout'>,</span> <span class='hs-varid'>current_cx</span> <span class='hs-varop'>+</span> <span class='hs-varid'>cw</span>
<a name="line-382"></a> <span class='hs-layout'>,</span> <span class='hs-conid'>True</span>
<a name="line-383"></a> <span class='hs-layout'>)</span>
<a name="line-384"></a> <span class='hs-layout'>)</span>
<a name="line-385"></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> <span class='hs-conid'>False</span><span class='hs-layout'>)</span>
<a name="line-386"></a> <span class='hs-varid'>cursor_row_ops</span>
<a name="line-387"></a> <span class='hs-keyword'>in</span> <span class='hs-varid'>out_offset</span>
<a name="line-388"></a>
<a name="line-389"></a><a name="limit_attr_for_display"></a><span class='hs-definition'>limit_attr_for_display</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>DisplayTerminal</span> <span class='hs-varid'>d</span> <span class='hs-keyglyph'>=></span> <span class='hs-varid'>d</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Attr</span> <span class='hs-keyglyph'>-></span> <span class='hs-conid'>Attr</span>
<a name="line-390"></a><span class='hs-definition'>limit_attr_for_display</span> <span class='hs-varid'>d</span> <span class='hs-varid'>attr</span>
<a name="line-391"></a> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>attr</span> <span class='hs-layout'>{</span> <span class='hs-varid'>attr_fore_color</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>clamp_color</span> <span class='hs-varop'>$</span> <span class='hs-varid'>attr_fore_color</span> <span class='hs-varid'>attr</span>
<a name="line-392"></a> <span class='hs-layout'>,</span> <span class='hs-varid'>attr_back_color</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>clamp_color</span> <span class='hs-varop'>$</span> <span class='hs-varid'>attr_back_color</span> <span class='hs-varid'>attr</span>
<a name="line-393"></a> <span class='hs-layout'>}</span>
<a name="line-394"></a> <span class='hs-keyword'>where</span>
<a name="line-395"></a> <span class='hs-varid'>clamp_color</span> <span class='hs-conid'>Default</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Default</span>
<a name="line-396"></a> <span class='hs-varid'>clamp_color</span> <span class='hs-conid'>KeepCurrent</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>KeepCurrent</span>
<a name="line-397"></a> <span class='hs-varid'>clamp_color</span> <span class='hs-layout'>(</span><span class='hs-conid'>SetTo</span> <span class='hs-varid'>c</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>clamp_color'</span> <span class='hs-varid'>c</span>
<a name="line-398"></a> <span class='hs-varid'>clamp_color'</span> <span class='hs-layout'>(</span><span class='hs-conid'>ISOColor</span> <span class='hs-varid'>v</span><span class='hs-layout'>)</span>
<a name="line-399"></a> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>context_color_count</span> <span class='hs-varid'>d</span> <span class='hs-varop'><</span> <span class='hs-num'>8</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Default</span>
<a name="line-400"></a> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>context_color_count</span> <span class='hs-varid'>d</span> <span class='hs-varop'><</span> <span class='hs-num'>16</span> <span class='hs-varop'>&&</span> <span class='hs-varid'>v</span> <span class='hs-varop'>>=</span> <span class='hs-num'>8</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>SetTo</span> <span class='hs-varop'>$</span> <span class='hs-conid'>ISOColor</span> <span class='hs-layout'>(</span><span class='hs-varid'>v</span> <span class='hs-comment'>-</span> <span class='hs-num'>8</span><span class='hs-layout'>)</span>
<a name="line-401"></a> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>otherwise</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>SetTo</span> <span class='hs-varop'>$</span> <span class='hs-conid'>ISOColor</span> <span class='hs-varid'>v</span>
<a name="line-402"></a> <span class='hs-varid'>clamp_color'</span> <span class='hs-layout'>(</span><span class='hs-conid'>Color240</span> <span class='hs-varid'>v</span><span class='hs-layout'>)</span>
<a name="line-403"></a> <span class='hs-comment'>-- TODO: Choose closes ISO color?</span>
<a name="line-404"></a> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>context_color_count</span> <span class='hs-varid'>d</span> <span class='hs-varop'><</span> <span class='hs-num'>8</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Default</span>
<a name="line-405"></a> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>context_color_count</span> <span class='hs-varid'>d</span> <span class='hs-varop'><</span> <span class='hs-num'>16</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Default</span>
<a name="line-406"></a> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>context_color_count</span> <span class='hs-varid'>d</span> <span class='hs-varop'>==</span> <span class='hs-num'>240</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>SetTo</span> <span class='hs-varop'>$</span> <span class='hs-conid'>Color240</span> <span class='hs-varid'>v</span>
<a name="line-407"></a> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>otherwise</span>
<a name="line-408"></a> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>let</span> <span class='hs-varid'>p</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>Double</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>fromIntegral</span> <span class='hs-varid'>v</span> <span class='hs-varop'>/</span> <span class='hs-num'>240.0</span>
<a name="line-409"></a> <span class='hs-varid'>v'</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>floor</span> <span class='hs-varop'>$</span> <span class='hs-varid'>p</span> <span class='hs-varop'>*</span> <span class='hs-layout'>(</span><span class='hs-varid'>fromIntegral</span> <span class='hs-varop'>$</span> <span class='hs-varid'>context_color_count</span> <span class='hs-varid'>d</span><span class='hs-layout'>)</span>
<a name="line-410"></a> <span class='hs-keyword'>in</span> <span class='hs-conid'>SetTo</span> <span class='hs-varop'>$</span> <span class='hs-conid'>Color240</span> <span class='hs-varid'>v'</span>
<a name="line-411"></a>
</pre></body>
</html>
|