about summary refs log tree commit diff stats
path: root/html/edit.mu.html
blob: 157998e33e9338ace0f3900d37300666e1597d1e (plain) (blame)
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
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Mu - edit.mu</title>
<meta name="Generator" content="Vim/7.4">
<meta name="plugin-version" content="vim7.4_v1">
<meta name="syntax" content="none">
<meta name="settings" content="use_css,pre_wrap,no_foldcolumn,expand_tabs,prevent_copy=">
<meta name="colorscheme" content="minimal">
<style type="text/css">
<!--
pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; }
body { font-family: monospace; color: #eeeeee; background-color: #080808; }
* { font-size: 1.05em; }
.muScenario { color: #00af00; }
.Delimiter { color: #a04060; }
.SalientComment { color: #00ffff; }
.Comment { color: #9090ff; }
.Constant { color: #00a0a0; }
.Special { color: #ff6060; }
.CommentedCode { color: #6c6c6c; }
.muControl { color: #c0a020; }
.muRecipe { color: #ff8700; }
-->
</style>

<script type='text/javascript'>
<!--

-->
</script>
</head>
<body>
<pre id='vimCodeElement'>
<span class="Comment"># Editor widget: takes a string and screen coordinates, modifying them in place.</span>

<span class="muRecipe">recipe</span> main [
  <span class="Constant">default-space</span>:address:array:location<span class="Special"> &lt;- </span>new location:type, <span class="Constant">30:literal</span>
  open-console
  width:number<span class="Special"> &lt;- </span>display-width
  height:number<span class="Special"> &lt;- </span>display-height
  divider:number, _<span class="Special"> &lt;- </span>divide-with-remainder width:number, <span class="Constant">2:literal</span>
  draw-vertical <span class="Constant">0:literal/screen</span>, divider:number, <span class="Constant">0:literal/top</span>, height:number
  in:address:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[abcdef</span>
<span class="Constant">def</span>
<span class="Constant">ghi</span>
<span class="Constant">jkl</span>
<span class="Constant">]</span>
  editor:address:editor-data<span class="Special"> &lt;- </span>new-editor in:address:array:character, <span class="Constant">0:literal/screen</span>, <span class="Constant">0:literal/top</span>, <span class="Constant">0:literal/left</span>, divider:number/right
  event-loop <span class="Constant">0:literal/screen</span>, <span class="Constant">0:literal/events</span>, editor:address:editor-data
  close-console
]

<span class="muScenario">scenario</span> editor-initially-prints-string-to-screen [
  assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span>
  run [
    s:address:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[abc]</span>
    new-editor s:address:array:character, screen:address, <span class="Constant">0:literal/top</span>, <span class="Constant">0:literal/left</span>, <span class="Constant">5:literal/right</span>
  ]
  screen-should-contain [
   <span class="Constant"> .abc       .</span>
   <span class="Constant"> .          .</span>
  ]
]

<span class="SalientComment">## In which we introduce the editor data structure, and show how it displays</span>
<span class="SalientComment">## text to the screen.</span>

container editor-data [
  <span class="Comment"># doubly linked list of characters</span>
  data:address:duplex-list
  <span class="Comment"># location of top-left of screen inside data (scrolling)</span>
  top-of-screen:address:duplex-list
  <span class="Comment"># location of cursor inside data</span>
  cursor:address:duplex-list

  screen:address:screen
  <span class="Comment"># raw bounds of display area on screen</span>
  top:number
  left:number
  bottom:number
  right:number
  <span class="Comment"># raw screen coordinates of cursor</span>
  cursor-row:number
  cursor-column:number
]

<span class="Comment"># editor:address, screen:address &lt;- new-editor s:address:array:character, screen:address, top:number, left:number, bottom:number</span>
<span class="Comment"># creates a new editor widget and renders its initial appearance to screen.</span>
<span class="Comment">#   top/left/right constrain the screen area available to the new editor.</span>
<span class="Comment">#   right is exclusive.</span>
<span class="muRecipe">recipe</span> new-editor [
  <span class="Constant">default-space</span>:address:array:location<span class="Special"> &lt;- </span>new location:type, <span class="Constant">30:literal</span>
  s:address:array:character<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  screen:address<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Comment"># no clipping of bounds</span>
  top:number<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  left:number<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  right:number<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  right:number<span class="Special"> &lt;- </span>subtract right:number, <span class="Constant">1:literal</span>
  result:address:editor-data<span class="Special"> &lt;- </span>new editor-data:type
  <span class="Comment"># initialize screen-related fields</span>
  sc:address:address:screen<span class="Special"> &lt;- </span>get-address result:address:editor-data/deref, screen:offset
  sc:address:address:screen/deref<span class="Special"> &lt;- </span>copy screen:address
  x:address:number<span class="Special"> &lt;- </span>get-address result:address:editor-data/deref, top:offset
  x:address:number/deref<span class="Special"> &lt;- </span>copy top:number
  x:address:number<span class="Special"> &lt;- </span>get-address result:address:editor-data/deref, left:offset
  x:address:number/deref<span class="Special"> &lt;- </span>copy left:number
  x:address:number<span class="Special"> &lt;- </span>get-address result:address:editor-data/deref, right:offset
  x:address:number/deref<span class="Special"> &lt;- </span>copy right:number
  <span class="Comment"># initialize bottom to top for starters</span>
  x:address:number<span class="Special"> &lt;- </span>get-address result:address:editor-data/deref, bottom:offset
  x:address:number/deref<span class="Special"> &lt;- </span>copy top:number
  <span class="Comment"># initialize cursor</span>
  x:address:number<span class="Special"> &lt;- </span>get-address result:address:editor-data/deref, cursor-row:offset
  x:address:number/deref<span class="Special"> &lt;- </span>copy top:number
  x:address:number<span class="Special"> &lt;- </span>get-address result:address:editor-data/deref, cursor-column:offset
  x:address:number/deref<span class="Special"> &lt;- </span>copy left:number
  <span class="Comment"># early exit if s is empty</span>
  <span class="muControl">reply-unless</span> s:address:array:character, result:address:editor-data
  len:number<span class="Special"> &lt;- </span>length s:address:array:character/deref
  <span class="muControl">reply-unless</span> len:number, result:address:editor-data
  idx:number<span class="Special"> &lt;- </span>copy <span class="Constant">0:literal</span>
  <span class="Comment"># s is guaranteed to have at least one character, so initialize result's</span>
  <span class="Comment"># duplex-list</span>
  init:address:address:duplex-list<span class="Special"> &lt;- </span>get-address result:address:editor-data/deref, top-of-screen:offset
  init:address:address:duplex-list/deref<span class="Special"> &lt;- </span>copy <span class="Constant">0:literal</span>
  c:character<span class="Special"> &lt;- </span>index s:address:array:character/deref, idx:number
  idx:number<span class="Special"> &lt;- </span>add idx:number, <span class="Constant">1:literal</span>
  init:address:address:duplex-list/deref<span class="Special"> &lt;- </span>push c:character, init:address:address:duplex-list/deref
  curr:address:duplex-list<span class="Special"> &lt;- </span>copy init:address:address:duplex-list/deref
  <span class="Comment"># now we can start appending the rest, character by character</span>
  <span class="Delimiter">{</span>
<span class="CommentedCode">#?     $print idx:number, [ vs ], len:number, [ </span>
<span class="CommentedCode">#? ] #? 1</span>
    done?:boolean<span class="Special"> &lt;- </span>greater-or-equal idx:number, len:number
    <span class="muControl">break-if</span> done?:boolean
    c:character<span class="Special"> &lt;- </span>index s:address:array:character/deref, idx:number
<span class="CommentedCode">#?     $print [aa: ], c:character, [ </span>
<span class="CommentedCode">#? ] #? 1</span>
    insert-duplex c:character, curr:address:duplex-list
    <span class="Comment"># next iter</span>
    curr:address:duplex-list<span class="Special"> &lt;- </span>next-duplex curr:address:duplex-list
    idx:number<span class="Special"> &lt;- </span>add idx:number, <span class="Constant">1:literal</span>
    <span class="muControl">loop</span>
  <span class="Delimiter">}</span>
  <span class="Comment"># initialize cursor to top of screen</span>
  y:address:address:duplex-list<span class="Special"> &lt;- </span>get-address result:address:editor-data/deref, cursor:offset
  y:address:address:duplex-list/deref<span class="Special"> &lt;- </span>copy init:address:address:duplex-list/deref
  <span class="Comment"># perform initial rendering to screen</span>
  bottom:address:number<span class="Special"> &lt;- </span>get-address result:address:editor-data/deref, bottom:offset
  bottom:address:number/deref, screen:address<span class="Special"> &lt;- </span>render result:address:editor-data, screen:address, top:number, left:number, right:number
  <span class="muControl">reply</span> result:address:editor-data
]

<span class="muScenario">scenario</span> editor-initializes-without-data [
  assume-screen <span class="Constant">5:literal/width</span>, <span class="Constant">3:literal/height</span>
  run [
    1:address:editor-data<span class="Special"> &lt;- </span>new-editor <span class="Constant">0:literal/data</span>, screen:address, <span class="Constant">1:literal/top</span>, <span class="Constant">2:literal/left</span>, <span class="Constant">5:literal/right</span>
    2:editor-data<span class="Special"> &lt;- </span>copy 1:address:editor-data/deref
  ]
  memory-should-contain [
    2<span class="Special"> &lt;- </span>0  <span class="Comment"># data</span>
    3<span class="Special"> &lt;- </span>0  <span class="Comment"># pointer into data to top of screen</span>
    4<span class="Special"> &lt;- </span>0  <span class="Comment"># pointer into data to cursor</span>
    <span class="Comment"># 5 &lt;- screen</span>
    6<span class="Special"> &lt;- </span>1  <span class="Comment"># top</span>
    7<span class="Special"> &lt;- </span>2  <span class="Comment"># left</span>
    8<span class="Special"> &lt;- </span>1  <span class="Comment"># bottom</span>
    9<span class="Special"> &lt;- </span>4  <span class="Comment"># right  (inclusive)</span>
    10<span class="Special"> &lt;- </span>1  <span class="Comment"># cursor row</span>
    11<span class="Special"> &lt;- </span>2  <span class="Comment"># cursor column</span>
  ]
  screen-should-contain [
   <span class="Constant"> .     .</span>
   <span class="Constant"> .     .</span>
   <span class="Constant"> .     .</span>
  ]
]

<span class="muRecipe">recipe</span> render [
  <span class="Constant">default-space</span>:address:array:location<span class="Special"> &lt;- </span>new location:type, <span class="Constant">30:literal</span>
  editor:address:editor-data<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  screen:address<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  top:number<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  left:number<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  screen-height:number<span class="Special"> &lt;- </span>screen-height screen:address
  right:number<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  cursor:address:duplex-list<span class="Special"> &lt;- </span>get editor:address:editor-data/deref, cursor:offset
  <span class="Comment"># traversing editor</span>
  curr:address:duplex-list<span class="Special"> &lt;- </span>get editor:address:editor-data/deref, top-of-screen:offset
  <span class="Comment"># traversing screen</span>
  row:number<span class="Special"> &lt;- </span>copy top:number
  column:number<span class="Special"> &lt;- </span>copy left:number
  move-cursor screen:address, row:number, column:number
  <span class="Delimiter">{</span>
<span class="Constant">    +next-character</span>
<span class="CommentedCode">#?     $print curr:address:duplex-list, [ </span>
<span class="CommentedCode">#? ] #? 1</span>
    <span class="muControl">break-unless</span> curr:address:duplex-list
    off-screen?:boolean<span class="Special"> &lt;- </span>greater-or-equal row:number, screen-height:number
    <span class="muControl">break-if</span> off-screen?:boolean
    <span class="Delimiter">{</span>
      at-cursor?:boolean<span class="Special"> &lt;- </span>equal curr:address:duplex-list, cursor:address:duplex-list
      <span class="muControl">break-unless</span> at-cursor?:boolean
      cursor-row:number<span class="Special"> &lt;- </span>copy row:number
      cursor-column:number<span class="Special"> &lt;- </span>copy column:number
    <span class="Delimiter">}</span>
    c:character<span class="Special"> &lt;- </span>get curr:address:duplex-list/deref, value:offset
    <span class="Delimiter">{</span>
      <span class="Comment"># newline? move to left rather than 0</span>
      newline?:boolean<span class="Special"> &lt;- </span>equal c:character, <span class="Constant">10:literal/newline</span>
      <span class="muControl">break-unless</span> newline?:boolean
      row:number<span class="Special"> &lt;- </span>add row:number, <span class="Constant">1:literal</span>
      column:number<span class="Special"> &lt;- </span>copy left:number
      move-cursor screen:address, row:number, column:number
      curr:address:duplex-list<span class="Special"> &lt;- </span>next-duplex curr:address:duplex-list
      <span class="muControl">loop</span> <span class="Constant">+next-character:label</span>
    <span class="Delimiter">}</span>
    <span class="Delimiter">{</span>
      <span class="Comment"># at right? more than one letter left in the line? wrap</span>
      at-right?:boolean<span class="Special"> &lt;- </span>equal column:number, right:number
      <span class="muControl">break-unless</span> at-right?:boolean
      next-node:address:duplex-list<span class="Special"> &lt;- </span>next-duplex curr:address:duplex-list
      <span class="muControl">break-unless</span> next-node:address:duplex-list
      next:character<span class="Special"> &lt;- </span>get next-node:address:duplex-list/deref, value:offset
      next-character-is-newline?:boolean<span class="Special"> &lt;- </span>equal next:character, <span class="Constant">10:literal/newline</span>
      <span class="muControl">break-if</span> next-character-is-newline?:boolean
      <span class="Comment"># wrap</span>
      print-character screen:address, <span class="Constant">8617:literal/loop-back-to-left</span>, <span class="Constant">245:literal/grey</span>
      column:number<span class="Special"> &lt;- </span>copy left:number
      row:number<span class="Special"> &lt;- </span>add row:number, <span class="Constant">1:literal</span>
      move-cursor screen:address, row:number, column:number
      <span class="Comment"># don't increment curr</span>
      <span class="muControl">loop</span> <span class="Constant">+next-character:label</span>
    <span class="Delimiter">}</span>
    print-character screen:address, c:character
    curr:address:duplex-list<span class="Special"> &lt;- </span>next-duplex curr:address:duplex-list
    column:number<span class="Special"> &lt;- </span>add column:number, <span class="Constant">1:literal</span>
    <span class="muControl">loop</span>
  <span class="Delimiter">}</span>
  move-cursor screen:address, cursor-row:number, cursor-column:number
  <span class="muControl">reply</span> row:number, screen:address/same-as-ingredient:1
]

<span class="muScenario">scenario</span> editor-initially-prints-multiple-lines [
  assume-screen <span class="Constant">5:literal/width</span>, <span class="Constant">3:literal/height</span>
  run [
    s:address:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[abc</span>
<span class="Constant">def]</span>
    new-editor s:address:array:character, screen:address, <span class="Constant">0:literal/top</span>, <span class="Constant">0:literal/left</span>, <span class="Constant">5:literal/right</span>
  ]
  screen-should-contain [
   <span class="Constant"> .abc  .</span>
   <span class="Constant"> .def  .</span>
   <span class="Constant"> .     .</span>
  ]
]

<span class="muScenario">scenario</span> editor-initially-handles-offsets [
  assume-screen <span class="Constant">5:literal/width</span>, <span class="Constant">3:literal/height</span>
  run [
    s:address:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[abc]</span>
    new-editor s:address:array:character, screen:address, <span class="Constant">0:literal/top</span>, <span class="Constant">1:literal/left</span>, <span class="Constant">5:literal/right</span>
  ]
  screen-should-contain [
   <span class="Constant"> . abc .</span>
   <span class="Constant"> .     .</span>
   <span class="Constant"> .     .</span>
  ]
]

<span class="muScenario">scenario</span> editor-initially-prints-multiple-lines-at-offset [
  assume-screen <span class="Constant">5:literal/width</span>, <span class="Constant">3:literal/height</span>
  run [
    s:address:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[abc</span>
<span class="Constant">def]</span>
    new-editor s:address:array:character, screen:address, <span class="Constant">0:literal/top</span>, <span class="Constant">1:literal/left</span>, <span class="Constant">5:literal/right</span>
  ]
  screen-should-contain [
   <span class="Constant"> . abc .</span>
   <span class="Constant"> . def .</span>
   <span class="Constant"> .     .</span>
  ]
]

<span class="muScenario">scenario</span> editor-initially-wraps-long-lines [
  assume-screen <span class="Constant">5:literal/width</span>, <span class="Constant">3:literal/height</span>
  run [
    s:address:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[abc def]</span>
    new-editor s:address:array:character, screen:address, <span class="Constant">0:literal/top</span>, <span class="Constant">0:literal/left</span>, <span class="Constant">5:literal/right</span>
  ]
  screen-should-contain [
   <span class="Constant"> .abc ↩.</span>
   <span class="Constant"> .def  .</span>
   <span class="Constant"> .     .</span>
  ]
  screen-should-contain-in-color, <span class="Constant">245:literal/grey</span> [
   <span class="Constant"> .    ↩.</span>
   <span class="Constant"> .     .</span>
   <span class="Constant"> .     .</span>
  ]
]

<span class="SalientComment">## handling events from the keyboard and mouse</span>

<span class="muRecipe">recipe</span> event-loop [
  <span class="Constant">default-space</span>:address:array:location<span class="Special"> &lt;- </span>new location:type, <span class="Constant">30:literal</span>
  screen:address<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  console:address<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  editor:address:editor-data<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Delimiter">{</span>
<span class="Constant">    +next-event</span>
    e:event, console:address, found?:boolean, quit?:boolean<span class="Special"> &lt;- </span>read-event console:address
    <span class="muControl">loop-unless</span> found?:boolean
    <span class="muControl">break-if</span> quit?:boolean  <span class="Comment"># only in tests</span>
    trace <span class="Constant">[app]</span>, <span class="Constant">[next-event]</span>
    <span class="Delimiter">{</span>
      t:address:touch-event<span class="Special"> &lt;- </span>maybe-convert e:event, touch:variant
      <span class="muControl">break-unless</span> t:address:touch-event
      editor:address:editor-data<span class="Special"> &lt;- </span>move-cursor-in-editor editor:address:editor-data, t:address:touch-event
      <span class="muControl">loop</span> <span class="Constant">+next-event:label</span>
    <span class="Delimiter">}</span>
    c:address:character<span class="Special"> &lt;- </span>maybe-convert e:event, text:variant
    assert c:address:character, <span class="Constant">[event was of unknown type; neither keyboard nor mouse]</span>
    <span class="muControl">loop</span>
  <span class="Delimiter">}</span>
]

<span class="muRecipe">recipe</span> move-cursor-in-editor [
  <span class="Constant">default-space</span>:address:array:location<span class="Special"> &lt;- </span>new location:type, <span class="Constant">30:literal</span>
  editor:address:editor-data<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  t:address:touch-event<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  row:address:number<span class="Special"> &lt;- </span>get-address editor:address:editor-data/deref, cursor-row:offset
  row:address:number/deref<span class="Special"> &lt;- </span>get t:address:touch-event/deref, row:offset
  column:address:number<span class="Special"> &lt;- </span>get-address editor:address:editor-data/deref, cursor-column:offset
  column:address:number/deref<span class="Special"> &lt;- </span>get t:address:touch-event/deref, column:offset
  <span class="Comment"># todo: adjust 'cursor' pointer into editor data</span>
]

<span class="muScenario">scenario</span> editor-handles-empty-event-queue [
  assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span>
  assume-console <span class="Constant">[]</span>
  run [
    s:address:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[abc]</span>
    editor:address:editor-data<span class="Special"> &lt;- </span>new-editor s:address:array:character, screen:address, <span class="Constant">0:literal/top</span>, <span class="Constant">0:literal/left</span>, <span class="Constant">5:literal/right</span>
    event-loop screen:address, console:address, editor:address:editor-data
  ]
  screen-should-contain [
   <span class="Constant"> .abc       .</span>
   <span class="Constant"> .          .</span>
  ]
]

<span class="muScenario">scenario</span> editor-handles-mouse-clicks [
  assume-screen <span class="Constant">10:literal/width</span>, <span class="Constant">5:literal/height</span>
  assume-console [
    left-click 0, 1
  ]
  run [
    1:address:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[abc]</span>
    2:address:editor-data<span class="Special"> &lt;- </span>new-editor 1:address:array:character, screen:address, <span class="Constant">0:literal/top</span>, <span class="Constant">0:literal/left</span>, <span class="Constant">5:literal/right</span>
    event-loop screen:address, console:address, 2:address:editor-data
    3:number<span class="Special"> &lt;- </span>get 2:address:editor-data/deref, cursor-row:offset
    4:number<span class="Special"> &lt;- </span>get 2:address:editor-data/deref, cursor-column:offset
  ]
  screen-should-contain [
   <span class="Constant"> .abc       .</span>
   <span class="Constant"> .          .</span>
  ]
  memory-should-contain [
    3<span class="Special"> &lt;- </span>0  <span class="Comment"># cursor is at row 0..</span>
    4<span class="Special"> &lt;- </span>1  <span class="Comment"># ..and column 1</span>
  ]
]

<span class="SalientComment">## helpers for drawing editor borders</span>

<span class="muRecipe">recipe</span> draw-box [
  <span class="Constant">default-space</span>:address:array:location<span class="Special"> &lt;- </span>new location:type, <span class="Constant">30:literal</span>
  screen:address<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  top:number<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  left:number<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  bottom:number<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  right:number<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  color:number, color-found?:boolean<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Delimiter">{</span>
    <span class="Comment"># default color to white</span>
    <span class="muControl">break-if</span> color-found?:boolean
    color:number<span class="Special"> &lt;- </span>copy <span class="Constant">245:literal/grey</span>
  <span class="Delimiter">}</span>
  <span class="Comment"># top border</span>
  draw-horizontal screen:address, top:number, left:number, right:number, color:number
  draw-horizontal screen:address, bottom:number, left:number, right:number, color:number
  draw-vertical screen:address, left:number, top:number, bottom:number, color:number
  draw-vertical screen:address, right:number, top:number, bottom:number, color:number
  draw-top-left screen:address, top:number, left:number, color:number
  draw-top-right screen:address, top:number, right:number, color:number
  draw-bottom-left screen:address, bottom:number, left:number, color:number
  draw-bottom-right screen:address, bottom:number, right:number, color:number
  <span class="Comment"># position cursor inside box</span>
  move-cursor screen:address, top:number, left:number
  cursor-down screen:address
  cursor-right screen:address
]

<span class="muRecipe">recipe</span> draw-horizontal [
  <span class="Constant">default-space</span>:address:array:location<span class="Special"> &lt;- </span>new location:type, <span class="Constant">30:literal</span>
  screen:address<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  row:number<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  x:number<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  right:number<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  color:number, color-found?:boolean<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Delimiter">{</span>
    <span class="Comment"># default color to white</span>
    <span class="muControl">break-if</span> color-found?:boolean
    color:number<span class="Special"> &lt;- </span>copy <span class="Constant">245:literal/grey</span>
  <span class="Delimiter">}</span>
  move-cursor screen:address, row:number, x:number
  <span class="Delimiter">{</span>
    continue?:boolean<span class="Special"> &lt;- </span>lesser-than x:number, right:number
    <span class="muControl">break-unless</span> continue?:boolean
    print-character screen:address, <span class="Constant">9472:literal/horizontal</span>, color:number
    x:number<span class="Special"> &lt;- </span>add x:number, <span class="Constant">1:literal</span>
    <span class="muControl">loop</span>
  <span class="Delimiter">}</span>
]

<span class="muRecipe">recipe</span> draw-vertical [
  <span class="Constant">default-space</span>:address:array:location<span class="Special"> &lt;- </span>new location:type, <span class="Constant">30:literal</span>
  screen:address<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  col:number<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  x:number<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  bottom:number<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  color:number, color-found?:boolean<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Delimiter">{</span>
    <span class="Comment"># default color to white</span>
    <span class="muControl">break-if</span> color-found?:boolean
    color:number<span class="Special"> &lt;- </span>copy <span class="Constant">245:literal/grey</span>
  <span class="Delimiter">}</span>
  <span class="Delimiter">{</span>
    continue?:boolean<span class="Special"> &lt;- </span>lesser-than x:number, bottom:number
    <span class="muControl">break-unless</span> continue?:boolean
    move-cursor screen:address, x:number, col:number
    print-character screen:address, <span class="Constant">9474:literal/vertical</span>, color:number
    x:number<span class="Special"> &lt;- </span>add x:number, <span class="Constant">1:literal</span>
    <span class="muControl">loop</span>
  <span class="Delimiter">}</span>
]

<span class="muRecipe">recipe</span> draw-top-left [
  <span class="Constant">default-space</span>:address:array:location<span class="Special"> &lt;- </span>new location:type, <span class="Constant">30:literal</span>
  screen:address<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  top:number<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  left:number<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  color:number, color-found?:boolean<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Delimiter">{</span>
    <span class="Comment"># default color to white</span>
    <span class="muControl">break-if</span> color-found?:boolean
    color:number<span class="Special"> &lt;- </span>copy <span class="Constant">245:literal/grey</span>
  <span class="Delimiter">}</span>
  move-cursor screen:address, top:number, left:number
  print-character screen:address, <span class="Constant">9484:literal/down-right</span>, color:number
]

<span class="muRecipe">recipe</span> draw-top-right [
  <span class="Constant">default-space</span>:address:array:location<span class="Special"> &lt;- </span>new location:type, <span class="Constant">30:literal</span>
  screen:address<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  top:number<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  right:number<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  color:number, color-found?:boolean<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Delimiter">{</span>
    <span class="Comment"># default color to white</span>
    <span class="muControl">break-if</span> color-found?:boolean
    color:number<span class="Special"> &lt;- </span>copy <span class="Constant">245:literal/grey</span>
  <span class="Delimiter">}</span>
  move-cursor screen:address, top:number, right:number
  print-character screen:address, <span class="Constant">9488:literal/down-left</span>, color:number
]

<span class="muRecipe">recipe</span> draw-bottom-left [
  <span class="Constant">default-space</span>:address:array:location<span class="Special"> &lt;- </span>new location:type, <span class="Constant">30:literal</span>
  screen:address<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  bottom:number<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  left:number<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  color:number, color-found?:boolean<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Delimiter">{</span>
    <span class="Comment"># default color to white</span>
    <span class="muControl">break-if</span> color-found?:boolean
    color:number<span class="Special"> &lt;- </span>copy <span class="Constant">245:literal/grey</span>
  <span class="Delimiter">}</span>
  move-cursor screen:address, bottom:number, left:number
  print-character screen:address, <span class="Constant">9492:literal/up-right</span>, color:number
]

<span class="muRecipe">recipe</span> draw-bottom-right [
  <span class="Constant">default-space</span>:address:array:location<span class="Special"> &lt;- </span>new location:type, <span class="Constant">30:literal</span>
  screen:address<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  bottom:number<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  right:number<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  color:number, color-found?:boolean<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Delimiter">{</span>
    <span class="Comment"># default color to white</span>
    <span class="muControl">break-if</span> color-found?:boolean
    color:number<span class="Special"> &lt;- </span>copy <span class="Constant">245:literal/grey</span>
  <span class="Delimiter">}</span>
  move-cursor screen:address, bottom:number, right:number
  print-character screen:address, <span class="Constant">9496:literal/up-left</span>, color:number
]
</pre>
</body>
</html>
<!-- vim: set foldmethod=manual : -->