From aac2775a4d30459c3090569b26e81ba18f1423a7 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sat, 24 Jun 2017 16:00:44 -0700 Subject: 3951 --- html/edit/001-editor.mu.html | 512 ++++++++++++++++++++++--------------------- 1 file changed, 257 insertions(+), 255 deletions(-) (limited to 'html/edit/001-editor.mu.html') diff --git a/html/edit/001-editor.mu.html b/html/edit/001-editor.mu.html index a928a2bc..8b13fc80 100644 --- a/html/edit/001-editor.mu.html +++ b/html/edit/001-editor.mu.html @@ -23,6 +23,7 @@ a:hover { text-decoration: underline; } .SalientComment { color: #00ffff; } .Constant { color: #00a0a0; } .LineNr { color: #444444; } +.CommentedCode { color: #6c6c6c; } .Comment { color: #9090ff; } .Comment a { color:#0000ee; text-decoration:underline; } .muControl { color: #c0a020; } @@ -69,7 +70,7 @@ if ('onhashchange' in window) { 6 local-scope 7 load-ingredients 8 open-console - 9 clear-screen 0/screen # non-scrolling app + 9 clear-screen 0/screen # non-scrolling app 10 e:&:editor <- new-editor text, 0/left, 5/right 11 render 0/screen, e 12 wait-for-event 0/console @@ -81,7 +82,7 @@ if ('onhashchange' in window) { 18 assume-screen 10/width, 5/height 19 e:&:editor <- new-editor [abc], 0/left, 10/right 20 run [ - 21 ¦ render screen, e + 21 ¦ render screen, e 22 ] 23 screen-should-contain [ 24 ¦ # top line of screen reserved for menu @@ -167,12 +168,12 @@ if ('onhashchange' in window) { 104 # Assumes cursor should be at coordinates (cursor-row, cursor-column) and 105 # updates before-cursor to match. Might also move coordinates if they're 106 # outside text. -107 def render screen:&:screen, editor:&:editor -> last-row:num, last-column:num, screen:&:screen, editor:&:editor [ +107 def render screen:&:screen, editor:&:editor -> last-row:num, last-column:num, screen:&:screen, editor:&:editor [ 108 local-scope 109 load-ingredients 110 return-unless editor, 1/top, 0/left 111 left:num <- get *editor, left:offset -112 screen-height:num <- screen-height screen +112 screen-height:num <- screen-height screen 113 right:num <- get *editor, right:offset 114 # traversing editor 115 curr:&:duplex-list:char <- get *editor, top-of-screen:offset @@ -185,11 +186,11 @@ if ('onhashchange' in window) { 122 cursor-row:num <- get *editor, cursor-row:offset 123 cursor-column:num <- get *editor, cursor-column:offset 124 before-cursor:&:duplex-list:char <- get *editor, before-cursor:offset -125 screen <- move-cursor screen, row, column +125 screen <- move-cursor screen, row, column 126 { 127 ¦ +next-character 128 ¦ break-unless curr -129 ¦ off-screen?:bool <- greater-or-equal row, screen-height +129 ¦ off-screen?:bool <- greater-or-equal row, screen-height 130 ¦ break-if off-screen? 131 ¦ # update editor.before-cursor 132 ¦ # Doing so at the start of each iteration ensures it stays one step behind @@ -217,11 +218,11 @@ if ('onhashchange' in window) { 154 ¦ ¦ ¦ before-cursor <- prev curr 155 ¦ ¦ } 156 ¦ ¦ # clear rest of line in this window -157 ¦ ¦ clear-line-until screen, right +157 ¦ ¦ clear-line-until screen, right 158 ¦ ¦ # skip to next line 159 ¦ ¦ row <- add row, 1 160 ¦ ¦ column <- copy left -161 ¦ ¦ screen <- move-cursor screen, row, column +161 ¦ ¦ screen <- move-cursor screen, row, column 162 ¦ ¦ curr <- next curr 163 ¦ ¦ prev <- next prev 164 ¦ ¦ loop +next-character @@ -233,14 +234,14 @@ if ('onhashchange' in window) { 170 ¦ ¦ break-unless at-right? 171 ¦ ¦ # print wrap icon 172 ¦ ¦ wrap-icon:char <- copy 8617/loop-back-to-left -173 ¦ ¦ print screen, wrap-icon, 245/grey +173 ¦ ¦ print screen, wrap-icon, 245/grey 174 ¦ ¦ column <- copy left 175 ¦ ¦ row <- add row, 1 -176 ¦ ¦ screen <- move-cursor screen, row, column +176 ¦ ¦ screen <- move-cursor screen, row, column 177 ¦ ¦ # don't increment curr 178 ¦ ¦ loop +next-character 179 ¦ } -180 ¦ print screen, c, color +180 ¦ print screen, c, color 181 ¦ curr <- next curr 182 ¦ prev <- next prev 183 ¦ column <- add column, 1 @@ -267,260 +268,261 @@ if ('onhashchange' in window) { 204 return row, column 205 ] 206 -207 def clear-screen-from screen:&:screen, row:num, column:num, left:num, right:num -> screen:&:screen [ +207 def clear-screen-from screen:&:screen, row:num, column:num, left:num, right:num -> screen:&:screen [ 208 local-scope 209 load-ingredients -210 # if it's the real screen, use the optimized primitive -211 { -212 ¦ break-if screen -213 ¦ clear-display-from row, column, left, right -214 ¦ return -215 } -216 # if not, go the slower route -217 screen <- move-cursor screen, row, column -218 clear-line-until screen, right -219 clear-rest-of-screen screen, row, left, right -220 ] -221 -222 def clear-rest-of-screen screen:&:screen, row:num, left:num, right:num -> screen:&:screen [ -223 local-scope -224 load-ingredients -225 row <- add row, 1 -226 # if it's the real screen, use the optimized primitive -227 { -228 ¦ break-if screen -229 ¦ clear-display-from row, left, left, right -230 ¦ return -231 } -232 screen <- move-cursor screen, row, left -233 screen-height:num <- screen-height screen -234 { -235 ¦ at-bottom-of-screen?:bool <- greater-or-equal row, screen-height -236 ¦ break-if at-bottom-of-screen? -237 ¦ screen <- move-cursor screen, row, left -238 ¦ clear-line-until screen, right -239 ¦ row <- add row, 1 -240 ¦ loop -241 } -242 ] -243 -244 scenario editor-prints-multiple-lines [ -245 local-scope -246 assume-screen 5/width, 5/height -247 s:text <- new [abc -248 def] -249 e:&:editor <- new-editor s, 0/left, 5/right -250 run [ -251 ¦ render screen, e -252 ] -253 screen-should-contain [ -254 ¦ . . -255 ¦ .abc . -256 ¦ .def . -257 ¦ . . -258 ] -259 ] -260 -261 scenario editor-handles-offsets [ -262 local-scope -263 assume-screen 5/width, 5/height -264 e:&:editor <- new-editor [abc], 1/left, 5/right -265 run [ -266 ¦ render screen, e -267 ] -268 screen-should-contain [ -269 ¦ . . -270 ¦ . abc . -271 ¦ . . -272 ] -273 ] -274 -275 scenario editor-prints-multiple-lines-at-offset [ -276 local-scope -277 assume-screen 5/width, 5/height -278 s:text <- new [abc -279 def] -280 e:&:editor <- new-editor s, 1/left, 5/right -281 run [ -282 ¦ render screen, e -283 ] -284 screen-should-contain [ -285 ¦ . . -286 ¦ . abc . -287 ¦ . def . -288 ¦ . . -289 ] -290 ] -291 -292 scenario editor-wraps-long-lines [ -293 local-scope -294 assume-screen 5/width, 5/height -295 e:&:editor <- new-editor [abc def], 0/left, 5/right -296 run [ -297 ¦ render screen, e -298 ] -299 screen-should-contain [ -300 ¦ . . -301 ¦ .abc ↩. -302 ¦ .def . -303 ¦ . . -304 ] -305 screen-should-contain-in-color 245/grey [ -306 ¦ . . -307 ¦ . ↩. -308 ¦ . . +210 #? stash [clear-screen-from] row column [between] left [and] right +211 # if it's the real screen, use the optimized primitive +212 { +213 ¦ break-if screen +214 ¦ clear-display-from row, column, left, right +215 ¦ return +216 } +217 # if not, go the slower route +218 screen <- move-cursor screen, row, column +219 clear-line-until screen, right +220 clear-rest-of-screen screen, row, left, right +221 ] +222 +223 def clear-rest-of-screen screen:&:screen, row:num, left:num, right:num -> screen:&:screen [ +224 local-scope +225 load-ingredients +226 row <- add row, 1 +227 # if it's the real screen, use the optimized primitive +228 { +229 ¦ break-if screen +230 ¦ clear-display-from row, left, left, right +231 ¦ return +232 } +233 screen <- move-cursor screen, row, left +234 screen-height:num <- screen-height screen +235 { +236 ¦ at-bottom-of-screen?:bool <- greater-or-equal row, screen-height +237 ¦ break-if at-bottom-of-screen? +238 ¦ screen <- move-cursor screen, row, left +239 ¦ clear-line-until screen, right +240 ¦ row <- add row, 1 +241 ¦ loop +242 } +243 ] +244 +245 scenario editor-prints-multiple-lines [ +246 local-scope +247 assume-screen 5/width, 5/height +248 s:text <- new [abc +249 def] +250 e:&:editor <- new-editor s, 0/left, 5/right +251 run [ +252 ¦ render screen, e +253 ] +254 screen-should-contain [ +255 ¦ . . +256 ¦ .abc . +257 ¦ .def . +258 ¦ . . +259 ] +260 ] +261 +262 scenario editor-handles-offsets [ +263 local-scope +264 assume-screen 5/width, 5/height +265 e:&:editor <- new-editor [abc], 1/left, 5/right +266 run [ +267 ¦ render screen, e +268 ] +269 screen-should-contain [ +270 ¦ . . +271 ¦ . abc . +272 ¦ . . +273 ] +274 ] +275 +276 scenario editor-prints-multiple-lines-at-offset [ +277 local-scope +278 assume-screen 5/width, 5/height +279 s:text <- new [abc +280 def] +281 e:&:editor <- new-editor s, 1/left, 5/right +282 run [ +283 ¦ render screen, e +284 ] +285 screen-should-contain [ +286 ¦ . . +287 ¦ . abc . +288 ¦ . def . +289 ¦ . . +290 ] +291 ] +292 +293 scenario editor-wraps-long-lines [ +294 local-scope +295 assume-screen 5/width, 5/height +296 e:&:editor <- new-editor [abc def], 0/left, 5/right +297 run [ +298 ¦ render screen, e +299 ] +300 screen-should-contain [ +301 ¦ . . +302 ¦ .abc ↩. +303 ¦ .def . +304 ¦ . . +305 ] +306 screen-should-contain-in-color 245/grey [ +307 ¦ . . +308 ¦ . ↩. 309 ¦ . . -310 ] -311 ] -312 -313 scenario editor-wraps-barely-long-lines [ -314 local-scope -315 assume-screen 5/width, 5/height -316 e:&:editor <- new-editor [abcde], 0/left, 5/right -317 run [ -318 ¦ render screen, e -319 ] -320 # still wrap, even though the line would fit. We need room to click on the -321 # end of the line -322 screen-should-contain [ -323 ¦ . . -324 ¦ .abcd↩. -325 ¦ .e . -326 ¦ . . -327 ] -328 screen-should-contain-in-color 245/grey [ -329 ¦ . . -330 ¦ . ↩. -331 ¦ . . +310 ¦ . . +311 ] +312 ] +313 +314 scenario editor-wraps-barely-long-lines [ +315 local-scope +316 assume-screen 5/width, 5/height +317 e:&:editor <- new-editor [abcde], 0/left, 5/right +318 run [ +319 ¦ render screen, e +320 ] +321 # still wrap, even though the line would fit. We need room to click on the +322 # end of the line +323 screen-should-contain [ +324 ¦ . . +325 ¦ .abcd↩. +326 ¦ .e . +327 ¦ . . +328 ] +329 screen-should-contain-in-color 245/grey [ +330 ¦ . . +331 ¦ . ↩. 332 ¦ . . -333 ] -334 ] -335 -336 scenario editor-with-empty-text [ -337 local-scope -338 assume-screen 5/width, 5/height -339 e:&:editor <- new-editor [], 0/left, 5/right -340 run [ -341 ¦ render screen, e -342 ¦ 3:num/raw <- get *e, cursor-row:offset -343 ¦ 4:num/raw <- get *e, cursor-column:offset -344 ] -345 screen-should-contain [ -346 ¦ . . +333 ¦ . . +334 ] +335 ] +336 +337 scenario editor-with-empty-text [ +338 local-scope +339 assume-screen 5/width, 5/height +340 e:&:editor <- new-editor [], 0/left, 5/right +341 run [ +342 ¦ render screen, e +343 ¦ 3:num/raw <- get *e, cursor-row:offset +344 ¦ 4:num/raw <- get *e, cursor-column:offset +345 ] +346 screen-should-contain [ 347 ¦ . . 348 ¦ . . -349 ] -350 memory-should-contain [ -351 ¦ 3 <- 1 # cursor row -352 ¦ 4 <- 0 # cursor column -353 ] -354 ] -355 -356 # just a little color for Mu code -357 -358 scenario render-colors-comments [ -359 local-scope -360 assume-screen 5/width, 5/height -361 s:text <- new [abc -362 # de -363 f] -364 e:&:editor <- new-editor s, 0/left, 5/right -365 run [ -366 ¦ render screen, e -367 ] -368 screen-should-contain [ -369 ¦ . . -370 ¦ .abc . -371 ¦ .# de . -372 ¦ .f . -373 ¦ . . -374 ] -375 screen-should-contain-in-color 12/lightblue, [ -376 ¦ . . +349 ¦ . . +350 ] +351 memory-should-contain [ +352 ¦ 3 <- 1 # cursor row +353 ¦ 4 <- 0 # cursor column +354 ] +355 ] +356 +357 # just a little color for Mu code +358 +359 scenario render-colors-comments [ +360 local-scope +361 assume-screen 5/width, 5/height +362 s:text <- new [abc +363 # de +364 f] +365 e:&:editor <- new-editor s, 0/left, 5/right +366 run [ +367 ¦ render screen, e +368 ] +369 screen-should-contain [ +370 ¦ . . +371 ¦ .abc . +372 ¦ .# de . +373 ¦ .f . +374 ¦ . . +375 ] +376 screen-should-contain-in-color 12/lightblue, [ 377 ¦ . . -378 ¦ .# de . -379 ¦ . . +378 ¦ . . +379 ¦ .# de . 380 ¦ . . -381 ] -382 screen-should-contain-in-color 7/white, [ -383 ¦ . . -384 ¦ .abc . -385 ¦ . . -386 ¦ .f . -387 ¦ . . -388 ] -389 ] -390 -391 after <character-c-received> [ -392 color <- get-color color, c -393 ] -394 -395 # so far the previous color is all the information we need; that may change -396 def get-color color:num, c:char -> color:num [ -397 local-scope -398 load-ingredients -399 color-is-white?:bool <- equal color, 7/white -400 # if color is white and next character is '#', switch color to blue -401 { -402 ¦ break-unless color-is-white? -403 ¦ starting-comment?:bool <- equal c, 35/# -404 ¦ break-unless starting-comment? -405 ¦ trace 90, [app], [switch color back to blue] -406 ¦ return 12/lightblue -407 } -408 # if color is blue and next character is newline, switch color to white -409 { -410 ¦ color-is-blue?:bool <- equal color, 12/lightblue -411 ¦ break-unless color-is-blue? -412 ¦ ending-comment?:bool <- equal c, 10/newline -413 ¦ break-unless ending-comment? -414 ¦ trace 90, [app], [switch color back to white] -415 ¦ return 7/white -416 } -417 # if color is white (no comments) and next character is '<', switch color to red -418 { -419 ¦ break-unless color-is-white? -420 ¦ starting-assignment?:bool <- equal c, 60/< -421 ¦ break-unless starting-assignment? -422 ¦ return 1/red -423 } -424 # if color is red and next character is space, switch color to white -425 { -426 ¦ color-is-red?:bool <- equal color, 1/red -427 ¦ break-unless color-is-red? -428 ¦ ending-assignment?:bool <- equal c, 32/space -429 ¦ break-unless ending-assignment? -430 ¦ return 7/white -431 } -432 # otherwise no change -433 return color -434 ] -435 -436 scenario render-colors-assignment [ -437 local-scope -438 assume-screen 8/width, 5/height -439 s:text <- new [abc -440 d <- e -441 f] -442 e:&:editor <- new-editor s, 0/left, 8/right -443 run [ -444 ¦ render screen, e -445 ] -446 screen-should-contain [ -447 ¦ . . -448 ¦ .abc . -449 ¦ .d <- e . -450 ¦ .f . -451 ¦ . . -452 ] -453 screen-should-contain-in-color 1/red, [ -454 ¦ . . +381 ¦ . . +382 ] +383 screen-should-contain-in-color 7/white, [ +384 ¦ . . +385 ¦ .abc . +386 ¦ . . +387 ¦ .f . +388 ¦ . . +389 ] +390 ] +391 +392 after <character-c-received> [ +393 color <- get-color color, c +394 ] +395 +396 # so far the previous color is all the information we need; that may change +397 def get-color color:num, c:char -> color:num [ +398 local-scope +399 load-ingredients +400 color-is-white?:bool <- equal color, 7/white +401 # if color is white and next character is '#', switch color to blue +402 { +403 ¦ break-unless color-is-white? +404 ¦ starting-comment?:bool <- equal c, 35/# +405 ¦ break-unless starting-comment? +406 ¦ trace 90, [app], [switch color back to blue] +407 ¦ return 12/lightblue +408 } +409 # if color is blue and next character is newline, switch color to white +410 { +411 ¦ color-is-blue?:bool <- equal color, 12/lightblue +412 ¦ break-unless color-is-blue? +413 ¦ ending-comment?:bool <- equal c, 10/newline +414 ¦ break-unless ending-comment? +415 ¦ trace 90, [app], [switch color back to white] +416 ¦ return 7/white +417 } +418 # if color is white (no comments) and next character is '<', switch color to red +419 { +420 ¦ break-unless color-is-white? +421 ¦ starting-assignment?:bool <- equal c, 60/< +422 ¦ break-unless starting-assignment? +423 ¦ return 1/red +424 } +425 # if color is red and next character is space, switch color to white +426 { +427 ¦ color-is-red?:bool <- equal color, 1/red +428 ¦ break-unless color-is-red? +429 ¦ ending-assignment?:bool <- equal c, 32/space +430 ¦ break-unless ending-assignment? +431 ¦ return 7/white +432 } +433 # otherwise no change +434 return color +435 ] +436 +437 scenario render-colors-assignment [ +438 local-scope +439 assume-screen 8/width, 5/height +440 s:text <- new [abc +441 d <- e +442 f] +443 e:&:editor <- new-editor s, 0/left, 8/right +444 run [ +445 ¦ render screen, e +446 ] +447 screen-should-contain [ +448 ¦ . . +449 ¦ .abc . +450 ¦ .d <- e . +451 ¦ .f . +452 ¦ . . +453 ] +454 screen-should-contain-in-color 1/red, [ 455 ¦ . . -456 ¦ . <- . -457 ¦ . . +456 ¦ . . +457 ¦ . <- . 458 ¦ . . -459 ] -460 ] +459 ¦ . . +460 ] +461 ] -- cgit 1.4.1-2-gfad0