about summary refs log tree commit diff stats
path: root/edit/007-sandbox-delete.mu
blob: def5c0c5e728f28587849f6eda277317659479e1 (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
## deleting sandboxes

scenario deleting-sandboxes [
  trace-until 100/app  # trace too long
  assume-screen 100/width, 15/height
  1:address:array:character <- new []
  2:address:array:character <- new []
  3:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character, 2:address:array:character
  # run a few commands
  assume-console [
    left-click 1, 80
    type [divide-with-remainder 11, 3]
    press F4
    type [add 2, 2]
    press F4
  ]
  event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data
  screen-should-contain [
    .                                                                                 run (F4)           .
    .                                                                                                   .
    .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
    .                                                  0   edit          copy            delete         .
    .                                                  add 2, 2                                         .
    .                                                  4                                                .
    .                                                  ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
    .                                                  1   edit          copy            delete         .
    .                                                  divide-with-remainder 11, 3                      .
    .                                                  3                                                .
    .                                                  2                                                .
    .                                                  ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
    .                                                                                                   .
  ]
  # delete second sandbox by clicking on left edge of 'delete' button
  assume-console [
    left-click 7, 85
  ]
  run [
    event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data
  ]
  screen-should-contain [
    .                                                                                 run (F4)           .
    .                                                                                                   .
    .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
    .                                                  0   edit          copy            delete         .
    .                                                  add 2, 2                                         .
    .                                                  4                                                .
    .                                                  ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
    .                                                                                                   .
    .                                                                                                   .
  ]
  # delete first sandbox by clicking at right edge of 'delete' button
  assume-console [
    left-click 3, 99
  ]
  run [
    event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data
  ]
  screen-should-contain [
    .                                                                                 run (F4)           .
    .                                                                                                   .
    .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
    .                                                                                                   .
    .                                                                                                   .
  ]
]

after <global-touch> [
  # support 'delete' button
  {
    delete?:boolean <- should-attempt-delete? click-row, click-column, env
    break-unless delete?
    delete?, env <- try-delete-sandbox click-row, env
    break-unless delete?
    hide-screen screen
    screen <- render-sandbox-side screen, env, render
    screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env
    show-screen screen
    loop +next-event:label
  }
]

# some preconditions for attempting to delete a sandbox
def should-attempt-delete? click-row:number, click-column:number, env:address:programming-environment-data -> result:boolean [
  local-scope
  load-ingredients
  # are we below the sandbox editor?
  click-sandbox-area?:boolean <- click-on-sandbox-area? click-row, click-column, env
  reply-unless click-sandbox-area?, 0/false
  # narrower, is the click in the columns spanning the 'copy' button?
  first-sandbox:address:editor-data <- get *env, current-sandbox:offset
  assert first-sandbox, [!!]
  sandbox-left-margin:number <- get *first-sandbox, left:offset
  sandbox-right-margin:number <- get *first-sandbox, right:offset
  _, _, _, _, delete-button-left:number <- sandbox-menu-columns sandbox-left-margin, sandbox-right-margin
  result <- within-range? click-column, delete-button-left, sandbox-right-margin
]

def try-delete-sandbox click-row:number, env:address:programming-environment-data -> clicked-on-delete-button?:boolean, env:address:programming-environment-data [
  local-scope
  load-ingredients
  # identify the sandbox to delete, if the click was actually on the 'delete' button
  sandbox:address:sandbox-data <- find-sandbox env, click-row
  return-unless sandbox, 0/false
  clicked-on-delete-button? <- copy 1/true
  env <- delete-sandbox env, sandbox
]

def delete-sandbox env:address:programming-environment-data, sandbox:address:sandbox-data -> env:address:programming-environment-data [
  local-scope
  load-ingredients
  curr-sandbox:address:sandbox-data <- get *env, sandbox:offset
  first-sandbox?:boolean <- equal curr-sandbox, sandbox
  {
    # first sandbox? pop
    break-unless first-sandbox?
    next-sandbox:address:sandbox-data <- get *curr-sandbox, next-sandbox:offset
    *env <- put *env, sandbox:offset, next-sandbox
  }
  {
    # not first sandbox?
    break-if first-sandbox?
    prev-sandbox:address:sandbox-data <- copy curr-sandbox
    curr-sandbox <- get *curr-sandbox, next-sandbox:offset
    {
      assert curr-sandbox, [sandbox not found! something is wrong.]
      found?:boolean <- equal curr-sandbox, sandbox
      break-if found?
      prev-sandbox <- copy curr-sandbox
      curr-sandbox <- get *curr-sandbox, next-sandbox:offset
      loop
    }
    # snip sandbox out of its list
    next-sandbox:address:sandbox-data <- get *curr-sandbox, next-sandbox:offset
    *prev-sandbox <- put *prev-sandbox, next-sandbox:offset, next-sandbox
  }
  # update sandbox count
  sandbox-count:number <- get *env, number-of-sandboxes:offset
  sandbox-count <- subtract sandbox-count, 1
  *env <- put *env, number-of-sandboxes:offset, sandbox-count
  # reset scroll if deleted sandbox was last
  {
    break-if next-sandbox
    render-from:number <- get *env, render-from:offset
    reset-scroll?:boolean <- equal render-from, sandbox-count
    break-unless reset-scroll?
    *env <- put *env, render-from:offset, -1
  }
]

scenario deleting-sandbox-after-scroll [
  trace-until 100/app  # trace too long
  assume-screen 100/width, 10/height
  # initialize environment
  1:address:array:character <- new []
  2:address:array:character <- new []
  3:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character, 2:address:array:character
  render-all screen, 3:address:programming-environment-data, render
  # create 2 sandboxes and scroll to second
  assume-console [
    press ctrl-n
    type [add 2, 2]
    press F4
    type [add 1, 1]
    press F4
    press page-down
  ]
  event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data
  screen-should-contain [
    .                                                                                 run (F4)           .
    .                                                  ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
    .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊0   edit          copy            delete         .
    .                                                  add 1, 1                                         .
    .                                                  2                                                .
    .                                                  ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
    .                                                  1   edit          copy            delete         .
  ]
  # delete the second sandbox
  assume-console [
    left-click 6, 99
  ]
  run [
    event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data
  ]
  # second sandbox shows in editor; scroll resets to display first sandbox
  screen-should-contain [
    .                                                                                 run (F4)           .
    .                                                  ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
    .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊0   edit          copy            delete         .
    .                                                  add 1, 1                                         .
    .                                                  2                                                .
    .                                                  ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
    .                                                                                                   .
  ]
]

scenario deleting-top-sandbox-after-scroll [
  trace-until 100/app  # trace too long
  assume-screen 100/width, 10/height
  # initialize environment
  1:address:array:character <- new []
  2:address:array:character <- new []
  3:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character, 2:address:array:character
  render-all screen, 3:address:programming-environment-data, render
  # create 2 sandboxes and scroll to second
  assume-console [
    press ctrl-n
    type [add 2, 2]
    press F4
    type [add 1, 1]
    press F4
    press page-down
  ]
  event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data
  screen-should-contain [
    .                                                                                 run (F4)           .
    .                                                  ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
    .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊0   edit          copy            delete         .
    .                                                  add 1, 1                                         .
    .                                                  2                                                .
    .                                                  ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
    .                                                  1   edit          copy            delete         .
  ]
  # delete the second sandbox
  assume-console [
    left-click 2, 99
  ]
  run [
    event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data
  ]
  # second sandbox shows in editor; scroll resets to display first sandbox
  screen-should-contain [
    .                                                                                 run (F4)           .
    .                                                  ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
    .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊0   edit          copy            delete         .
    .                                                  add 2, 2                                         .
    .                                                  4                                                .
    .                                                  ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
    .                                                                                                   .
  ]
]

scenario deleting-final-sandbox-after-scroll [
  trace-until 100/app  # trace too long
  assume-screen 100/width, 10/height
  # initialize environment
  1:address:array:character <- new []
  2:address:array:character <- new []
  3:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character, 2:address:array:character
  render-all screen, 3:address:programming-environment-data, render
  # create 2 sandboxes and scroll to second
  assume-console [
    press ctrl-n
    type [add 2, 2]
    press F4
    type [add 1, 1]
    press F4
    press page-down
    press page-down
  ]
  event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data
  screen-should-contain [
    .                                                                                 run (F4)           .
    .                                                  ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
    .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊1   edit          copy            delete         .
    .                                                  add 2, 2                                         .
    .                                                  4                                                .
    .                                                  ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
    .                                                                                                   .
  ]
  # delete the second sandbox
  assume-console [
    left-click 2, 99
  ]
  run [
    event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data
  ]
  # implicitly scroll up to first sandbox
  screen-should-contain [
    .                                                                                 run (F4)           .
    .                                                                                                   .
    .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
    .                                                  0   edit          copy            delete         .
    .                                                  add 1, 1                                         .
    .                                                  2                                                .
    .                                                  ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
    .                                                                                                   .
  ]
]

scenario deleting-updates-sandbox-count [
  trace-until 100/app  # trace too long
  assume-screen 100/width, 10/height
  # initialize environment
  1:address:array:character <- new []
  2:address:array:character <- new []
  3:address:programming-environment-data <- new-programming-environment screen:address:screen, 1:address:array:character, 2:address:array:character
  render-all screen, 3:address:programming-environment-data, render
  # create 2 sandboxes
  assume-console [
    press ctrl-n
    type [add 2, 2]
    press F4
    type [add 1, 1]
    press F4
  ]
  event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data
  screen-should-contain [
    .                                                                                 run (F4)           .
    .                                                                                                   .
    .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
    .                                                  0   edit          copy            delete         .
    .                                                  add 1, 1                                         .
    .                                                  2                                                .
    .                                                  ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
    .                                                  1   edit          copy            delete         .
    .                                                  add 2, 2                                         .
    .                                                  4                                                .
  ]
  # delete the second sandbox, then try to scroll down twice
  assume-console [
    left-click 3, 99
    press page-down
    press page-down
  ]
  run [
    event-loop screen:address:screen, console:address:console, 3:address:programming-environment-data
  ]
  # shouldn't go past last sandbox
  screen-should-contain [
    .                                                                                 run (F4)           .
    .                                                  ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
    .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊0   edit          copy            delete         .
    .                                                  add 2, 2                                         .
    .                                                  4                                                .
    .                                                  ┊━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━.
    .                                                                                                   .
  ]
]
class="p">>get *fake-screen, <span class="Constant">data:offset</span> <span class="Constant">11</span>:array:screen-cell/<span class="Special">raw &lt;- </span>copy *cell ] memory-should-contain [ <span class="Constant">10</span><span class="Special"> &lt;- </span><span class="Constant">0</span> <span class="Comment"># cursor column</span> <span class="Constant">11</span><span class="Special"> &lt;- </span><span class="Constant">6</span> <span class="Comment"># width*height</span> <span class="Constant">12</span><span class="Special"> &lt;- </span><span class="Constant">32</span> <span class="Comment"># space, not 'a'</span> <span class="Constant">13</span><span class="Special"> &lt;- </span><span class="Constant">7</span> <span class="Comment"># white</span> <span class="Comment"># rest of screen is empty</span> <span class="Constant">14</span><span class="Special"> &lt;- </span><span class="Constant">0</span> ] ] <span class="muScenario">scenario</span> print-extra-backspace-character [ run [ <span class="Constant">local-scope</span> fake-screen:address:screen<span class="Special"> &lt;- </span>new-fake-screen <span class="Constant">3/width</span>, <span class="Constant">2/height</span> a:character<span class="Special"> &lt;- </span>copy <span class="Constant">97/a</span> fake-screen<span class="Special"> &lt;- </span>print fake-screen, a backspace:character<span class="Special"> &lt;- </span>copy <span class="Constant">8/backspace</span> fake-screen<span class="Special"> &lt;- </span>print fake-screen, backspace fake-screen<span class="Special"> &lt;- </span>print fake-screen, backspace <span class="Constant">1</span>:number/<span class="Special">raw &lt;- </span>get *fake-screen, <span class="Constant">cursor-column:offset</span> cell:address:array:screen-cell<span class="Special"> &lt;- </span>get *fake-screen, <span class="Constant">data:offset</span> <span class="Constant">3</span>:array:screen-cell/<span class="Special">raw &lt;- </span>copy *cell ] memory-should-contain [ <span class="Constant">1</span><span class="Special"> &lt;- </span><span class="Constant">0</span> <span class="Comment"># cursor column</span> <span class="Constant">3</span><span class="Special"> &lt;- </span><span class="Constant">6</span> <span class="Comment"># width*height</span> <span class="Constant">4</span><span class="Special"> &lt;- </span><span class="Constant">32</span> <span class="Comment"># space, not 'a'</span> <span class="Constant">5</span><span class="Special"> &lt;- </span><span class="Constant">7</span> <span class="Comment"># white</span> <span class="Comment"># rest of screen is empty</span> <span class="Constant">6</span><span class="Special"> &lt;- </span><span class="Constant">0</span> ] ] <span class="muScenario">scenario</span> print-character-at-right-margin [ run [ <span class="Constant">local-scope</span> fake-screen:address:screen<span class="Special"> &lt;- </span>new-fake-screen <span class="Constant">2/width</span>, <span class="Constant">2/height</span> a:character<span class="Special"> &lt;- </span>copy <span class="Constant">97/a</span> fake-screen<span class="Special"> &lt;- </span>print fake-screen, a b:character<span class="Special"> &lt;- </span>copy <span class="Constant">98/b</span> fake-screen<span class="Special"> &lt;- </span>print fake-screen, b c:character<span class="Special"> &lt;- </span>copy <span class="Constant">99/c</span> fake-screen<span class="Special"> &lt;- </span>print fake-screen, c <span class="Constant">10</span>:number/<span class="Special">raw &lt;- </span>get *fake-screen, <span class="Constant">cursor-column:offset</span> cell:address:array:screen-cell<span class="Special"> &lt;- </span>get *fake-screen, <span class="Constant">data:offset</span> <span class="Constant">11</span>:array:screen-cell/<span class="Special">raw &lt;- </span>copy *cell ] memory-should-contain [ <span class="Constant">10</span><span class="Special"> &lt;- </span><span class="Constant">1</span> <span class="Comment"># cursor column</span> <span class="Constant">11</span><span class="Special"> &lt;- </span><span class="Constant">4</span> <span class="Comment"># width*height</span> <span class="Constant">12</span><span class="Special"> &lt;- </span><span class="Constant">97</span> <span class="Comment"># 'a'</span> <span class="Constant">13</span><span class="Special"> &lt;- </span><span class="Constant">7</span> <span class="Comment"># white</span> <span class="Constant">14</span><span class="Special"> &lt;- </span><span class="Constant">99</span> <span class="Comment"># 'c' over 'b'</span> <span class="Constant">15</span><span class="Special"> &lt;- </span><span class="Constant">7</span> <span class="Comment"># white</span> <span class="Comment"># rest of screen is empty</span> <span class="Constant">16</span><span class="Special"> &lt;- </span><span class="Constant">0</span> ] ] <span class="muScenario">scenario</span> print-newline-character [ run [ <span class="Constant">local-scope</span> fake-screen:address:screen<span class="Special"> &lt;- </span>new-fake-screen <span class="Constant">3/width</span>, <span class="Constant">2/height</span> newline:character<span class="Special"> &lt;- </span>copy <span class="Constant">10/newline</span> a:character<span class="Special"> &lt;- </span>copy <span class="Constant">97/a</span> fake-screen<span class="Special"> &lt;- </span>print fake-screen, a fake-screen<span class="Special"> &lt;- </span>print fake-screen, newline <span class="Constant">10</span>:number/<span class="Special">raw &lt;- </span>get *fake-screen, <span class="Constant">cursor-row:offset</span> <span class="Constant">11</span>:number/<span class="Special">raw &lt;- </span>get *fake-screen, <span class="Constant">cursor-column:offset</span> cell:address:array:screen-cell<span class="Special"> &lt;- </span>get *fake-screen, <span class="Constant">data:offset</span> <span class="Constant">12</span>:array:screen-cell/<span class="Special">raw &lt;- </span>copy *cell ] memory-should-contain [ <span class="Constant">10</span><span class="Special"> &lt;- </span><span class="Constant">1</span> <span class="Comment"># cursor row</span> <span class="Constant">11</span><span class="Special"> &lt;- </span><span class="Constant">0</span> <span class="Comment"># cursor column</span> <span class="Constant">12</span><span class="Special"> &lt;- </span><span class="Constant">6</span> <span class="Comment"># width*height</span> <span class="Constant">13</span><span class="Special"> &lt;- </span><span class="Constant">97</span> <span class="Comment"># 'a'</span> <span class="Constant">14</span><span class="Special"> &lt;- </span><span class="Constant">7</span> <span class="Comment"># white</span> <span class="Comment"># rest of screen is empty</span> <span class="Constant">15</span><span class="Special"> &lt;- </span><span class="Constant">0</span> ] ] <span class="muScenario">scenario</span> print-newline-at-bottom-line [ run [ <span class="Constant">local-scope</span> fake-screen:address:screen<span class="Special"> &lt;- </span>new-fake-screen <span class="Constant">3/width</span>, <span class="Constant">2/height</span> newline:character<span class="Special"> &lt;- </span>copy <span class="Constant">10/newline</span> fake-screen<span class="Special"> &lt;- </span>print fake-screen, newline fake-screen<span class="Special"> &lt;- </span>print fake-screen, newline fake-screen<span class="Special"> &lt;- </span>print fake-screen, newline <span class="Constant">10</span>:number/<span class="Special">raw &lt;- </span>get *fake-screen, <span class="Constant">cursor-row:offset</span> <span class="Constant">11</span>:number/<span class="Special">raw &lt;- </span>get *fake-screen, <span class="Constant">cursor-column:offset</span> ] memory-should-contain [ <span class="Constant">10</span><span class="Special"> &lt;- </span><span class="Constant">1</span> <span class="Comment"># cursor row</span> <span class="Constant">11</span><span class="Special"> &lt;- </span><span class="Constant">0</span> <span class="Comment"># cursor column</span> ] ] <span class="muScenario">scenario</span> print-character-at-bottom-right [ run [ <span class="Constant">local-scope</span> fake-screen:address:screen<span class="Special"> &lt;- </span>new-fake-screen <span class="Constant">2/width</span>, <span class="Constant">2/height</span> newline:character<span class="Special"> &lt;- </span>copy <span class="Constant">10/newline</span> fake-screen<span class="Special"> &lt;- </span>print fake-screen, newline a:character<span class="Special"> &lt;- </span>copy <span class="Constant">97/a</span> fake-screen<span class="Special"> &lt;- </span>print fake-screen, a b:character<span class="Special"> &lt;- </span>copy <span class="Constant">98/b</span> fake-screen<span class="Special"> &lt;- </span>print fake-screen, b c:character<span class="Special"> &lt;- </span>copy <span class="Constant">99/c</span> fake-screen<span class="Special"> &lt;- </span>print fake-screen, c fake-screen<span class="Special"> &lt;- </span>print fake-screen, newline d:character<span class="Special"> &lt;- </span>copy <span class="Constant">100/d</span> fake-screen<span class="Special"> &lt;- </span>print fake-screen, d <span class="Constant">10</span>:number/<span class="Special">raw &lt;- </span>get *fake-screen, <span class="Constant">cursor-row:offset</span> <span class="Constant">11</span>:number/<span class="Special">raw &lt;- </span>get *fake-screen, <span class="Constant">cursor-column:offset</span> cell:address:array:screen-cell<span class="Special"> &lt;- </span>get *fake-screen, <span class="Constant">data:offset</span> <span class="Constant">20</span>:array:screen-cell/<span class="Special">raw &lt;- </span>copy *cell ] memory-should-contain [ <span class="Constant">10</span><span class="Special"> &lt;- </span><span class="Constant">1</span> <span class="Comment"># cursor row</span> <span class="Constant">11</span><span class="Special"> &lt;- </span><span class="Constant">1</span> <span class="Comment"># cursor column</span> <span class="Constant">20</span><span class="Special"> &lt;- </span><span class="Constant">4</span> <span class="Comment"># width*height</span> <span class="Constant">21</span><span class="Special"> &lt;- </span><span class="Constant">0</span> <span class="Comment"># unused</span> <span class="Constant">22</span><span class="Special"> &lt;- </span><span class="Constant">7</span> <span class="Comment"># white</span> <span class="Constant">23</span><span class="Special"> &lt;- </span><span class="Constant">0</span> <span class="Comment"># unused</span> <span class="Constant">24</span><span class="Special"> &lt;- </span><span class="Constant">7</span> <span class="Comment"># white</span> <span class="Constant">25</span><span class="Special"> &lt;- </span><span class="Constant">97</span> <span class="Comment"># 'a'</span> <span class="Constant">26</span><span class="Special"> &lt;- </span><span class="Constant">7</span> <span class="Comment"># white</span> <span class="Constant">27</span><span class="Special"> &lt;- </span><span class="Constant">100</span> <span class="Comment"># 'd' over 'b' and 'c' and newline</span> <span class="Constant">28</span><span class="Special"> &lt;- </span><span class="Constant">7</span> <span class="Comment"># white</span> <span class="Comment"># rest of screen is empty</span> <span class="Constant">29</span><span class="Special"> &lt;- </span><span class="Constant">0</span> ] ] <span class="muRecipe">def</span> clear-line screen:address:screen<span class="muRecipe"> -&gt; </span>screen:address:screen [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> space:character<span class="Special"> &lt;- </span>copy <span class="Constant">0/nul</span> <span class="Comment"># if x exists, clear line in fake screen</span> <span class="Delimiter">{</span> <span class="muControl">break-unless</span> screen width:number<span class="Special"> &lt;- </span>get *screen, <span class="Constant">num-columns:offset</span> column:number<span class="Special"> &lt;- </span>get *screen, <span class="Constant">cursor-column:offset</span> original-column:number<span class="Special"> &lt;- </span>copy column <span class="Comment"># space over the entire line</span> <span class="Delimiter">{</span> right:number<span class="Special"> &lt;- </span>subtract width, <span class="Constant">1</span> done?:boolean<span class="Special"> &lt;- </span>greater-or-equal column, right <span class="muControl">break-if</span> done? print screen, space column<span class="Special"> &lt;- </span>add column, <span class="Constant">1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> <span class="Comment"># now back to where the cursor was</span> *screen<span class="Special"> &lt;- </span>put *screen, <span class="Constant">cursor-column:offset</span>, original-column <span class="muControl">return</span> <span class="Delimiter">}</span> <span class="Comment"># otherwise, real screen</span> clear-line-on-display ] <span class="muRecipe">def</span> clear-line-until screen:address:screen, right:number/inclusive<span class="muRecipe"> -&gt; </span>screen:address:screen [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> _, column:number<span class="Special"> &lt;- </span>cursor-position screen space:character<span class="Special"> &lt;- </span>copy <span class="Constant">32/space</span> bg-color:number, bg-color-found?:boolean<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span> <span class="Delimiter">{</span> <span class="Comment"># default bg-color to black</span> <span class="muControl">break-if</span> bg-color-found? bg-color<span class="Special"> &lt;- </span>copy <span class="Constant">0/black</span> <span class="Delimiter">}</span> <span class="Delimiter">{</span> done?:boolean<span class="Special"> &lt;- </span>greater-than column, right <span class="muControl">break-if</span> done? screen<span class="Special"> &lt;- </span>print screen, space, <span class="Constant">7/white</span>, bg-color <span class="Comment"># foreground color is mostly unused except if the cursor shows up at this cell</span> column<span class="Special"> &lt;- </span>add column, <span class="Constant">1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> ] <span class="muRecipe">def</span> cursor-position screen:address:screen<span class="muRecipe"> -&gt; </span>row:number, column:number [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="Comment"># if x exists, lookup cursor in fake screen</span> <span class="Delimiter">{</span> <span class="muControl">break-unless</span> screen row:number<span class="Special"> &lt;- </span>get *screen, <span class="Constant">cursor-row:offset</span> column:number<span class="Special"> &lt;- </span>get *screen, <span class="Constant">cursor-column:offset</span> <span class="muControl">return</span> <span class="Delimiter">}</span> row, column<span class="Special"> &lt;- </span>cursor-position-on-display ] <span class="muRecipe">def</span> move-cursor screen:address:screen, new-row:number, new-column:number<span class="muRecipe"> -&gt; </span>screen:address:screen [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="Comment"># if x exists, move cursor in fake screen</span> <span class="Delimiter">{</span> <span class="muControl">break-unless</span> screen *screen<span class="Special"> &lt;- </span>put *screen, <span class="Constant">cursor-row:offset</span>, new-row *screen<span class="Special"> &lt;- </span>put *screen, <span class="Constant">cursor-column:offset</span>, new-column <span class="muControl">return</span> <span class="Delimiter">}</span> <span class="Comment"># otherwise, real screen</span> move-cursor-on-display new-row, new-column ] <span class="muScenario">scenario</span> clear-line-erases-printed-characters [ run [ <span class="Constant">local-scope</span> fake-screen:address:screen<span class="Special"> &lt;- </span>new-fake-screen <span class="Constant">3/width</span>, <span class="Constant">2/height</span> <span class="Comment"># print a character</span> a:character<span class="Special"> &lt;- </span>copy <span class="Constant">97/a</span> fake-screen<span class="Special"> &lt;- </span>print fake-screen, a <span class="Comment"># move cursor to start of line</span> fake-screen<span class="Special"> &lt;- </span>move-cursor fake-screen, <span class="Constant">0/row</span>, <span class="Constant">0/column</span> <span class="Comment"># clear line</span> fake-screen<span class="Special"> &lt;- </span>clear-line fake-screen cell:address:array:screen-cell<span class="Special"> &lt;- </span>get *fake-screen, <span class="Constant">data:offset</span> <span class="Constant">10</span>:array:screen-cell/<span class="Special">raw &lt;- </span>copy *cell ] <span class="Comment"># screen should be blank</span> memory-should-contain [ <span class="Constant">10</span><span class="Special"> &lt;- </span><span class="Constant">6</span> <span class="Comment"># width*height</span> <span class="Constant">11</span><span class="Special"> &lt;- </span><span class="Constant">0</span> <span class="Constant">12</span><span class="Special"> &lt;- </span><span class="Constant">7</span> <span class="Constant">13</span><span class="Special"> &lt;- </span><span class="Constant">0</span> <span class="Constant">14</span><span class="Special"> &lt;- </span><span class="Constant">7</span> <span class="Constant">15</span><span class="Special"> &lt;- </span><span class="Constant">0</span> <span class="Constant">16</span><span class="Special"> &lt;- </span><span class="Constant">7</span> <span class="Constant">17</span><span class="Special"> &lt;- </span><span class="Constant">0</span> <span class="Constant">18</span><span class="Special"> &lt;- </span><span class="Constant">7</span> <span class="Constant">19</span><span class="Special"> &lt;- </span><span class="Constant">0</span> <span class="Constant">20</span><span class="Special"> &lt;- </span><span class="Constant">7</span> <span class="Constant">21</span><span class="Special"> &lt;- </span><span class="Constant">0</span> <span class="Constant">22</span><span class="Special"> &lt;- </span><span class="Constant">7</span> ] ] <span class="muRecipe">def</span> cursor-down screen:address:screen<span class="muRecipe"> -&gt; </span>screen:address:screen [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="Comment"># if x exists, move cursor in fake screen</span> <span class="Delimiter">{</span> <span class="muControl">break-unless</span> screen <span class="Delimiter">{</span> <span class="Comment"># increment row unless it's already all the way down</span> height:number<span class="Special"> &lt;- </span>get *screen, <span class="Constant">num-rows:offset</span> row:number<span class="Special"> &lt;- </span>get *screen, <span class="Constant">cursor-row:offset</span> max:number<span class="Special"> &lt;- </span>subtract height, <span class="Constant">1</span> at-bottom?:boolean<span class="Special"> &lt;- </span>greater-or-equal row, max <span class="muControl">break-if</span> at-bottom? row<span class="Special"> &lt;- </span>add row, <span class="Constant">1</span> *screen<span class="Special"> &lt;- </span>put *screen, <span class="Constant">cursor-row:offset</span>, row <span class="Delimiter">}</span> <span class="muControl">return</span> <span class="Delimiter">}</span> <span class="Comment"># otherwise, real screen</span> move-cursor-down-on-display ] <span class="muRecipe">def</span> cursor-up screen:address:screen<span class="muRecipe"> -&gt; </span>screen:address:screen [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="Comment"># if x exists, move cursor in fake screen</span> <span class="Delimiter">{</span> <span class="muControl">break-unless</span> screen <span class="Delimiter">{</span> <span class="Comment"># decrement row unless it's already all the way up</span> row:number<span class="Special"> &lt;- </span>get *screen, <span class="Constant">cursor-row:offset</span> at-top?:boolean<span class="Special"> &lt;- </span>lesser-or-equal row, <span class="Constant">0</span> <span class="muControl">break-if</span> at-top? row<span class="Special"> &lt;- </span>subtract row, <span class="Constant">1</span> *screen<span class="Special"> &lt;- </span>put *screen, <span class="Constant">cursor-row:offset</span>, row <span class="Delimiter">}</span> <span class="muControl">return</span> <span class="Delimiter">}</span> <span class="Comment"># otherwise, real screen</span> move-cursor-up-on-display ] <span class="muRecipe">def</span> cursor-right screen:address:screen<span class="muRecipe"> -&gt; </span>screen:address:screen [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="Comment"># if x exists, move cursor in fake screen</span> <span class="Delimiter">{</span> <span class="muControl">break-unless</span> screen <span class="Delimiter">{</span> <span class="Comment"># increment column unless it's already all the way to the right</span> width:number<span class="Special"> &lt;- </span>get *screen, <span class="Constant">num-columns:offset</span> column:number<span class="Special"> &lt;- </span>get *screen, <span class="Constant">cursor-column:offset</span> max:number<span class="Special"> &lt;- </span>subtract width, <span class="Constant">1</span> at-bottom?:boolean<span class="Special"> &lt;- </span>greater-or-equal column, max <span class="muControl">break-if</span> at-bottom? column<span class="Special"> &lt;- </span>add column, <span class="Constant">1</span> *screen<span class="Special"> &lt;- </span>put *screen, <span class="Constant">cursor-column:offset</span>, column <span class="Delimiter">}</span> <span class="muControl">return</span> <span class="Delimiter">}</span> <span class="Comment"># otherwise, real screen</span> move-cursor-right-on-display ] <span class="muRecipe">def</span> cursor-left screen:address:screen<span class="muRecipe"> -&gt; </span>screen:address:screen [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="Comment"># if x exists, move cursor in fake screen</span> <span class="Delimiter">{</span> <span class="muControl">break-unless</span> screen <span class="Delimiter">{</span> <span class="Comment"># decrement column unless it's already all the way to the left</span> column:number<span class="Special"> &lt;- </span>get *screen, <span class="Constant">cursor-column:offset</span> at-top?:boolean<span class="Special"> &lt;- </span>lesser-or-equal column, <span class="Constant">0</span> <span class="muControl">break-if</span> at-top? column<span class="Special"> &lt;- </span>subtract column, <span class="Constant">1</span> *screen<span class="Special"> &lt;- </span>put *screen, <span class="Constant">cursor-column:offset</span>, column <span class="Delimiter">}</span> <span class="muControl">return</span> <span class="Delimiter">}</span> <span class="Comment"># otherwise, real screen</span> move-cursor-left-on-display ] <span class="muRecipe">def</span> cursor-to-start-of-line screen:address:screen<span class="muRecipe"> -&gt; </span>screen:address:screen [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> row:number<span class="Special"> &lt;- </span>cursor-position screen column:number<span class="Special"> &lt;- </span>copy <span class="Constant">0</span> screen<span class="Special"> &lt;- </span>move-cursor screen, row, column ] <span class="muRecipe">def</span> cursor-to-next-line screen:address:screen<span class="muRecipe"> -&gt; </span>screen:address:screen [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> screen<span class="Special"> &lt;- </span>cursor-down screen screen<span class="Special"> &lt;- </span>cursor-to-start-of-line screen ] <span class="muRecipe">def</span> move-cursor-to-column screen:address:screen, column:number<span class="muRecipe"> -&gt; </span>screen:address:screen [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> row:number, _<span class="Special"> &lt;- </span>cursor-position screen move-cursor screen, row, column ] <span class="muRecipe">def</span> screen-width screen:address:screen<span class="muRecipe"> -&gt; </span>width:number [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="Comment"># if x exists, move cursor in fake screen</span> <span class="Delimiter">{</span> <span class="muControl">break-unless</span> screen width<span class="Special"> &lt;- </span>get *screen, <span class="Constant">num-columns:offset</span> <span class="muControl">return</span> <span class="Delimiter">}</span> <span class="Comment"># otherwise, real screen</span> width<span class="Special"> &lt;- </span>display-width ] <span class="muRecipe">def</span> screen-height screen:address:screen<span class="muRecipe"> -&gt; </span>height:number [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="Comment"># if x exists, move cursor in fake screen</span> <span class="Delimiter">{</span> <span class="muControl">break-unless</span> screen height<span class="Special"> &lt;- </span>get *screen, <span class="Constant">num-rows:offset</span> <span class="muControl">return</span> <span class="Delimiter">}</span> <span class="Comment"># otherwise, real screen</span> height<span class="Special"> &lt;- </span>display-height ] <span class="muRecipe">def</span> hide-cursor screen:address:screen<span class="muRecipe"> -&gt; </span>screen:address:screen [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="Comment"># if x exists (not real display), do nothing</span> <span class="Delimiter">{</span> <span class="muControl">break-unless</span> screen <span class="muControl">return</span> <span class="Delimiter">}</span> <span class="Comment"># otherwise, real screen</span> hide-cursor-on-display ] <span class="muRecipe">def</span> show-cursor screen:address:screen<span class="muRecipe"> -&gt; </span>screen:address:screen [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="Comment"># if x exists (not real display), do nothing</span> <span class="Delimiter">{</span> <span class="muControl">break-unless</span> screen <span class="muControl">return</span> <span class="Delimiter">}</span> <span class="Comment"># otherwise, real screen</span> show-cursor-on-display ] <span class="muRecipe">def</span> hide-screen screen:address:screen<span class="muRecipe"> -&gt; </span>screen:address:screen [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="Comment"># if x exists (not real display), do nothing</span> <span class="Comment"># todo: help test this</span> <span class="Delimiter">{</span> <span class="muControl">break-unless</span> screen <span class="muControl">return</span> <span class="Delimiter">}</span> <span class="Comment"># otherwise, real screen</span> hide-display ] <span class="muRecipe">def</span> show-screen screen:address:screen<span class="muRecipe"> -&gt; </span>screen:address:screen [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</span> <span class="Comment"># if x exists (not real display), do nothing</span> <span class="Comment"># todo: help test this</span> <span class="Delimiter">{</span> <span class="muControl">break-unless</span> screen <span class="muControl">return</span> <span class="Delimiter">}</span> <span class="Comment"># otherwise, real screen</span> show-display ] <span class="muRecipe">def</span> print screen:address:screen, s:text<span class="muRecipe"> -&gt; </span>screen:address:screen [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</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? color<span class="Special"> &lt;- </span>copy <span class="Constant">7/white</span> <span class="Delimiter">}</span> bg-color:number, bg-color-found?:boolean<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span> <span class="Delimiter">{</span> <span class="Comment"># default bg-color to black</span> <span class="muControl">break-if</span> bg-color-found? bg-color<span class="Special"> &lt;- </span>copy <span class="Constant">0/black</span> <span class="Delimiter">}</span> len:number<span class="Special"> &lt;- </span>length *s i:number<span class="Special"> &lt;- </span>copy <span class="Constant">0</span> <span class="Delimiter">{</span> done?:boolean<span class="Special"> &lt;- </span>greater-or-equal i, len <span class="muControl">break-if</span> done? c:character<span class="Special"> &lt;- </span>index *s, i print screen, c, color, bg-color i<span class="Special"> &lt;- </span>add i, <span class="Constant">1</span> <span class="muControl">loop</span> <span class="Delimiter">}</span> ] <span class="muScenario">scenario</span> print-text-stops-at-right-margin [ run [ <span class="Constant">local-scope</span> fake-screen:address:screen<span class="Special"> &lt;- </span>new-fake-screen <span class="Constant">3/width</span>, <span class="Constant">2/height</span> s:text<span class="Special"> &lt;- </span>new <span class="Constant">[abcd]</span> fake-screen<span class="Special"> &lt;- </span>print fake-screen, s:text cell:address:array:screen-cell<span class="Special"> &lt;- </span>get *fake-screen, <span class="Constant">data:offset</span> <span class="Constant">10</span>:array:screen-cell/<span class="Special">raw &lt;- </span>copy *cell ] memory-should-contain [ <span class="Constant">10</span><span class="Special"> &lt;- </span><span class="Constant">6</span> <span class="Comment"># width*height</span> <span class="Constant">11</span><span class="Special"> &lt;- </span><span class="Constant">97</span> <span class="Comment"># 'a'</span> <span class="Constant">12</span><span class="Special"> &lt;- </span><span class="Constant">7</span> <span class="Comment"># white</span> <span class="Constant">13</span><span class="Special"> &lt;- </span><span class="Constant">98</span> <span class="Comment"># 'b'</span> <span class="Constant">14</span><span class="Special"> &lt;- </span><span class="Constant">7</span> <span class="Comment"># white</span> <span class="Constant">15</span><span class="Special"> &lt;- </span><span class="Constant">100</span> <span class="Comment"># 'd' overwrites 'c'</span> <span class="Constant">16</span><span class="Special"> &lt;- </span><span class="Constant">7</span> <span class="Comment"># white</span> <span class="Comment"># rest of screen is empty</span> <span class="Constant">17</span><span class="Special"> &lt;- </span><span class="Constant">0</span> ] ] <span class="muRecipe">def</span> print-integer screen:address:screen, n:number<span class="muRecipe"> -&gt; </span>screen:address:screen [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</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? color<span class="Special"> &lt;- </span>copy <span class="Constant">7/white</span> <span class="Delimiter">}</span> bg-color:number, bg-color-found?:boolean<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span> <span class="Delimiter">{</span> <span class="Comment"># default bg-color to black</span> <span class="muControl">break-if</span> bg-color-found? bg-color<span class="Special"> &lt;- </span>copy <span class="Constant">0/black</span> <span class="Delimiter">}</span> <span class="Comment"># todo: other bases besides decimal</span> s:text<span class="Special"> &lt;- </span>to-text n screen<span class="Special"> &lt;- </span>print screen, s, color, bg-color ] <span class="Comment"># for now, we can only print integers</span> <span class="muRecipe">def</span> print screen:address:screen, n:number<span class="muRecipe"> -&gt; </span>screen:address:screen [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</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? color<span class="Special"> &lt;- </span>copy <span class="Constant">7/white</span> <span class="Delimiter">}</span> bg-color:number, bg-color-found?:boolean<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span> <span class="Delimiter">{</span> <span class="Comment"># default bg-color to black</span> <span class="muControl">break-if</span> bg-color-found? bg-color<span class="Special"> &lt;- </span>copy <span class="Constant">0/black</span> <span class="Delimiter">}</span> screen<span class="Special"> &lt;- </span>print-integer screen, n, color, bg-color ] <span class="Comment"># addresses</span> <span class="muRecipe">def</span> print screen:address:screen, n:address:_elem<span class="muRecipe"> -&gt; </span>screen:address:screen [ <span class="Constant">local-scope</span> <span class="Constant">load-ingredients</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? color<span class="Special"> &lt;- </span>copy <span class="Constant">7/white</span> <span class="Delimiter">}</span> bg-color:number, bg-color-found?:boolean<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span> <span class="Delimiter">{</span> <span class="Comment"># default bg-color to black</span> <span class="muControl">break-if</span> bg-color-found? bg-color<span class="Special"> &lt;- </span>copy <span class="Constant">0/black</span> <span class="Delimiter">}</span> n2:number<span class="Special"> &lt;- </span>copy n screen<span class="Special"> &lt;- </span>print-integer screen, n2, color, bg-color ] </pre> </body> </html> <!-- vim: set foldmethod=manual : -->