1 ## putting the environment together out of editors
  2 #
  3 # Consists of one editor on the left for recipes and one on the right for the
  4 # sandbox.
  5 
  6 def! main [
  7   local-scope
  8   open-console
  9   env:&:environment <- new-programming-environment 0/filesystem, 0/screen
 10   render-all 0/screen, env, render
 11   event-loop 0/screen, 0/console, env, 0/filesystem
 12   # never gets here
 13 ]
 14 
 15 container environment [
 16   recipes:&:editor
 17   current-sandbox:&:editor
 18   sandbox-in-focus?:bool  # false => cursor in recipes; true => cursor in current-sandbox
 19 ]
 20 
 21 def new-programming-environment resources:&:resources, screen:&:screen, test-sandbox-editor-contents:text -> result:&:environment [
 22   local-scope
 23   load-ingredients
 24   width:num <- screen-width screen
 25   result <- new environment:type
 26   # recipe editor on the left
 27   initial-recipe-contents:text <- slurp resources, [lesson/recipes.mu]  # ignore errors
 28   divider:num, _ <- divide-with-remainder width, 2
 29   recipes:&:editor <- new-editor initial-recipe-contents, 0/left, divider/right
 30   # sandbox editor on the right
 31   sandbox-left:num <- add divider, 1
 32   current-sandbox:&:editor <- new-editor test-sandbox-editor-contents, sandbox-left, width/right
 33   *result <- put *result, recipes:offset, recipes
 34   *result <- put *result, current-sandbox:offset, current-sandbox
 35   *result <- put *result, sandbox-in-focus?:offset, 0/false
 36   <programming-environment-initialization>
 37 ]
 38 
 39 def event-loop screen:&:screen, console:&:console, env:&:environment, resources:&:resources -> screen:&:screen, console:&:console, env:&:environment, resources:&:resources [
 40   local-scope
 41   load-ingredients
 42   recipes:&:editor <- get *env, recipes:offset
 43   current-sandbox:&:editor <- get *env, current-sandbox:offset
 44   sandbox-in-focus?:bool <- get *env, sandbox-in-focus?:offset
 45   # if we fall behind we'll stop updating the screen, but then we have to
 46   # render the entire screen when we catch up.
 47   # todo: test this
 48   render-all-on-no-more-events?:bool <- copy 0/false
 49   {
 50   ¦ # looping over each (keyboard or touch) event as it occurs
 51   ¦ +next-event
 52   ¦ e:event, found?:bool, quit?:bool, console <- read-event console
 53   ¦ loop-unless found?
 54   ¦ break-if quit?  # only in tests
 55   ¦ trace 10, [app], [next-event]
 56   ¦ <handle-event>
 57   ¦ # check for global events that will trigger regardless of which editor has focus
 58   ¦ {
 59   ¦ ¦ k:num, is-keycode?:bool <- maybe-convert e:event, keycode:variant
 60   ¦ ¦ break-unless is-keycode?
 61   ¦ ¦ <global-keypress>
 62   ¦ }
 63   ¦ {
 64   ¦ ¦ c:char, is-unicode?:bool <- maybe-convert e:event, text:variant
 65   ¦ ¦ break-unless is-unicode?
 66   ¦ ¦ <global-type>
 67   ¦ }
 68   ¦ # 'touch' event - send to both sides, see what picks it up
 69   ¦ {
 70   ¦ ¦ t:touch-event, is-touch?:bool <- maybe-convert e:event, touch:variant
 71   ¦ ¦ break-unless is-touch?
 72   ¦ ¦ # ignore all but 'left-click' events for now
 73   ¦ ¦ # todo: test this
 74   ¦ ¦ touch-type:num <- get t, type:offset
 75   ¦ ¦ is-left-click?:bool <- equal touch-type, 65513/mouse-left
 76   ¦ ¦ loop-unless is-left-click?, +next-event
 77   ¦ ¦ click-row:num <- get t, row:offset
 78   ¦ ¦ click-column:num <- get t, column:offset
 79   ¦ ¦ # later exceptions for non-editor touches will go here
 80   ¦ ¦ <global-touch>
 81   ¦ ¦ # send to both editors
 82   ¦ ¦ _ <- move-cursor-in-editor screen, recipes, t
 83   ¦ ¦ sandbox-in-focus?:bool <- move-cursor-in-editor screen, current-sandbox, t
 84   ¦ ¦ *env <- put *env, sandbox-in-focus?:offset, sandbox-in-focus?
 85   ¦ ¦ screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env
 86   ¦ ¦ loop +next-event
 87   ¦ }
 88   ¦ # 'resize' event - redraw editor
 89   ¦ # todo: test this after supporting resize in assume-console
 90   ¦ {
 91   ¦ ¦ r:resize-event, is-resize?:bool <- maybe-convert e:event, resize:variant
 92   ¦ ¦ break-unless is-resize?
 93   ¦ ¦ env, screen <- resize screen, env
 94   ¦ ¦ screen <- render-all screen, env, render-without-moving-cursor
 95   ¦ ¦ loop +next-event
 96   ¦ }
 97   ¦ # if it's not global and not a touch event, send to appropriate editor
 98   ¦ {
 99   ¦ ¦ hide-screen screen
100   ¦ ¦ sandbox-in-focus?:bool <- get *env, sandbox-in-focus?:offset
101   ¦ ¦ {
102   ¦ ¦ ¦ break-if sandbox-in-focus?
103   ¦ ¦ ¦ render?:bool <- handle-keyboard-event screen, recipes, e:event
104   ¦ ¦ ¦ # refresh screen only if no more events
105   ¦ ¦ ¦ # if there are more events to process, wait for them to clear up, then make sure you render-all afterward.
106   ¦ ¦ ¦ more-events?:bool <- has-more-events? console
107   ¦ ¦ ¦ {
108   ¦ ¦ ¦ ¦ break-unless more-events?
109   ¦ ¦ ¦ ¦ render-all-on-no-more-events? <- copy 1/true  # no rendering now, full rendering on some future event
110   ¦ ¦ ¦ ¦ jump +finish-event
111   ¦ ¦ ¦ }
112   ¦ ¦ ¦ {
113   ¦ ¦ ¦ ¦ break-if more-events?
114   ¦ ¦ ¦ ¦ {
115   ¦ ¦ ¦ ¦ ¦ break-unless render-all-on-no-more-events?
116   ¦ ¦ ¦ ¦ ¦ # no more events, and we have to force render
117   ¦ ¦ ¦ ¦ ¦ screen <- render-all screen, env, render
118   ¦ ¦ ¦ ¦ ¦ render-all-on-no-more-events? <- copy 0/false
119   ¦ ¦ ¦ ¦ ¦ jump +finish-event
120   ¦ ¦ ¦ ¦ }
121   ¦ ¦ ¦ ¦ # no more events, no force render
122   ¦ ¦ ¦ ¦ {
123   ¦ ¦ ¦ ¦ ¦ break-unless render?
124   ¦ ¦ ¦ ¦ ¦ screen <- render-recipes screen, env, render
125   ¦ ¦ ¦ ¦ ¦ jump +finish-event
126   ¦ ¦ ¦ ¦ }
127   ¦ ¦ ¦ }
128   ¦ ¦ }
129   ¦ ¦ {
130   ¦ ¦ ¦ break-unless sandbox-in-focus?
131   ¦ ¦ ¦ render?:bool <- handle-keyboard-event screen, current-sandbox, e:event
132   ¦ ¦ ¦ # refresh screen only if no more events
133   ¦ ¦ ¦ # if there are more events to process, wait for them to clear up, then make sure you render-all afterward.
134   ¦ ¦ ¦ more-events?:bool <- has-more-events? console
135   ¦ ¦ ¦ {
136   ¦ ¦ ¦ ¦ break-unless more-events?
137   ¦ ¦ ¦ ¦ render-all-on-no-more-events? <- copy 1/true  # no rendering now, full rendering on some future event
138   ¦ ¦ ¦ ¦ jump +finish-event
139   ¦ ¦ ¦ }
140   ¦ ¦ ¦ {
141   ¦ ¦ ¦ ¦ break-if more-events?
142   ¦ ¦ ¦ ¦ {
143   ¦ ¦ ¦ ¦ ¦ break-unless render-all-on-no-more-events?
144   ¦ ¦ ¦ ¦ ¦ # no more events, and we have to force render
145   ¦ ¦ ¦ ¦ ¦ screen <- render-all screen, env, render
146   ¦ ¦ ¦ ¦ ¦ render-all-on-no-more-events? <- copy 0/false
147   ¦ ¦ ¦ ¦ ¦ jump +finish-event
148   ¦ ¦ ¦ ¦ }
149   ¦ ¦ ¦ ¦ # no more events, no force render
150   ¦ ¦ ¦ ¦ {
151   ¦ ¦ ¦ ¦ ¦ break-unless render?
152   ¦ ¦ ¦ ¦ ¦ screen <- render-sandbox-side screen, env, render
153   ¦ ¦ ¦ ¦ ¦ jump +finish-event
154   ¦ ¦ ¦ ¦ }
155   ¦ ¦ ¦ }
156   ¦ ¦ }
157   ¦ ¦ +finish-event
158   ¦ ¦ screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env
159   ¦ ¦ show-screen screen
160   ¦ }
161   ¦ loop
162   }
163 ]
164 
165 def resize screen:&:screen, env:&:environment -> env:&:environment, screen:&:screen [
166   local-scope
167   load-ingredients
168   clear-screen screen  # update screen dimensions
169   width:num <- screen-width screen
170   divider:num, _ <- divide-with-remainder width, 2
171   # update recipe editor
172   recipes:&:editor <- get *env, recipes:offset
173   right:num <- subtract divider, 1
174   *recipes <- put *recipes, right:offset, right
175   # reset cursor (later we'll try to preserve its position)
176   *recipes <- put *recipes, cursor-row:offset, 1
177   *recipes <- put *recipes, cursor-column:offset, 0
178   # update sandbox editor
179   current-sandbox:&:editor <- get *env, current-sandbox:offset
180   left:num <- add divider, 1
181   *current-sandbox <- put *current-sandbox, left:offset, left
182   right:num <- subtract width, 1
183   *current-sandbox <- put *current-sandbox, right:offset, right
184   # reset cursor (later we'll try to preserve its position)
185   *current-sandbox <- put *current-sandbox, cursor-row:offset, 1
186   *current-sandbox <- put *current-sandbox, cursor-column:offset, left
187 ]
188 
189 # Variant of 'render' that updates cursor-row and cursor-column based on
190 # before-cursor (rather than the other way around). If before-cursor moves
191 # off-screen, it resets cursor-row and cursor-column.
192 def render-without-moving-cursor screen:&:screen, editor:&:editor -> last-row:num, last-column:num, screen:&:screen, editor:&:editor [
193   local-scope
194   load-ingredients
195   return-unless editor, 1/top, 0/left
196   left:num <- get *editor, left:offset
197   screen-height:num <- screen-height screen
198   right:num <- get *editor, right:offset
199   curr:&:duplex-list:char <- get *editor, top-of-screen:offset
200   prev:&:duplex-list:char <- copy curr  # just in case curr becomes null and we can't compute prev
201   curr <- next curr
202   color:num <- copy 7/white
203   row:num <- copy 1/top
204   column:num <- copy left
205   # save before-cursor
206   old-before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset
207   # initialze cursor-row/cursor-column/before-cursor to the top of the screen
208   # by default
209   *editor <- put *editor, cursor-row:offset, row
210   *editor <- put *editor, cursor-column:offset, column
211   top-of-screen:&:duplex-list:char <- get *editor, top-of-screen:offset
212   *editor <- put *editor, before-cursor:offset, top-of-screen
213   screen <- move-cursor screen, row, column
214   {
215   ¦ +next-character
216   ¦ break-unless curr
217   ¦ off-screen?:bool <- greater-or-equal row, screen-height
218   ¦ break-if off-screen?
219   ¦ # if we find old-before-cursor still on the new resized screen, update
220   ¦ # editor.cursor-row and editor.cursor-column based on
221   ¦ # old-before-cursor
222   ¦ {
223   ¦ ¦ at-cursor?:bool <- equal old-before-cursor, prev
224   ¦ ¦ break-unless at-cursor?
225   ¦ ¦ *editor <- put *editor, cursor-row:offset, row
226   ¦ ¦ *editor <- put *editor, cursor-column:offset, column
227   ¦ ¦ *editor <- put *editor, before-cursor:offset, old-before-cursor
228   ¦ }
229   ¦ c:char <- get *curr, value:offset
230   ¦ <character-c-received>
231   ¦ {
232   ¦ ¦ # newline? move to left rather than 0
233   ¦ ¦ newline?:bool <- equal c, 10/newline
234   ¦ ¦ break-unless newline?
235   ¦ ¦ # clear rest of line in this window
236   ¦ ¦ clear-line-until screen, right
237   ¦ ¦ # skip to next line
238   ¦ ¦ row <- add row, 1
239   ¦ ¦ column <- copy left
240   ¦ ¦ screen <- move-cursor screen, row, column
241   ¦ ¦ curr <- next curr
242   ¦ ¦ prev <- next prev
243   ¦ ¦ loop +next-character
244   ¦ }
245   ¦ {
246   ¦ ¦ # at right? wrap. even if there's only one more letter left; we need
247   ¦ ¦ # room for clicking on the cursor after it.
248   ¦ ¦ at-right?:bool <- equal column, right
249   ¦ ¦ break-unless at-right?
250   ¦ ¦ # print wrap icon
251   ¦ ¦ wrap-icon:char <- copy 8617/loop-back-to-left
252   ¦ ¦ print screen, wrap-icon, 245/grey
253   ¦ ¦ column <- copy left
254   ¦ ¦ row <- add row, 1
255   ¦ ¦ screen <- move-cursor screen, row, column
256   ¦ ¦ # don't increment curr
257   ¦ ¦ loop +next-character
258   ¦ }
259   ¦ print screen, c, color
260   ¦ curr <- next curr
261   ¦ prev <- next prev
262   ¦ column <- add column, 1
263   ¦ loop
264   }
265   # save first character off-screen
266   *editor <- put *editor, bottom-of-screen:offset, curr
267   *editor <- put *editor, bottom:offset, row
268   return row, column
269 ]
270 
271 scenario point-at-multiple-editors [
272   local-scope
273   trace-until 100/app  # trace too long
274   assume-screen 30/width, 5/height
275   # initialize both halves of screen
276   assume-resources [
277   ¦ [lesson/recipes.mu] <- [
278   ¦ ¦ |abc|
279   ¦ ]
280   ]
281   env:&:environment <- new-programming-environment resources, screen, [def]  # contents of sandbox editor
282   # focus on both sides
283   assume-console [
284   ¦ left-click 1, 1
285   ¦ left-click 1, 17
286   ]
287   # check cursor column in each
288   run [
289   ¦ event-loop screen, console, env, resources
290   ¦ recipes:&:editor <- get *env, recipes:offset
291   ¦ 5:num/raw <- get *recipes, cursor-column:offset
292   ¦ sandbox:&:editor <- get *env, current-sandbox:offset
293   ¦ 7:num/raw <- get *sandbox, cursor-column:offset
294   ]
295   memory-should-contain [
296   ¦ 5 <- 1
297   ¦ 7 <- 17
298   ]
299 ]
300 
301 scenario edit-multiple-editors [
302   local-scope
303   trace-until 100/app  # trace too long
304   assume-screen 30/width, 5/height
305   # initialize both halves of screen
306   assume-resources [
307   ¦ [lesson/recipes.mu] <- [
308   ¦ ¦ |abc|
309   ¦ ]
310   ]
311   env:&:environment <- new-programming-environment resources, screen, [def]  # contents of sandbox
312   render-all screen, env, render
313   # type one letter in each of them
314   assume-console [
315   ¦ left-click 1, 1
316   ¦ type [0]
317   ¦ left-click 1, 17
318   ¦ type [1]
319   ]
320   run [
321   ¦ event-loop screen, console, env, resources
322   ¦ recipes:&:editor <- get *env, recipes:offset
323   ¦ 5:num/raw <- get *recipes, cursor-column:offset
324   ¦ sandbox:&:editor <- get *env, current-sandbox:offset
325   ¦ 7:num/raw <- get *sandbox, cursor-column:offset
326   ]
327   screen-should-contain [
328   ¦ .           run (F4)           .  # this line has a different background, but we don't test that yet
329   ¦ .a0bc           ╎d1ef          .
330   ¦ .               ╎──────────────.
331   ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎              .
332   ¦ .               ╎              .
333   ]
334   memory-should-contain [
335   ¦ 5 <- 2  # cursor column of recipe editor
336   ¦ 7 <- 18  # cursor column of sandbox editor
337   ]
338   # show the cursor at the right window
339   run [
340   ¦ cursor:char <- copy 9251/␣
341   ¦ print screen, cursor
342   ]
343   screen-should-contain [
344   ¦ .           run (F4)           .
345   ¦ .a0bc           ╎d1␣f          .
346   ¦ .               ╎──────────────.
347   ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎              .
348   ¦ .               ╎              .
349   ]
350 ]
351 
352 scenario editor-in-focus-keeps-cursor [
353   local-scope
354   trace-until 100/app  # trace too long
355   assume-screen 30/width, 5/height
356   assume-resources [
357   ¦ [lesson/recipes.mu] <- [
358   ¦ ¦ |abc|
359   ¦ ]
360   ]
361   env:&:environment <- new-programming-environment resources, screen, [def]
362   render-all screen, env, render
363   # initialize programming environment and highlight cursor
364   assume-console []
365   run [
366   ¦ event-loop screen, console, env, resources
367   ¦ cursor:char <- copy 9251/␣
368   ¦ print screen, cursor
369   ]
370   # is cursor at the right place?
371   screen-should-contain [
372   ¦ .           run (F4)           .
373   ¦ .␣bc            ╎def           .
374   ¦ .               ╎──────────────.
375   ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎              .
376   ¦ .               ╎              .
377   ]
378   # now try typing a letter
379   assume-console [
380   ¦ type [z]
381   ]
382   run [
383   ¦ event-loop screen, console, env, resources
384   ¦ cursor:char <- copy 9251/␣
385   ¦ print screen, cursor
386   ]
387   # cursor should still be right
388   screen-should-contain [
389   ¦ .           run (F4)           .
390   ¦ .z␣bc           ╎def           .
391   ¦ .               ╎──────────────.
392   ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎              .
393   ¦ .               ╎              .
394   ]
395 ]
396 
397 scenario backspace-in-sandbox-editor-joins-lines [
398   local-scope
399   trace-until 100/app  # trace too long
400   assume-screen 30/width, 5/height
401   assume-resources [
402   ]
403   # initialize sandbox side with two lines
404   test-sandbox-editor-contents:text <- new [abc
405 def]
406   env:&:environment <- new-programming-environment resources, screen, test-sandbox-editor-contents
407   render-all screen, env, render
408   screen-should-contain [
409   ¦ .           run (F4)           .
410   ¦ .               ╎abc           .
411   ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎def           .
412   ¦ .               ╎──────────────.
413   ¦ .               ╎              .
414   ]
415   # position cursor at start of second line and hit backspace
416   assume-console [
417   ¦ left-click 2, 16
418   ¦ press backspace
419   ]
420   run [
421   ¦ event-loop screen, console, env, resources
422   ¦ cursor:char <- copy 9251/␣
423   ¦ print screen, cursor
424   ]
425   # cursor moves to end of old line
426   screen-should-contain [
427   ¦ .           run (F4)           .
428   ¦ .               ╎abc␣ef        .
429   ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎──────────────.
430   ¦ .               ╎              .
431   ]
432 ]
433 
434 def render-all screen:&:screen, env:&:environment, {render-editor: (recipe (address screen) (address editor) -> number number (address screen) (address editor))} -> screen:&:screen, env:&:environment [
435   local-scope
436   load-ingredients
437   trace 10, [app], [render all]
438   hide-screen screen
439   # top menu
440   trace 11, [app], [render top menu]
441   width:num <- screen-width screen
442   draw-horizontal screen, 0, 0/left, width, 32/space, 0/black, 238/grey
443   button-start:num <- subtract width, 20
444   button-on-screen?:bool <- greater-or-equal button-start, 0
445   assert button-on-screen?, [screen too narrow for menu]
446   screen <- move-cursor screen, 0/row, button-start
447   print screen, [ run (F4) ], 255/white, 161/reddish
448   # dotted line down the middle
449   trace 11, [app], [render divider]
450   divider:num, _ <- divide-with-remainder width, 2
451   height:num <- screen-height screen
452   draw-vertical screen, divider, 1/top, height, 9482/vertical-dotted
453   #
454   screen <- render-recipes screen, env, render-editor
455   screen <- render-sandbox-side screen, env, render-editor
456   <render-components-end>
457   #
458   recipes:&:editor <- get *env, recipes:offset
459   current-sandbox:&:editor <- get *env, current-sandbox:offset
460   sandbox-in-focus?:bool <- get *env, sandbox-in-focus?:offset
461   screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env
462   #
463   show-screen screen
464 ]
465 
466 def render-recipes screen:&:screen, env:&:environment, {render-editor: (recipe (address screen) (address editor) -> number number (address screen) (address editor))} -> screen:&:screen, env:&:environment [
467   local-scope
468   load-ingredients
469   trace 11, [app], [render recipes]
470   recipes:&:editor <- get *env, recipes:offset
471   # render recipes
472   left:num <- get *recipes, left:offset
473   right:num <- get *recipes, right:offset
474   row:num, column:num, screen <- call render-editor, screen, recipes
475   clear-line-until screen, right
476   row <- add row, 1
477   <render-recipe-components-end>
478   # draw dotted line after recipes
479   draw-horizontal screen, row, left, right, 9480/horizontal-dotted
480   row <- add row, 1
481   clear-screen-from screen, row, left, left, right
482 ]
483 
484 # replaced in a later layer
485 def render-sandbox-side screen:&:screen, env:&:environment, {render-editor: (recipe (address screen) (address editor) -> number number (address screen) (address editor))} -> screen:&:screen, env:&:environment [
486   local-scope
487   load-ingredients
488   current-sandbox:&:editor <- get *env, current-sandbox:offset
489   left:num <- get *current-sandbox, left:offset
490   right:num <- get *current-sandbox, right:offset
491   row:num, column:num, screen, current-sandbox <- call render-editor, screen, current-sandbox
492   clear-line-until screen, right
493   row <- add row, 1
494   # draw solid line after code (you'll see why in later layers)
495   draw-horizontal screen, row, left, right
496   row <- add row, 1
497   clear-screen-from screen, row, left, left, right
498 ]
499 
500 def update-cursor screen:&:screen, recipes:&:editor, current-sandbox:&:editor, sandbox-in-focus?:bool, env:&:environment -> screen:&:screen [
501   local-scope
502   load-ingredients
503   <update-cursor-special-cases>
504   {
505   ¦ break-if sandbox-in-focus?
506   ¦ cursor-row:num <- get *recipes, cursor-row:offset
507   ¦ cursor-column:num <- get *recipes, cursor-column:offset
508   }
509   {
510   ¦ break-unless sandbox-in-focus?
511   ¦ cursor-row:num <- get *current-sandbox, cursor-row:offset
512   ¦ cursor-column:num <- get *current-sandbox, cursor-column:offset
513   }
514   screen <- move-cursor screen, cursor-row, cursor-column
515 ]
516 
517 # ctrl-l - redraw screen (just in case it printed junk somehow)
518 
519 after <global-type> [
520   {
521   ¦ redraw-screen?:bool <- equal c, 12/ctrl-l
522   ¦ break-unless redraw-screen?
523   ¦ screen <- render-all screen, env:&:environment, render
524   ¦ sync-screen screen
525   ¦ loop +next-event
526   }
527 ]
528 
529 # ctrl-n - switch focus
530 # todo: test this
531 
532 after <global-type> [
533   {
534   ¦ switch-side?:bool <- equal c, 14/ctrl-n
535   ¦ break-unless switch-side?
536   ¦ sandbox-in-focus?:bool <- get *env, sandbox-in-focus?:offset
537   ¦ sandbox-in-focus? <- not sandbox-in-focus?
538   ¦ *env <- put *env, sandbox-in-focus?:offset, sandbox-in-focus?
539   ¦ screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env
540   ¦ loop +next-event
541   }
542 ]
543 
544 ## helpers
545 
546 def draw-vertical screen:&:screen, col:num, y:num, bottom:num -> screen:&:screen [
547   local-scope
548   load-ingredients
549   style:char, style-found?:bool <- next-ingredient
550   {
551   ¦ break-if style-found?
552   ¦ style <- copy 9474/vertical
553   }
554   color:num, color-found?:bool <- next-ingredient
555   {
556   ¦ # default color to white
557   ¦ break-if color-found?
558   ¦ color <- copy 245/grey
559   }
560   {
561   ¦ continue?:bool <- lesser-than y, bottom
562   ¦ break-unless continue?
563   ¦ screen <- move-cursor screen, y, col
564   ¦ print screen, style, color
565   ¦ y <- add y, 1
566   ¦ loop
567   }
568 ]