1
2
3 scenario sandbox-click-on-code-toggles-app-trace [
4 local-scope
5 trace-until 100/app
6 assume-screen 100/width, 10/height
7
8 assume-resources [
9 ¦ [lesson/recipes.mu] <- [
10 ¦ ¦ |recipe foo [|
11 ¦ ¦ | stash [abc]|
12 ¦ ¦ |]|
13 ¦ ]
14 ]
15 env:&:environment <- new-programming-environment resources, screen, [foo]
16
17 assume-console [
18 ¦ press F4
19 ]
20 event-loop screen, console, env, resources
21 screen-should-contain [
22 ¦ . run (F4) .
23 ¦ .recipe foo [ ╎ .
24 ¦ . stash [abc] ╎─────────────────────────────────────────────────.
25 ¦ .] ╎0 edit copy delete .
26 ¦ . ╎foo .
27 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────.
28 ¦ . ╎ .
29 ]
30
31 assume-console [
32 ¦ left-click 4, 51
33 ]
34 run [
35 ¦ event-loop screen, console, env, resources
36 ¦ cursor:char <- copy 9251/␣
37 ¦ print screen, cursor
38 ]
39
40 screen-should-contain [
41 ¦ . run (F4) .
42 ¦ .␣ecipe foo [ ╎ .
43 ¦ . stash [abc] ╎─────────────────────────────────────────────────.
44 ¦ .] ╎0 edit copy delete .
45 ¦ . ╎foo .
46 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎abc .
47 ]
48 screen-should-contain-in-color 245/grey, [
49 ¦ . .
50 ¦ . ╎ .
51 ¦ . ╎─────────────────────────────────────────────────.
52 ¦ . ╎ .
53 ¦ . ╎ .
54 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎abc .
55 ]
56
57 assume-console [
58 ¦ left-click 4, 55
59 ]
60 run [
61 ¦ event-loop screen, console, env, resources
62 ¦ print screen, cursor
63 ]
64
65 screen-should-contain [
66 ¦ . run (F4) .
67 ¦ .␣ecipe foo [ ╎ .
68 ¦ . stash [abc] ╎─────────────────────────────────────────────────.
69 ¦ .] ╎0 edit copy delete .
70 ¦ . ╎foo .
71 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────.
72 ¦ . ╎ .
73 ]
74 ]
75
76 scenario sandbox-shows-app-trace-and-result [
77 local-scope
78 trace-until 100/app
79 assume-screen 100/width, 10/height
80
81 assume-resources [
82 ¦ [lesson/recipes.mu] <- [
83 ¦ ¦ |recipe foo [|
84 ¦ ¦ | stash [abc]|
85 ¦ ¦ | reply 4|
86 ¦ ¦ |]|
87 ¦ ]
88 ]
89 env:&:environment <- new-programming-environment resources, screen, [foo]
90
91 assume-console [
92 ¦ press F4
93 ]
94 event-loop screen, console, env, resources
95 screen-should-contain [
96 ¦ . run (F4) .
97 ¦ .recipe foo [ ╎ .
98 ¦ . stash [abc] ╎─────────────────────────────────────────────────.
99 ¦ . reply 4 ╎0 edit copy delete .
100 ¦ .] ╎foo .
101 ¦ . ╎4 .
102 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────.
103 ¦ . ╎ .
104 ]
105
106 assume-console [
107 ¦ left-click 4, 51
108 ]
109 run [
110 ¦ event-loop screen, console, env, resources
111 ]
112
113 screen-should-contain [
114 ¦ . run (F4) .
115 ¦ .recipe foo [ ╎ .
116 ¦ . stash [abc] ╎─────────────────────────────────────────────────.
117 ¦ . reply 4 ╎0 edit copy delete .
118 ¦ .] ╎foo .
119 ¦ . ╎abc .
120 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎8 instructions run .
121 ¦ . ╎4 .
122 ¦ . ╎─────────────────────────────────────────────────.
123 ¦ . ╎ .
124 ]
125 ]
126
127 scenario clicking-on-app-trace-does-nothing [
128 local-scope
129 trace-until 100/app
130 assume-screen 100/width, 10/height
131 assume-resources [
132 ]
133 env:&:environment <- new-programming-environment resources, screen, [stash 123456789]
134
135 assume-console [
136 ¦ press F4
137 ¦ left-click 4, 51
138 ]
139 event-loop screen, console, env, resources
140 screen-should-contain [
141 ¦ . run (F4) .
142 ¦ . ╎ .
143 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────.
144 ¦ . ╎0 edit copy delete .
145 ¦ . ╎stash 123456789 .
146 ¦ . ╎123456789 .
147 ]
148
149 assume-console [
150 ¦ left-click 5, 57
151 ]
152 run [
153 ¦ event-loop screen, console, env, resources
154 ]
155
156 screen-should-contain [
157 ¦ . run (F4) .
158 ¦ . ╎ .
159 ¦ .╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╎─────────────────────────────────────────────────.
160 ¦ . ╎0 edit copy delete .
161 ¦ . ╎stash 123456789 .
162 ¦ . ╎123456789 .
163 ]
164 ]
165
166 container sandbox [
167 trace:text
168 display-trace?:bool
169 ]
170
171
172 def! update-sandbox sandbox:&:sandbox, env:&:environment, idx:num -> sandbox:&:sandbox, env:&:environment [
173 local-scope
174 load-ingredients
175 data:text <- get *sandbox, data:offset
176 response:text, _, fake-screen:&:screen, trace:text <- run-sandboxed data
177 *sandbox <- put *sandbox, response:offset, response
178 *sandbox <- put *sandbox, screen:offset, fake-screen
179 *sandbox <- put *sandbox, trace:offset, trace
180 ]
181
182
183 after <global-touch> [
184
185 {
186 ¦ sandbox-left-margin:num <- get *current-sandbox, left:offset
187 ¦ click-column:num <- get t, column:offset
188 ¦ on-sandbox-side?:bool <- greater-or-equal click-column, sandbox-left-margin
189 ¦ break-unless on-sandbox-side?
190 ¦ first-sandbox:&:sandbox <- get *env, sandbox:offset
191 ¦ break-unless first-sandbox
192 ¦ first-sandbox-begins:num <- get *first-sandbox, starting-row-on-screen:offset
193 ¦ click-row:num <- get t, row:offset
194 ¦ below-sandbox-editor?:bool <- greater-or-equal click-row, first-sandbox-begins
195 ¦ break-unless below-sandbox-editor?
196 ¦
197 ¦ sandbox:&:sandbox <- find-click-in-sandbox-code env, click-row
198 ¦ break-unless sandbox
199 ¦
200 ¦ x:bool <- get *sandbox, display-trace?:offset
201 ¦ x <- not x
202 ¦ *sandbox <- put *sandbox, display-trace?:offset, x
203 ¦ hide-screen screen
204 ¦ screen <- render-sandbox-side screen, env, render
205 ¦ screen <- update-cursor screen, recipes, current-sandbox, sandbox-in-focus?, env
206 ¦ show-screen screen
207 ¦ loop +next-event
208 }
209 ]
210
211 def find-click-in-sandbox-code env:&:environment, click-row:num -> sandbox:&:sandbox [
212 local-scope
213 load-ingredients
214
215 sandbox <- get *env, sandbox:offset
216 start:num <- get *sandbox, starting-row-on-screen:offset
217 clicked-on-sandboxes?:bool <- greater-or-equal click-row, start
218 assert clicked-on-sandboxes?, [extract-sandbox called on click to sandbox editor]
219
220 {
221 ¦ next-sandbox:&:sandbox <- get *sandbox, next-sandbox:offset
222 ¦ break-unless next-sandbox
223 ¦ next-start:num <- get *next-sandbox, starting-row-on-screen:offset
224 ¦ found?:bool <- lesser-than click-row, next-start
225 ¦ break-if found?
226 ¦ sandbox <- copy next-sandbox
227 ¦ loop
228 }
229
230 code-ending-row:num <- get *sandbox, code-ending-row-on-screen:offset
231 click-above-response?:bool <- lesser-than click-row, code-ending-row
232 start:num <- get *sandbox, starting-row-on-screen:offset
233 click-below-menu?:bool <- greater-than click-row, start
234 click-on-sandbox-code?:bool <- and click-above-response?, click-below-menu?
235 {
236 ¦ break-if click-on-sandbox-code?
237 ¦ return 0/no-click-in-sandbox-output
238 }
239 return sandbox
240 ]
241
242
243 after <render-sandbox-results> [
244 {
245 ¦ display-trace?:bool <- get *sandbox, display-trace?:offset
246 ¦ break-unless display-trace?
247 ¦ sandbox-trace:text <- get *sandbox, trace:offset
248 ¦ break-unless sandbox-trace
249 ¦ row, screen <- render-text screen, sandbox-trace, left, right, 245/grey, row
250 }
251 <render-sandbox-trace-done>
252 ]