about summary refs log tree commit diff stats
path: root/html/edit/002-typing.mu.html
blob: e36c71db9313ca4aaa3e2faf6452a70152c3d546 (generated by cgit-pink 1.4.1-2-gfad0 (git 2.36.2.497.gbbea4dcf42) at 2024-07-13 03:31:55 +0000
5'>215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Mu - edit/002-typing.mu</title>
<meta name="Generator" content="Vim/7.4">
<meta name="plugin-version" content="vim7.4_v1">
<meta name="syntax" content="none">
<meta name="settings" content="use_css,pre_wrap,no_foldcolumn,expand_tabs,prevent_copy=">
<meta name="colorscheme" content="minimal">
<style type="text/css">
<!--
pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; }
body { font-family: monospace; color: #eeeeee; background-color: #080808; }
* { font-size: 1.05em; }
.muControl { color: #c0a020; }
.muRecipe { color: #ff8700; }
.Special { color: #ff6060; }
.muData { color: #ffff00; }
.Comment { color: #9090ff; }
.Constant { color: #00a0a0; }
.SalientComment { color: #00ffff; }
.Delimiter { color: #a04060; }
.muScenario { color: #00af00; }
-->
</style>

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

-->
</script>
</head>
<body>
<pre id='vimCodeElement'>
<span class="SalientComment">## handling events from the keyboard, mouse, touch screen, ...</span>

<span class="Comment"># temporary main: interactive editor</span>
<span class="Comment"># hit ctrl-c to exit</span>
<span class="muRecipe">recipe!</span> main text:address:shared:array:character [
  <span class="Constant">local-scope</span>
  <span class="Constant">load-ingredients</span>
  open-console
  editor:address:shared:editor-data<span class="Special"> &lt;- </span>new-editor text, <span class="Constant">0/screen</span>, <span class="Constant">5/left</span>, <span class="Constant">45/right</span>
  editor-event-loop <span class="Constant">0/screen</span>, <span class="Constant">0/console</span>, editor
  close-console
]

<span class="muRecipe">recipe</span> editor-event-loop screen:address:shared:screen, console:address:shared:console, editor:address:shared:editor-data<span class="muRecipe"> -&gt; </span>screen:address:shared:screen, console:address:shared:console, editor:address:shared:editor-data [
  <span class="Constant">local-scope</span>
  <span class="Constant">load-ingredients</span>
  <span class="Delimiter">{</span>
    <span class="Comment"># looping over each (keyboard or touch) event as it occurs</span>
<span class="Constant">    +next-event</span>
    cursor-row:number<span class="Special"> &lt;- </span>get *editor, <span class="Constant">cursor-row:offset</span>
    cursor-column:number<span class="Special"> &lt;- </span>get *editor, <span class="Constant">cursor-column:offset</span>
    screen<span class="Special"> &lt;- </span>move-cursor screen, cursor-row, cursor-column
    e:event, console:address:shared:console, found?:boolean, quit?:boolean<span class="Special"> &lt;- </span>read-event console
    <span class="muControl">loop-unless</span> found?
    <span class="muControl">break-if</span> quit?  <span class="Comment"># only in tests</span>
    trace <span class="Constant">10</span>, <span class="Constant">[app]</span>, <span class="Constant">[next-event]</span>
    <span class="Comment"># 'touch' event</span>
    t:address:touch-event<span class="Special"> &lt;- </span>maybe-convert e, <span class="Constant">touch:variant</span>
    <span class="Delimiter">{</span>
      <span class="muControl">break-unless</span> t
      move-cursor-in-editor screen, editor, *t
      <span class="muControl">loop</span> <span class="Constant">+next-event:label</span>
    <span class="Delimiter">}</span>
    <span class="Comment"># keyboard events</span>
    <span class="Delimiter">{</span>
      <span class="muControl">break-if</span> t
      screen, editor, go-render?:boolean<span class="Special"> &lt;- </span>handle-keyboard-event screen, editor, e
      <span class="Delimiter">{</span>
        <span class="muControl">break-unless</span> go-render?
        screen<span class="Special"> &lt;- </span>editor-render screen, editor
      <span class="Delimiter">}</span>
    <span class="Delimiter">}</span>
    <span class="muControl">loop</span>
  <span class="Delimiter">}</span>
]

<span class="Comment"># process click, return if it was on current editor</span>
<span class="muRecipe">recipe</span> move-cursor-in-editor screen:address:shared:screen, editor:address:shared:editor-data, t:touch-event<span class="muRecipe"> -&gt; </span>in-focus?:boolean, editor:address:shared:editor-data [
  <span class="Constant">local-scope</span>
  <span class="Constant">load-ingredients</span>
  <span class="muControl">reply-unless</span> editor, <span class="Constant">0/false</span>
  click-row:number<span class="Special"> &lt;- </span>get t, <span class="Constant">row:offset</span>
  <span class="muControl">reply-unless</span> click-row, <span class="Constant">0/false</span>  <span class="Comment"># ignore clicks on 'menu'</span>
  click-column:number<span class="Special"> &lt;- </span>get t, <span class="Constant">column:offset</span>
  left:number<span class="Special"> &lt;- </span>get *editor, <span class="Constant">left:offset</span>
  too-far-left?:boolean<span class="Special"> &lt;- </span>lesser-than click-column, left
  <span class="muControl">reply-if</span> too-far-left?, <span class="Constant">0/false</span>
  right:number<span class="Special"> &lt;- </span>get *editor, <span class="Constant">right:offset</span>
  too-far-right?:boolean<span class="Special"> &lt;- </span>greater-than click-column, right
  <span class="muControl">reply-if</span> too-far-right?, <span class="Constant">0/false</span>
  <span class="Comment"># position cursor</span>
<span class="Constant">  &lt;move-cursor-begin&gt;</span>
  editor<span class="Special"> &lt;- </span>snap-cursor screen, editor, click-row, click-column
  undo-coalesce-tag:number<span class="Special"> &lt;- </span>copy <span class="Constant">0/never</span>
<span class="Constant">  &lt;move-cursor-end&gt;</span>
  <span class="Comment"># gain focus</span>
  <span class="muControl">reply</span> <span class="Constant">1/true</span>
]

<span class="Comment"># Variant of 'render' that only moves the cursor (coordinates and</span>
<span class="Comment"># before-cursor). If it's past the end of a line, it 'slides' it left. If it's</span>
<span class="Comment"># past the last line it positions at end of last line.</span>
<span class="muRecipe">recipe</span> snap-cursor screen:address:shared:screen, editor:address:shared:editor-data, target-row:number, target-column:number<span class="muRecipe"> -&gt; </span>editor:address:shared:editor-data [
  <span class="Constant">local-scope</span>
  <span class="Constant">load-ingredients</span>
  <span class="muControl">reply-unless</span> editor
  left:number<span class="Special"> &lt;- </span>get *editor, <span class="Constant">left:offset</span>
  right:number<span class="Special"> &lt;- </span>get *editor, <span class="Constant">right:offset</span>
  screen-height:number<span class="Special"> &lt;- </span>screen-height screen
  <span class="Comment"># count newlines until screen row</span>
  curr:address:shared:duplex-list:character<span class="Special"> &lt;- </span>get *editor, <span class="Constant">top-of-screen:offset</span>
  prev:address:shared:duplex-list:character<span class="Special"> &lt;- </span>copy curr  <span class="Comment"># just in case curr becomes null and we can't compute prev</span>
  curr<span class="Special"> &lt;- </span>next curr
  row:number<span class="Special"> &lt;- </span>copy <span class="Constant">1/top</span>
  column:number<span class="Special"> &lt;- </span>copy left
  cursor-row:address:number<span class="Special"> &lt;- </span>get-address *editor, <span class="Constant">cursor-row:offset</span>
  *cursor-row<span class="Special"> &lt;- </span>copy target-row
  cursor-column:address:number<span class="Special"> &lt;- </span>get-address *editor, <span class="Constant">cursor-column:offset</span>
  *cursor-column<span class="Special"> &lt;- </span>copy target-column
  before-cursor:address:address:shared:duplex-list:character<span class="Special"> &lt;- </span>get-address *editor, <span class="Constant">before-cursor:offset</span>
  <span class="Delimiter">{</span>
<span class="Constant">    +next-character</span>
    <span class="muControl">break-unless</span> curr
    off-screen?:boolean<span class="Special"> &lt;- </span>greater-or-equal row, screen-height
    <span class="muControl">break-if</span> off-screen?
    <span class="Comment"># update editor-data.before-cursor</span>
    <span class="Comment"># Doing so at the start of each iteration ensures it stays one step behind</span>
    <span class="Comment"># the current character.</span>
    <span class="Delimiter">{</span>
      at-cursor-row?:boolean<span class="Special"> &lt;- </span>equal row, *cursor-row
      <span class="muControl">break-unless</span> at-cursor-row?
      at-cursor?:boolean<span class="Special"> &lt;- </span>equal column, *cursor-column
      <span class="muControl">break-unless</span> at-cursor?
      *before-cursor<span class="Special"> &lt;- </span>copy prev
    <span class="Delimiter">}</span>
    c:character<span class="Special"> &lt;- </span>get *curr, <span class="Constant">value:offset</span>
    <span class="Delimiter">{</span>
      <span class="Comment"># newline? move to left rather than 0</span>
      newline?:boolean<span class="Special"> &lt;- </span>equal c, <span class="Constant">10/newline</span>
      <span class="muControl">break-unless</span> newline?
      <span class="Comment"># adjust cursor if necessary</span>
      <span class="Delimiter">{</span>
        at-cursor-row?:boolean<span class="Special"> &lt;- </span>equal row, *cursor-row
        <span class="muControl">break-unless</span> at-cursor-row?
        left-of-cursor?:boolean<span class="Special"> &lt;- </span>lesser-than column, *cursor-column
        <span class="muControl">break-unless</span> left-of-cursor?
        *cursor-column<span class="Special"> &lt;- </span>copy column
        *before-cursor<span class="Special"> &lt;- </span>copy prev
      <span class="Delimiter">}</span>
      <span class="Comment"># skip to next line</span>
      row<span class="Special"> &lt;- </span>add row, <span class="Constant">1</span>
      column<span class="Special"> &lt;- </span>copy left
      curr<span class="Special"> &lt;- </span>next curr
      prev<span class="Special"> &lt;- </span>next prev
      <span class="muControl">loop</span> <span class="Constant">+next-character:label</span>
    <span class="Delimiter">}</span>
    <span class="Delimiter">{</span>
      <span class="Comment"># at right? wrap. even if there's only one more letter left; we need</span>
      <span class="Comment"># room for clicking on the cursor after it.</span>
      at-right?:boolean<span class="Special"> &lt;- </span>equal column, right
      <span class="muControl">break-unless</span> at-right?
      column<span class="Special"> &lt;- </span>copy left
      row<span class="Special"> &lt;- </span>add row, <span class="Constant">1</span>
      <span class="Comment"># don't increment curr/prev</span>
      <span class="muControl">loop</span> <span class="Constant">+next-character:label</span>
    <span class="Delimiter">}</span>
    curr<span class="Special"> &lt;- </span>next curr
    prev<span class="Special"> &lt;- </span>next prev
    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"># is cursor to the right of the last line? move to end</span>
  <span class="Delimiter">{</span>
    at-cursor-row?:boolean<span class="Special"> &lt;- </span>equal row, *cursor-row
    cursor-outside-line?:boolean<span class="Special"> &lt;- </span>lesser-or-equal column, *cursor-column
    before-cursor-on-same-line?:boolean<span class="Special"> &lt;- </span>and at-cursor-row?, cursor-outside-line?
    above-cursor-row?:boolean<span class="Special"> &lt;- </span>lesser-than row, *cursor-row
    before-cursor?:boolean<span class="Special"> &lt;- </span>or before-cursor-on-same-line?, above-cursor-row?
    <span class="muControl">break-unless</span> before-cursor?
    *cursor-row<span class="Special"> &lt;- </span>copy row
    *cursor-column<span class="Special"> &lt;- </span>copy column
    *before-cursor<span class="Special"> &lt;- </span>copy prev
  <span class="Delimiter">}</span>
]

<span class="Comment"># Process an event 'e' and try to minimally update the screen.</span>
<span class="Comment"># Set 'go-render?' to true to indicate the caller must perform a non-minimal update.</span>
<span class="muRecipe">recipe</span> handle-keyboard-event screen:address:shared:screen, editor:address:shared:editor-data, e:event<span class="muRecipe"> -&gt; </span>screen:address:shared:screen, editor:address:shared:editor-data, go-render?:boolean [
  <span class="Constant">local-scope</span>
  <span class="Constant">load-ingredients</span>
  go-render?<span class="Special"> &lt;- </span>copy <span class="Constant">0/false</span>
  <span class="muControl">reply-unless</span> editor
  screen-width:number<span class="Special"> &lt;- </span>screen-width screen
  screen-height:number<span class="Special"> &lt;- </span>screen-height screen
  left:number<span class="Special"> &lt;- </span>get *editor, <span class="Constant">left:offset</span>
  right:number<span class="Special"> &lt;- </span>get *editor, <span class="Constant">right:offset</span>
  before-cursor:address:address:shared:duplex-list:character<span class="Special"> &lt;- </span>get-address *editor, <span class="Constant">before-cursor:offset</span>
  cursor-row:address:number<span class="Special"> &lt;- </span>get-address *editor, <span class="Constant">cursor-row:offset</span>
  cursor-column:address:number<span class="Special"> &lt;- </span>get-address *editor, <span class="Constant">cursor-column:offset</span>
  save-row:number<span class="Special"> &lt;- </span>copy *cursor-row
  save-column:number<span class="Special"> &lt;- </span>copy *cursor-column
  <span class="Comment"># character</span>
  <span class="Delimiter">{</span>
    c:address:character<span class="Special"> &lt;- </span>maybe-convert e, <span class="Constant">text:variant</span>
    <span class="muControl">break-unless</span> c
    trace <span class="Constant">10</span>, <span class="Constant">[app]</span>, <span class="Constant">[handle-keyboard-event: special character]</span>
    <span class="Comment"># exceptions for special characters go here</span>
<span class="Constant">    &lt;handle-special-character&gt;</span>
    <span class="Comment"># ignore any other special characters</span>
    regular-character?:boolean<span class="Special"> &lt;- </span>greater-or-equal *c, <span class="Constant">32/space</span>
    go-render?<span class="Special"> &lt;- </span>copy <span class="Constant">0/false</span>
    <span class="muControl">reply-unless</span> regular-character?
    <span class="Comment"># otherwise type it in</span>
<span class="Constant">    &lt;insert-character-begin&gt;</span>
    editor, screen, go-render?:boolean<span class="Special"> &lt;- </span>insert-at-cursor editor, *c, screen
<span class="Constant">    &lt;insert-character-end&gt;</span>
    <span class="muControl">reply</span>
  <span class="Delimiter">}</span>
  <span class="Comment"># special key to modify the text or move the cursor</span>
  k:address:number<span class="Special"> &lt;- </span>maybe-convert e:event, <span class="Constant">keycode:variant</span>
  assert k, <span class="Constant">[event was of unknown type; neither keyboard nor mouse]</span>
  <span class="Comment"># handlers for each special key will go here</span>
<span class="Constant">  &lt;handle-special-key&gt;</span>
  go-render?<span class="Special"> &lt;- </span>copy <span class="Constant">1/true</span>
  <span class="muControl">reply</span>
]

<span class="muRecipe">recipe</span> insert-at-cursor editor:address:shared:editor-data, c:character, screen:address:shared:screen<span class="muRecipe"> -&gt; </span>editor:address:shared:editor-data, screen:address:shared:screen, go-render?:boolean [
  <span class="Constant">local-scope</span>
  <span class="Constant">load-ingredients</span>
  before-cursor:address:address:shared:duplex-list:character<span class="Special"> &lt;- </span>get-address *editor, <span class="Constant">before-cursor:offset</span>
  insert c, *before-cursor
  *before-cursor<span class="Special"> &lt;- </span>next *before-cursor
  cursor-row:address:number<span class="Special"> &lt;- </span>get-address *editor, <span class="Constant">cursor-row:offset</span>
  cursor-column:address:number<span class="Special"> &lt;- </span>get-address *editor, <span class="Constant">cursor-column:offset</span>
  left:number<span class="Special"> &lt;- </span>get *editor, <span class="Constant">left:offset</span>
  right:number<span class="Special"> &lt;- </span>get *editor, <span class="Constant">right:offset</span>
  save-row:number<span class="Special"> &lt;- </span>copy *cursor-row
  save-column:number<span class="Special"> &lt;- </span>copy *cursor-column
  screen-width:number<span class="Special"> &lt;- </span>screen-width screen
  screen-height:number<span class="Special"> &lt;- </span>screen-height screen
  <span class="Comment"># occasionally we'll need to mess with the cursor</span>
<span class="Constant">  &lt;insert-character-special-case&gt;</span>
  <span class="Comment"># but mostly we'll just move the cursor right</span>
  *cursor-column<span class="Special"> &lt;- </span>add *cursor-column, <span class="Constant">1</span>
  next:address:shared:duplex-list:character<span class="Special"> &lt;- </span>next *before-cursor
  <span class="Delimiter">{</span>
    <span class="Comment"># at end of all text? no need to scroll? just print the character and leave</span>
    at-end?:boolean<span class="Special"> &lt;- </span>equal next, <span class="Constant">0/null</span>
    <span class="muControl">break-unless</span> at-end?
    bottom:number<span class="Special"> &lt;- </span>subtract screen-height, <span class="Constant">1</span>
    at-bottom?:boolean<span class="Special"> &lt;- </span>equal save-row, bottom
    at-right?:boolean<span class="Special"> &lt;- </span>equal save-column, right
    overflow?:boolean<span class="Special"> &lt;- </span>and at-bottom?, at-right?
    <span class="muControl">break-if</span> overflow?
    move-cursor screen, save-row, save-column
    print screen, c
    go-render?<span class="Special"> &lt;- </span>copy <span class="Constant">0/false</span>
    <span class="muControl">reply</span>
  <span class="Delimiter">}</span>
  <span class="Delimiter">{</span>
    <span class="Comment"># not at right margin? print the character and rest of line</span>
    <span class="muControl">break-unless</span> next
    at-right?:boolean<span class="Special"> &lt;- </span>greater-or-equal *cursor-column, screen-width
    <span class="muControl">break-if</span> at-right?
    curr:address:shared:duplex-list:character<span class="Special"> &lt;- </span>copy *before-cursor
    move-cursor screen, save-row, save-column
    curr-column:number<span class="Special"> &lt;- </span>copy save-column
    <span class="Delimiter">{</span>
      <span class="Comment"># hit right margin? give up and let caller render</span>
      go-render?<span class="Special"> &lt;- </span>copy <span class="Constant">1/true</span>
      at-right?:boolean<span class="Special"> &lt;- </span>greater-than curr-column, right
      <span class="muControl">reply-if</span> at-right?
      <span class="muControl">break-unless</span> curr
      <span class="Comment"># newline? done.</span>
      currc:character<span class="Special"> &lt;- </span>get *curr, <span class="Constant">value:offset</span>
      at-newline?:boolean<span class="Special"> &lt;- </span>equal currc, <span class="Constant">10/newline</span>
      <span class="muControl">break-if</span> at-newline?
      print screen, currc
      curr-column<span class="Special"> &lt;- </span>add curr-column, <span class="Constant">1</span>
      curr<span class="Special"> &lt;- </span>next curr
      <span class="muControl">loop</span>
    <span class="Delimiter">}</span>
    go-render?<span class="Special"> &lt;- </span>copy <span class="Constant">0/false</span>
    <span class="muControl">reply</span>
  <span class="Delimiter">}</span>
  go-render?<span class="Special"> &lt;- </span>copy <span class="Constant">1/true</span>
  <span class="muControl">reply</span>
]

<span class="Comment"># helper for tests</span>
<span class="muRecipe">recipe</span> editor-render screen:address:shared:screen, editor:address:shared:editor-data<span class="muRecipe"> -&gt; </span>screen:address:shared:screen, editor:address:shared:editor-data [
  <span class="Constant">local-scope</span>
  <span class="Constant">load-ingredients</span>
  left:number<span class="Special"> &lt;- </span>get *editor, <span class="Constant">left:offset</span>
  right:number<span class="Special"> &lt;- </span>get *editor, <span class="Constant">right:offset</span>
  row:number, column:number<span class="Special"> &lt;- </span>render screen, editor
  clear-line-delimited screen, column, right
  row<span class="Special"> &lt;- </span>add row, <span class="Constant">1</span>
  draw-horizontal screen, row, left, right, <span class="Constant">9480/horizontal-dotted</span>
  row<span class="Special"> &lt;- </span>add row, <span class="Constant">1</span>
  clear-screen-from screen, row, left, left, right
]

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

<span class="muScenario">scenario</span> editor-handles-mouse-clicks [
  assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
  <span class="Constant">1</span>:address:shared:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[abc]</span>
  <span class="Constant">2</span>:address:shared:editor-data<span class="Special"> &lt;- </span>new-editor <span class="Constant">1</span>:address:shared:array:character, screen:address:shared:screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span>
  editor-render screen, <span class="Constant">2</span>:address:shared:editor-data
<span class="Constant">  $clear-trace</span>
  assume-console [
    left-click <span class="Constant">1</span>, <span class="Constant">1</span>  <span class="Comment"># on the 'b'</span>
  ]
  run [
    editor-event-loop screen:address:shared:screen, console:address:shared:console, <span class="Constant">2</span>:address:shared:editor-data
    <span class="Constant">3</span>:number<span class="Special"> &lt;- </span>get *<span class="Constant">2</span>:address:shared:editor-data, <span class="Constant">cursor-row:offset</span>
    <span class="Constant">4</span>:number<span class="Special"> &lt;- </span>get *<span class="Constant">2</span>:address:shared:editor-data, <span class="Constant">cursor-column:offset</span>
  ]
  screen-should-contain [
   <span class="Constant"> .          .</span>
   <span class="Constant"> .abc       .</span>
<span class="Constant">    .┈┈┈┈┈┈┈┈┈┈.</span>
   <span class="Constant"> .          .</span>
  ]
  memory-should-contain [
    <span class="Constant">3</span><span class="Special"> &lt;- </span><span class="Constant">1</span>  <span class="Comment"># cursor is at row 0..</span>
    <span class="Constant">4</span><span class="Special"> &lt;- </span><span class="Constant">1</span>  <span class="Comment"># ..and column 1</span>
  ]
  check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span>
]

<span class="muScenario">scenario</span> editor-handles-mouse-clicks-outside-text [
  assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
  <span class="Constant">1</span>:address:shared:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[abc]</span>
  <span class="Constant">2</span>:address:shared:editor-data<span class="Special"> &lt;- </span>new-editor <span class="Constant">1</span>:address:shared:array:character, screen:address:shared:screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span>
<span class="Constant">  $clear-trace</span>
  assume-console [
    left-click <span class="Constant">1</span>, <span class="Constant">7</span>  <span class="Comment"># last line, to the right of text</span>
  ]
  run [
    editor-event-loop screen:address:shared:screen, console:address:shared:console, <span class="Constant">2</span>:address:shared:editor-data
    <span class="Constant">3</span>:number<span class="Special"> &lt;- </span>get *<span class="Constant">2</span>:address:shared:editor-data, <span class="Constant">cursor-row:offset</span>
    <span class="Constant">4</span>:number<span class="Special"> &lt;- </span>get *<span class="Constant">2</span>:address:shared:editor-data, <span class="Constant">cursor-column:offset</span>
  ]
  memory-should-contain [
    <span class="Constant">3</span><span class="Special"> &lt;- </span><span class="Constant">1</span>  <span class="Comment"># cursor row</span>
    <span class="Constant">4</span><span class="Special"> &lt;- </span><span class="Constant">3</span>  <span class="Comment"># cursor column</span>
  ]
  check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span>
]

<span class="muScenario">scenario</span> editor-handles-mouse-clicks-outside-text-2 [
  assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
  <span class="Constant">1</span>:address:shared:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[abc</span>
<span class="Constant">def]</span>
  <span class="Constant">2</span>:address:shared:editor-data<span class="Special"> &lt;- </span>new-editor <span class="Constant">1</span>:address:shared:array:character, screen:address:shared:screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span>
<span class="Constant">  $clear-trace</span>
  assume-console [
    left-click <span class="Constant">1</span>, <span class="Constant">7</span>  <span class="Comment"># interior line, to the right of text</span>
  ]
  run [
    editor-event-loop screen:address:shared:screen, console:address:shared:console, <span class="Constant">2</span>:address:shared:editor-data
    <span class="Constant">3</span>:number<span class="Special"> &lt;- </span>get *<span class="Constant">2</span>:address:shared:editor-data, <span class="Constant">cursor-row:offset</span>
    <span class="Constant">4</span>:number<span class="Special"> &lt;- </span>get *<span class="Constant">2</span>:address:shared:editor-data, <span class="Constant">cursor-column:offset</span>
  ]
  memory-should-contain [
    <span class="Constant">3</span><span class="Special"> &lt;- </span><span class="Constant">1</span>  <span class="Comment"># cursor row</span>
    <span class="Constant">4</span><span class="Special"> &lt;- </span><span class="Constant">3</span>  <span class="Comment"># cursor column</span>
  ]
  check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span>
]

<span class="muScenario">scenario</span> editor-handles-mouse-clicks-outside-text-3 [
  assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
  <span class="Constant">1</span>:address:shared:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[abc</span>
<span class="Constant">def]</span>
  <span class="Constant">2</span>:address:shared:editor-data<span class="Special"> &lt;- </span>new-editor <span class="Constant">1</span>:address:shared:array:character, screen:address:shared:screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span>
<span class="Constant">  $clear-trace</span>
  assume-console [
    left-click <span class="Constant">3</span>, <span class="Constant">7</span>  <span class="Comment"># below text</span>
  ]
  run [
    editor-event-loop screen:address:shared:screen, console:address:shared:console, <span class="Constant">2</span>:address:shared:editor-data
    <span class="Constant">3</span>:number<span class="Special"> &lt;- </span>get *<span class="Constant">2</span>:address:shared:editor-data, <span class="Constant">cursor-row:offset</span>
    <span class="Constant">4</span>:number<span class="Special"> &lt;- </span>get *<span class="Constant">2</span>:address:shared:editor-data, <span class="Constant">cursor-column:offset</span>
  ]
  memory-should-contain [
    <span class="Constant">3</span><span class="Special"> &lt;- </span><span class="Constant">2</span>  <span class="Comment"># cursor row</span>
    <span class="Constant">4</span><span class="Special"> &lt;- </span><span class="Constant">3</span>  <span class="Comment"># cursor column</span>
  ]
  check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span>
]

<span class="muScenario">scenario</span> editor-handles-mouse-clicks-outside-column [
  assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
  <span class="Constant">1</span>:address:shared:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[abc]</span>
  <span class="Comment"># editor occupies only left half of screen</span>
  <span class="Constant">2</span>:address:shared:editor-data<span class="Special"> &lt;- </span>new-editor <span class="Constant">1</span>:address:shared:array:character, screen:address:shared:screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span>
  editor-render screen, <span class="Constant">2</span>:address:shared:editor-data
<span class="Constant">  $clear-trace</span>
  assume-console [
    <span class="Comment"># click on right half of screen</span>
    left-click <span class="Constant">3</span>, <span class="Constant">8</span>
  ]
  run [
    editor-event-loop screen:address:shared:screen, console:address:shared:console, <span class="Constant">2</span>:address:shared:editor-data
    <span class="Constant">3</span>:number<span class="Special"> &lt;- </span>get *<span class="Constant">2</span>:address:shared:editor-data, <span class="Constant">cursor-row:offset</span>
    <span class="Constant">4</span>:number<span class="Special"> &lt;- </span>get *<span class="Constant">2</span>:address:shared:editor-data, <span class="Constant">cursor-column:offset</span>
  ]
  screen-should-contain [
   <span class="Constant"> .          .</span>
   <span class="Constant"> .abc       .</span>
   <span class="Constant"> .┈┈┈┈┈     .</span>
   <span class="Constant"> .          .</span>
  ]
  memory-should-contain [
    <span class="Constant">3</span><span class="Special"> &lt;- </span><span class="Constant">1</span>  <span class="Comment"># no change to cursor row</span>
    <span class="Constant">4</span><span class="Special"> &lt;- </span><span class="Constant">0</span>  <span class="Comment"># ..or column</span>
  ]
  check-trace-count-for-label <span class="Constant">0</span>, <span class="Constant">[print-character]</span>
]

<span class="muScenario">scenario</span> editor-handles-mouse-clicks-in-menu-area [
  assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
  <span class="Constant">1</span>:address:shared:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[abc]</span>
  <span class="Constant">2</span>:address:shared:editor-data<span class="Special"> &lt;- </span>new-editor <span class="Constant">1</span>:address:shared:array:character, screen:address:shared:screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span>
  editor-render screen, <span class="Constant">2</span>:address:shared:editor-data
<span class="Constant">  $clear-trace</span>
  assume-console [
    <span class="Comment"># click on first, 'menu' row</span>
    left-click <span class="Constant">0</span>, <span class="Constant">3</span>
  ]
  run [
    editor-event-loop screen:address:shared:screen, console:address:shared:console, <span class="Constant">2</span>:address:shared:editor-data
    <span class="Constant">3</span>:number<span class="Special"> &lt;- </span>get *<span class="Constant">2</span>:address:shared:editor-data, <span class="Constant">cursor-row:offset</span>
    <span class="Constant">4</span>:number<span class="Special"> &lt;- </span>get *<span class="Constant">2</span>:address:shared:editor-data, <span class="Constant">cursor-column:offset</span>
  ]
  <span class="Comment"># no change to cursor</span>
  memory-should-contain [
    <span class="Constant">3</span><span class="Special"> &lt;- </span><span class="Constant">1</span>
    <span class="Constant">4</span><span class="Special"> &lt;- </span><span class="Constant">0</span>
  ]
]

<span class="muScenario">scenario</span> editor-inserts-characters-into-empty-editor [
  assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
  <span class="Constant">1</span>:address:shared:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[]</span>
  <span class="Constant">2</span>:address:shared:editor-data<span class="Special"> &lt;- </span>new-editor <span class="Constant">1</span>:address:shared:array:character, screen:address:shared:screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span>
  editor-render screen, <span class="Constant">2</span>:address:shared:editor-data
<span class="Constant">  $clear-trace</span>
  assume-console [
    type <span class="Constant">[abc]</span>
  ]
  run [
    editor-event-loop screen:address:shared:screen, console:address:shared:console, <span class="Constant">2</span>:address:shared:editor-data
  ]
  screen-should-contain [
   <span class="Constant"> .          .</span>
   <span class="Constant"> .abc       .</span>
   <span class="Constant"> .┈┈┈┈┈     .</span>
   <span class="Constant"> .          .</span>
  ]
  check-trace-count-for-label <span class="Constant">3</span>, <span class="Constant">[print-character]</span>
]

<span class="muScenario">scenario</span> editor-inserts-characters-at-cursor [
  assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
  <span class="Constant">1</span>:address:shared:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[abc]</span>
  <span class="Constant">2</span>:address:shared:editor-data<span class="Special"> &lt;- </span>new-editor <span class="Constant">1</span>:address:shared:array:character, screen:address:shared:screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span>
  editor-render screen, <span class="Constant">2</span>:address:shared:editor-data
<span class="Constant">  $clear-trace</span>
  <span class="Comment"># type two letters at different places</span>
  assume-console [
    type <span class="Constant">[0]</span>
    left-click <span class="Constant">1</span>, <span class="Constant">2</span>
    type <span class="Constant">[d]</span>
  ]
  run [
    editor-event-loop screen:address:shared:screen, console:address:shared:console, <span class="Constant">2</span>:address:shared:editor-data
  ]
  screen-should-contain [
   <span class="Constant"> .          .</span>
   <span class="Constant"> .0adbc     .</span>
<span class="Constant">    .┈┈┈┈┈┈┈┈┈┈.</span>
   <span class="Constant"> .          .</span>
  ]
  check-trace-count-for-label <span class="Constant">7</span>, <span class="Constant">[print-character]</span>  <span class="Comment"># 4 for first letter, 3 for second</span>
]

<span class="muScenario">scenario</span> editor-inserts-characters-at-cursor-2 [
  assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
  <span class="Constant">1</span>:address:shared:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[abc]</span>
  <span class="Constant">2</span>:address:shared:editor-data<span class="Special"> &lt;- </span>new-editor <span class="Constant">1</span>:address:shared:array:character, screen:address:shared:screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span>
  editor-render screen, <span class="Constant">2</span>:address:shared:editor-data
<span class="Constant">  $clear-trace</span>
  assume-console [
    left-click <span class="Constant">1</span>, <span class="Constant">5</span>  <span class="Comment"># right of last line</span>
    type <span class="Constant">[d]</span>
  ]
  run [
    editor-event-loop screen:address:shared:screen, console:address:shared:console, <span class="Constant">2</span>:address:shared:editor-data
  ]
  screen-should-contain [
   <span class="Constant"> .          .</span>
   <span class="Constant"> .abcd      .</span>
<span class="Constant">    .┈┈┈┈┈┈┈┈┈┈.</span>
   <span class="Constant"> .          .</span>
  ]
  check-trace-count-for-label <span class="Constant">1</span>, <span class="Constant">[print-character]</span>
]

<span class="muScenario">scenario</span> editor-inserts-characters-at-cursor-5 [
  assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
  <span class="Constant">1</span>:address:shared:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[abc</span>
<span class="Constant">d]</span>
  <span class="Constant">2</span>:address:shared:editor-data<span class="Special"> &lt;- </span>new-editor <span class="Constant">1</span>:address:shared:array:character, screen:address:shared:screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span>
  editor-render screen, <span class="Constant">2</span>:address:shared:editor-data
<span class="Constant">  $clear-trace</span>
  assume-console [
    left-click <span class="Constant">1</span>, <span class="Constant">5</span>  <span class="Comment"># right of non-last line</span>
    type <span class="Constant">[e]</span>
  ]
  run [
    editor-event-loop screen:address:shared:screen, console:address:shared:console, <span class="Constant">2</span>:address:shared:editor-data
  ]
  screen-should-contain [
   <span class="Constant"> .          .</span>
   <span class="Constant"> .abce      .</span>
   <span class="Constant"> .d         .</span>
<span class="Constant">    .┈┈┈┈┈┈┈┈┈┈.</span>
   <span class="Constant"> .          .</span>
  ]
  check-trace-count-for-label <span class="Constant">1</span>, <span class="Constant">[print-character]</span>
]

<span class="muScenario">scenario</span> editor-inserts-characters-at-cursor-3 [
  assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
  <span class="Constant">1</span>:address:shared:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[abc]</span>
  <span class="Constant">2</span>:address:shared:editor-data<span class="Special"> &lt;- </span>new-editor <span class="Constant">1</span>:address:shared:array:character, screen:address:shared:screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span>
  editor-render screen, <span class="Constant">2</span>:address:shared:editor-data
<span class="Constant">  $clear-trace</span>
  assume-console [
    left-click <span class="Constant">3</span>, <span class="Constant">5</span>  <span class="Comment"># below all text</span>
    type <span class="Constant">[d]</span>
  ]
  run [
    editor-event-loop screen:address:shared:screen, console:address:shared:console, <span class="Constant">2</span>:address:shared:editor-data
  ]
  screen-should-contain [
   <span class="Constant"> .          .</span>
   <span class="Constant"> .abcd      .</span>
<span class="Constant">    .┈┈┈┈┈┈┈┈┈┈.</span>
   <span class="Constant"> .          .</span>
  ]
  check-trace-count-for-label <span class="Constant">1</span>, <span class="Constant">[print-character]</span>
]

<span class="muScenario">scenario</span> editor-inserts-characters-at-cursor-4 [
  assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
  <span class="Constant">1</span>:address:shared:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[abc</span>
<span class="Constant">d]</span>
  <span class="Constant">2</span>:address:shared:editor-data<span class="Special"> &lt;- </span>new-editor <span class="Constant">1</span>:address:shared:array:character, screen:address:shared:screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span>
  editor-render screen, <span class="Constant">2</span>:address:shared:editor-data
<span class="Constant">  $clear-trace</span>
  assume-console [
    left-click <span class="Constant">3</span>, <span class="Constant">5</span>  <span class="Comment"># below all text</span>
    type <span class="Constant">[e]</span>
  ]
  run [
    editor-event-loop screen:address:shared:screen, console:address:shared:console, <span class="Constant">2</span>:address:shared:editor-data
  ]
  screen-should-contain [
   <span class="Constant"> .          .</span>
   <span class="Constant"> .abc       .</span>
   <span class="Constant"> .de        .</span>
<span class="Constant">    .┈┈┈┈┈┈┈┈┈┈.</span>
   <span class="Constant"> .          .</span>
  ]
  check-trace-count-for-label <span class="Constant">1</span>, <span class="Constant">[print-character]</span>
]

<span class="muScenario">scenario</span> editor-inserts-characters-at-cursor-6 [
  assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
  <span class="Constant">1</span>:address:shared:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[abc</span>
<span class="Constant">d]</span>
  <span class="Constant">2</span>:address:shared:editor-data<span class="Special"> &lt;- </span>new-editor <span class="Constant">1</span>:address:shared:array:character, screen:address:shared:screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span>
  editor-render screen, <span class="Constant">2</span>:address:shared:editor-data
<span class="Constant">  $clear-trace</span>
  assume-console [
    left-click <span class="Constant">3</span>, <span class="Constant">5</span>  <span class="Comment"># below all text</span>
    type <span class="Constant">[ef]</span>
  ]
  run [
    editor-event-loop screen:address:shared:screen, console:address:shared:console, <span class="Constant">2</span>:address:shared:editor-data
  ]
  screen-should-contain [
   <span class="Constant"> .          .</span>
   <span class="Constant"> .abc       .</span>
   <span class="Constant"> .def       .</span>
<span class="Constant">    .┈┈┈┈┈┈┈┈┈┈.</span>
   <span class="Constant"> .          .</span>
  ]
  check-trace-count-for-label <span class="Constant">2</span>, <span class="Constant">[print-character]</span>
]

<span class="muScenario">scenario</span> editor-moves-cursor-after-inserting-characters [
  assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
  <span class="Constant">1</span>:address:shared:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[ab]</span>
  <span class="Constant">2</span>:address:shared:editor-data<span class="Special"> &lt;- </span>new-editor <span class="Constant">1</span>:address:shared:array:character, screen:address:shared:screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span>
  editor-render screen, <span class="Constant">2</span>:address:shared:editor-data
  assume-console [
    type <span class="Constant">[01]</span>
  ]
  run [
    editor-event-loop screen:address:shared:screen, console:address:shared:console, <span class="Constant">2</span>:address:shared:editor-data
  ]
  screen-should-contain [
   <span class="Constant"> .          .</span>
   <span class="Constant"> .01ab      .</span>
   <span class="Constant"> .┈┈┈┈┈     .</span>
   <span class="Constant"> .          .</span>
  ]
]

<span class="Comment"># if the cursor reaches the right margin, wrap the line</span>

<span class="muScenario">scenario</span> editor-wraps-line-on-insert [
  assume-screen <span class="Constant">5/width</span>, <span class="Constant">5/height</span>
  <span class="Constant">1</span>:address:shared:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[abc]</span>
  <span class="Constant">2</span>:address:shared:editor-data<span class="Special"> &lt;- </span>new-editor <span class="Constant">1</span>:address:shared:array:character, screen:address:shared:screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span>
  editor-render screen, <span class="Constant">2</span>:address:shared:editor-data
  <span class="Comment"># type a letter</span>
  assume-console [
    type <span class="Constant">[e]</span>
  ]
  run [
    editor-event-loop screen:address:shared:screen, console:address:shared:console, <span class="Constant">2</span>:address:shared:editor-data
  ]
  <span class="Comment"># no wrap yet</span>
  screen-should-contain [
   <span class="Constant"> .     .</span>
   <span class="Constant"> .eabc .</span>
<span class="Constant">    .┈┈┈┈┈.</span>
   <span class="Constant"> .     .</span>
   <span class="Constant"> .     .</span>
  ]
  <span class="Comment"># type a second letter</span>
  assume-console [
    type <span class="Constant">[f]</span>
  ]
  run [
    editor-event-loop screen:address:shared:screen, console:address:shared:console, <span class="Constant">2</span>:address:shared:editor-data
  ]
  <span class="Comment"># now wrap</span>
  screen-should-contain [
   <span class="Constant"> .     .</span>
<span class="Constant">    .efab↩.</span>
   <span class="Constant"> .c    .</span>
<span class="Constant">    .┈┈┈┈┈.</span>
   <span class="Constant"> .     .</span>
  ]
]

<span class="muScenario">scenario</span> editor-wraps-line-on-insert-2 [
  <span class="Comment"># create an editor with some text</span>
  assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
  <span class="Constant">1</span>:address:shared:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[abcdefg</span>
<span class="Constant">defg]</span>
  <span class="Constant">2</span>:address:shared:editor-data<span class="Special"> &lt;- </span>new-editor <span class="Constant">1</span>:address:shared:array:character, screen:address:shared:screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span>
  editor-render screen, <span class="Constant">2</span>:address:shared:editor-data
  <span class="Comment"># type more text at the start</span>
  assume-console [
    left-click <span class="Constant">3</span>, <span class="Constant">0</span>
    type <span class="Constant">[abc]</span>
  ]
  run [
    editor-event-loop screen:address:shared:screen, console:address:shared:console, <span class="Constant">2</span>:address:shared:editor-data
    <span class="Constant">3</span>:number<span class="Special"> &lt;- </span>get *<span class="Constant">2</span>:address:shared:editor-data, <span class="Constant">cursor-row:offset</span>
    <span class="Constant">4</span>:number<span class="Special"> &lt;- </span>get *<span class="Constant">2</span>:address:shared:editor-data, <span class="Constant">cursor-column:offset</span>
  ]
  <span class="Comment"># cursor is not wrapped</span>
  memory-should-contain [
    <span class="Constant">3</span><span class="Special"> &lt;- </span><span class="Constant">3</span>
    <span class="Constant">4</span><span class="Special"> &lt;- </span><span class="Constant">3</span>
  ]
  <span class="Comment"># but line is wrapped</span>
  screen-should-contain [
   <span class="Constant"> .          .</span>
   <span class="Constant"> .abcd↩     .</span>
   <span class="Constant"> .efg       .</span>
   <span class="Constant"> .abcd↩     .</span>
   <span class="Constant"> .efg       .</span>
  ]
]

<span class="muRecipe">after</span> <span class="Constant">&lt;insert-character-special-case&gt;</span> [
  <span class="Comment"># if the line wraps at the cursor, move cursor to start of next row</span>
  <span class="Delimiter">{</span>
    <span class="Comment"># if we're at the column just before the wrap indicator</span>
    wrap-column:number<span class="Special"> &lt;- </span>subtract right, <span class="Constant">1</span>
    at-wrap?:boolean<span class="Special"> &lt;- </span>greater-or-equal *cursor-column, wrap-column
    <span class="muControl">break-unless</span> at-wrap?
    *cursor-column<span class="Special"> &lt;- </span>subtract *cursor-column, wrap-column
    *cursor-column<span class="Special"> &lt;- </span>add *cursor-column, left
    *cursor-row<span class="Special"> &lt;- </span>add *cursor-row, <span class="Constant">1</span>
    <span class="Comment"># if we're out of the screen, scroll down</span>
    <span class="Delimiter">{</span>
      below-screen?:boolean<span class="Special"> &lt;- </span>greater-or-equal *cursor-row, screen-height
      <span class="muControl">break-unless</span> below-screen?
<span class="Constant">      &lt;scroll-down&gt;</span>
    <span class="Delimiter">}</span>
    go-render?<span class="Special"> &lt;- </span>copy <span class="Constant">1/true</span>
    <span class="muControl">reply</span>
  <span class="Delimiter">}</span>
]

<span class="muScenario">scenario</span> editor-wraps-cursor-after-inserting-characters [
  assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
  <span class="Constant">1</span>:address:shared:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[abcde]</span>
  <span class="Constant">2</span>:address:shared:editor-data<span class="Special"> &lt;- </span>new-editor <span class="Constant">1</span>:address:shared:array:character, screen:address:shared:screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span>
  assume-console [
    left-click <span class="Constant">1</span>, <span class="Constant">4</span>  <span class="Comment"># line is full; no wrap icon yet</span>
    type <span class="Constant">[f]</span>
  ]
  run [
    editor-event-loop screen:address:shared:screen, console:address:shared:console, <span class="Constant">2</span>:address:shared:editor-data
    <span class="Constant">3</span>:number<span class="Special"> &lt;- </span>get *<span class="Constant">2</span>:address:shared:editor-data, <span class="Constant">cursor-row:offset</span>
    <span class="Constant">4</span>:number<span class="Special"> &lt;- </span>get *<span class="Constant">2</span>:address:shared:editor-data, <span class="Constant">cursor-column:offset</span>
  ]
  screen-should-contain [
   <span class="Constant"> .          .</span>
   <span class="Constant"> .abcd↩     .</span>
   <span class="Constant"> .fe        .</span>
   <span class="Constant"> .┈┈┈┈┈     .</span>
   <span class="Constant"> .          .</span>
  ]
  memory-should-contain [
    <span class="Constant">3</span><span class="Special"> &lt;- </span><span class="Constant">2</span>  <span class="Comment"># cursor row</span>
    <span class="Constant">4</span><span class="Special"> &lt;- </span><span class="Constant">1</span>  <span class="Comment"># cursor column</span>
  ]
]

<span class="muScenario">scenario</span> editor-wraps-cursor-after-inserting-characters-2 [
  assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
  <span class="Constant">1</span>:address:shared:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[abcde]</span>
  <span class="Constant">2</span>:address:shared:editor-data<span class="Special"> &lt;- </span>new-editor <span class="Constant">1</span>:address:shared:array:character, screen:address:shared:screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span>
  assume-console [
    left-click <span class="Constant">1</span>, <span class="Constant">3</span>  <span class="Comment"># right before the wrap icon</span>
    type <span class="Constant">[f]</span>
  ]
  run [
    editor-event-loop screen:address:shared:screen, console:address:shared:console, <span class="Constant">2</span>:address:shared:editor-data
    <span class="Constant">3</span>:number<span class="Special"> &lt;- </span>get *<span class="Constant">2</span>:address:shared:editor-data, <span class="Constant">cursor-row:offset</span>
    <span class="Constant">4</span>:number<span class="Special"> &lt;- </span>get *<span class="Constant">2</span>:address:shared:editor-data, <span class="Constant">cursor-column:offset</span>
  ]
  screen-should-contain [
   <span class="Constant"> .          .</span>
   <span class="Constant"> .abcf↩     .</span>
   <span class="Constant"> .de        .</span>
   <span class="Constant"> .┈┈┈┈┈     .</span>
   <span class="Constant"> .          .</span>
  ]
  memory-should-contain [
    <span class="Constant">3</span><span class="Special"> &lt;- </span><span class="Constant">2</span>  <span class="Comment"># cursor row</span>
    <span class="Constant">4</span><span class="Special"> &lt;- </span><span class="Constant">0</span>  <span class="Comment"># cursor column</span>
  ]
]

<span class="muScenario">scenario</span> editor-wraps-cursor-to-left-margin [
  assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
  <span class="Constant">1</span>:address:shared:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[abcde]</span>
  <span class="Constant">2</span>:address:shared:editor-data<span class="Special"> &lt;- </span>new-editor <span class="Constant">1</span>:address:shared:array:character, screen:address:shared:screen, <span class="Constant">2/left</span>, <span class="Constant">7/right</span>
  assume-console [
    left-click <span class="Constant">1</span>, <span class="Constant">5</span>  <span class="Comment"># line is full; no wrap icon yet</span>
    type <span class="Constant">[01]</span>
  ]
  run [
    editor-event-loop screen:address:shared:screen, console:address:shared:console, <span class="Constant">2</span>:address:shared:editor-data
    <span class="Constant">3</span>:number<span class="Special"> &lt;- </span>get *<span class="Constant">2</span>:address:shared:editor-data, <span class="Constant">cursor-row:offset</span>
    <span class="Constant">4</span>:number<span class="Special"> &lt;- </span>get *<span class="Constant">2</span>:address:shared:editor-data, <span class="Constant">cursor-column:offset</span>
  ]
  screen-should-contain [
   <span class="Constant"> .          .</span>
   <span class="Constant"> .  abc0↩   .</span>
   <span class="Constant"> .  1de     .</span>
   <span class="Constant"> .  ┈┈┈┈┈   .</span>
   <span class="Constant"> .          .</span>
  ]
  memory-should-contain [
    <span class="Constant">3</span><span class="Special"> &lt;- </span><span class="Constant">2</span>  <span class="Comment"># cursor row</span>
    <span class="Constant">4</span><span class="Special"> &lt;- </span><span class="Constant">3</span>  <span class="Comment"># cursor column</span>
  ]
]

<span class="Comment"># if newline, move cursor to start of next line, and maybe align indent with previous line</span>

<span class="muData">container</span> editor-data [
  indent?:boolean
]

<span class="muRecipe">after</span> <span class="Constant">&lt;editor-initialization&gt;</span> [
  indent?:address:boolean<span class="Special"> &lt;- </span>get-address *result, <span class="Constant">indent?:offset</span>
  *indent?<span class="Special"> &lt;- </span>copy <span class="Constant">1/true</span>
]

<span class="muScenario">scenario</span> editor-moves-cursor-down-after-inserting-newline [
  assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
  <span class="Constant">1</span>:address:shared:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[abc]</span>
  <span class="Constant">2</span>:address:shared:editor-data<span class="Special"> &lt;- </span>new-editor <span class="Constant">1</span>:address:shared:array:character, screen:address:shared:screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span>
  assume-console [
    type <span class="Constant">[0</span>
<span class="Constant">1]</span>
  ]
  run [
    editor-event-loop screen:address:shared:screen, console:address:shared:console, <span class="Constant">2</span>:address:shared:editor-data
  ]
  screen-should-contain [
   <span class="Constant"> .          .</span>
   <span class="Constant"> .0         .</span>
   <span class="Constant"> .1abc      .</span>
<span class="Constant">    .┈┈┈┈┈┈┈┈┈┈.</span>
   <span class="Constant"> .          .</span>
  ]
]

<span class="muRecipe">after</span> <span class="Constant">&lt;handle-special-character&gt;</span> [
  <span class="Delimiter">{</span>
    newline?:boolean<span class="Special"> &lt;- </span>equal *c, <span class="Constant">10/newline</span>
    <span class="muControl">break-unless</span> newline?
<span class="Constant">    &lt;insert-enter-begin&gt;</span>
    editor<span class="Special"> &lt;- </span>insert-new-line-and-indent editor, screen
<span class="Constant">    &lt;insert-enter-end&gt;</span>
    go-render?<span class="Special"> &lt;- </span>copy <span class="Constant">1/true</span>
    <span class="muControl">reply</span>
  <span class="Delimiter">}</span>
]

<span class="muRecipe">recipe</span> insert-new-line-and-indent editor:address:shared:editor-data, screen:address:shared:screen<span class="muRecipe"> -&gt; </span>editor:address:shared:editor-data, screen:address:shared:screen, go-render?:boolean [
  <span class="Constant">local-scope</span>
  <span class="Constant">load-ingredients</span>
  cursor-row:address:number<span class="Special"> &lt;- </span>get-address *editor, <span class="Constant">cursor-row:offset</span>
  cursor-column:address:number<span class="Special"> &lt;- </span>get-address *editor, <span class="Constant">cursor-column:offset</span>
  before-cursor:address:address:shared:duplex-list:character<span class="Special"> &lt;- </span>get-address *editor, <span class="Constant">before-cursor:offset</span>
  left:number<span class="Special"> &lt;- </span>get *editor, <span class="Constant">left:offset</span>
  right:number<span class="Special"> &lt;- </span>get *editor, <span class="Constant">right:offset</span>
  screen-height:number<span class="Special"> &lt;- </span>screen-height screen
  <span class="Comment"># insert newline</span>
  insert <span class="Constant">10/newline</span>, *before-cursor
  *before-cursor<span class="Special"> &lt;- </span>next *before-cursor
  *cursor-row<span class="Special"> &lt;- </span>add *cursor-row, <span class="Constant">1</span>
  *cursor-column<span class="Special"> &lt;- </span>copy left
  <span class="Comment"># maybe scroll</span>
  <span class="Delimiter">{</span>
    below-screen?:boolean<span class="Special"> &lt;- </span>greater-or-equal *cursor-row, screen-height  <span class="Comment"># must be equal, never greater</span>
    <span class="muControl">break-unless</span> below-screen?
<span class="Constant">    &lt;scroll-down&gt;</span>
    go-render?<span class="Special"> &lt;- </span>copy <span class="Constant">1/true</span>
    *cursor-row<span class="Special"> &lt;- </span>subtract *cursor-row, <span class="Constant">1</span>  <span class="Comment"># bring back into screen range</span>
  <span class="Delimiter">}</span>
  <span class="Comment"># indent if necessary</span>
  indent?:boolean<span class="Special"> &lt;- </span>get *editor, <span class="Constant">indent?:offset</span>
  <span class="muControl">reply-unless</span> indent?
  d:address:shared:duplex-list:character<span class="Special"> &lt;- </span>get *editor, <span class="Constant">data:offset</span>
  end-of-previous-line:address:shared:duplex-list:character<span class="Special"> &lt;- </span>prev *before-cursor
  indent:number<span class="Special"> &lt;- </span>line-indent end-of-previous-line, d
  i:number<span class="Special"> &lt;- </span>copy <span class="Constant">0</span>
  <span class="Delimiter">{</span>
    indent-done?:boolean<span class="Special"> &lt;- </span>greater-or-equal i, indent
    <span class="muControl">break-if</span> indent-done?
    editor, screen, go-render?:boolean<span class="Special"> &lt;- </span>insert-at-cursor editor, <span class="Constant">32/space</span>, screen
    i<span class="Special"> &lt;- </span>add i, <span class="Constant">1</span>
    <span class="muControl">loop</span>
  <span class="Delimiter">}</span>
]

<span class="Comment"># takes a pointer 'curr' into the doubly-linked list and its sentinel, counts</span>
<span class="Comment"># the number of spaces at the start of the line containing 'curr'.</span>
<span class="muRecipe">recipe</span> line-indent curr:address:shared:duplex-list:character, start:address:shared:duplex-list:character<span class="muRecipe"> -&gt; </span>result:number [
  <span class="Constant">local-scope</span>
  <span class="Constant">load-ingredients</span>
  result:number<span class="Special"> &lt;- </span>copy <span class="Constant">0</span>
  <span class="muControl">reply-unless</span> curr
  at-start?:boolean<span class="Special"> &lt;- </span>equal curr, start
  <span class="muControl">reply-if</span> at-start?
  <span class="Delimiter">{</span>
    curr<span class="Special"> &lt;- </span>prev curr
    <span class="muControl">break-unless</span> curr
    at-start?:boolean<span class="Special"> &lt;- </span>equal curr, start
    <span class="muControl">break-if</span> at-start?
    c:character<span class="Special"> &lt;- </span>get *curr, <span class="Constant">value:offset</span>
    at-newline?:boolean<span class="Special"> &lt;- </span>equal c, <span class="Constant">10/newline</span>
    <span class="muControl">break-if</span> at-newline?
    <span class="Comment"># if c is a space, increment result</span>
    is-space?:boolean<span class="Special"> &lt;- </span>equal c, <span class="Constant">32/space</span>
    <span class="Delimiter">{</span>
      <span class="muControl">break-unless</span> is-space?
      result<span class="Special"> &lt;- </span>add result, <span class="Constant">1</span>
    <span class="Delimiter">}</span>
    <span class="Comment"># if c is not a space, reset result</span>
    <span class="Delimiter">{</span>
      <span class="muControl">break-if</span> is-space?
      result<span class="Special"> &lt;- </span>copy <span class="Constant">0</span>
    <span class="Delimiter">}</span>
    <span class="muControl">loop</span>
  <span class="Delimiter">}</span>
]

<span class="muScenario">scenario</span> editor-moves-cursor-down-after-inserting-newline-2 [
  assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
  <span class="Constant">1</span>:address:shared:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[abc]</span>
  <span class="Constant">2</span>:address:shared:editor-data<span class="Special"> &lt;- </span>new-editor <span class="Constant">1</span>:address:shared:array:character, screen:address:shared:screen, <span class="Constant">1/left</span>, <span class="Constant">10/right</span>
  assume-console [
    type <span class="Constant">[0</span>
<span class="Constant">1]</span>
  ]
  run [
    editor-event-loop screen:address:shared:screen, console:address:shared:console, <span class="Constant">2</span>:address:shared:editor-data
  ]
  screen-should-contain [
   <span class="Constant"> .          .</span>
   <span class="Constant"> . 0        .</span>
   <span class="Constant"> . 1abc     .</span>
   <span class="Constant"> . ┈┈┈┈┈┈┈┈┈.</span>
   <span class="Constant"> .          .</span>
  ]
]

<span class="muScenario">scenario</span> editor-clears-previous-line-completely-after-inserting-newline [
  assume-screen <span class="Constant">10/width</span>, <span class="Constant">5/height</span>
  <span class="Constant">1</span>:address:shared:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[abcde]</span>
  <span class="Constant">2</span>:address:shared:editor-data<span class="Special"> &lt;- </span>new-editor <span class="Constant">1</span>:address:shared:array:character, screen:address:shared:screen, <span class="Constant">0/left</span>, <span class="Constant">5/right</span>
  assume-console [
    press enter
  ]
  screen-should-contain [
   <span class="Constant"> .          .</span>
   <span class="Constant"> .abcd↩     .</span>
   <span class="Constant"> .e         .</span>
   <span class="Constant"> .          .</span>
   <span class="Constant"> .          .</span>
  ]
  run [
    editor-event-loop screen:address:shared:screen, console:address:shared:console, <span class="Constant">2</span>:address:shared:editor-data
  ]
  <span class="Comment"># line should be fully cleared</span>
  screen-should-contain [
   <span class="Constant"> .          .</span>
   <span class="Constant"> .          .</span>
   <span class="Constant"> .abcd↩     .</span>
   <span class="Constant"> .e         .</span>
   <span class="Constant"> .┈┈┈┈┈     .</span>
  ]
]

<span class="muScenario">scenario</span> editor-inserts-indent-after-newline [
  assume-screen <span class="Constant">10/width</span>, <span class="Constant">10/height</span>
  <span class="Constant">1</span>:address:shared:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[ab</span>
<span class="Constant">  cd</span>
<span class="Constant">ef]</span>
  <span class="Constant">2</span>:address:shared:editor-data<span class="Special"> &lt;- </span>new-editor <span class="Constant">1</span>:address:shared:array:character, screen:address:shared:screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span>
  <span class="Comment"># position cursor after 'cd' and hit 'newline'</span>
  assume-console [
    left-click <span class="Constant">2</span>, <span class="Constant">8</span>
    type [
]
  ]
  run [
    editor-event-loop screen:address:shared:screen, console:address:shared:console, <span class="Constant">2</span>:address:shared:editor-data
    <span class="Constant">3</span>:number<span class="Special"> &lt;- </span>get *<span class="Constant">2</span>:address:shared:editor-data, <span class="Constant">cursor-row:offset</span>
    <span class="Constant">4</span>:number<span class="Special"> &lt;- </span>get *<span class="Constant">2</span>:address:shared:editor-data, <span class="Constant">cursor-column:offset</span>
  ]
  <span class="Comment"># cursor should be below start of previous line</span>
  memory-should-contain [
    <span class="Constant">3</span><span class="Special"> &lt;- </span><span class="Constant">3</span>  <span class="Comment"># cursor row</span>
    <span class="Constant">4</span><span class="Special"> &lt;- </span><span class="Constant">2</span>  <span class="Comment"># cursor column (indented)</span>
  ]
]

<span class="muScenario">scenario</span> editor-skips-indent-around-paste [
  assume-screen <span class="Constant">10/width</span>, <span class="Constant">10/height</span>
  <span class="Constant">1</span>:address:shared:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[ab</span>
<span class="Constant">  cd</span>
<span class="Constant">ef]</span>
  <span class="Constant">2</span>:address:shared:editor-data<span class="Special"> &lt;- </span>new-editor <span class="Constant">1</span>:address:shared:array:character, screen:address:shared:screen, <span class="Constant">0/left</span>, <span class="Constant">10/right</span>
  <span class="Comment"># position cursor after 'cd' and hit 'newline' surrounded by paste markers</span>
  assume-console [
    left-click <span class="Constant">2</span>, <span class="Constant">8</span>
    press <span class="Constant">65507</span>  <span class="Comment"># start paste</span>
    press enter
    press <span class="Constant">65506</span>  <span class="Comment"># end paste</span>
  ]
  run [
    editor-event-loop screen:address:shared:screen, console:address:shared:console, <span class="Constant">2</span>:address:shared:editor-data
    <span class="Constant">3</span>:number<span class="Special"> &lt;- </span>get *<span class="Constant">2</span>:address:shared:editor-data, <span class="Constant">cursor-row:offset</span>
    <span class="Constant">4</span>:number<span class="Special"> &lt;- </span>get *<span class="Constant">2</span>:address:shared:editor-data, <span class="Constant">cursor-column:offset</span>
  ]
  <span class="Comment"># cursor should be below start of previous line</span>
  memory-should-contain [
    <span class="Constant">3</span><span class="Special"> &lt;- </span><span class="Constant">3</span>  <span class="Comment"># cursor row</span>
    <span class="Constant">4</span><span class="Special"> &lt;- </span><span class="Constant">0</span>  <span class="Comment"># cursor column (not indented)</span>
  ]
]

<span class="muRecipe">after</span> <span class="Constant">&lt;handle-special-key&gt;</span> [
  <span class="Delimiter">{</span>
    paste-start?:boolean<span class="Special"> &lt;- </span>equal *k, <span class="Constant">65507/paste-start</span>
    <span class="muControl">break-unless</span> paste-start?
    indent?:address:boolean<span class="Special"> &lt;- </span>get-address *editor, <span class="Constant">indent?:offset</span>
    *indent?<span class="Special"> &lt;- </span>copy <span class="Constant">0/false</span>
    go-render?<span class="Special"> &lt;- </span>copy <span class="Constant">1/true</span>
    <span class="muControl">reply</span>
  <span class="Delimiter">}</span>
]

<span class="muRecipe">after</span> <span class="Constant">&lt;handle-special-key&gt;</span> [
  <span class="Delimiter">{</span>
    paste-end?:boolean<span class="Special"> &lt;- </span>equal *k, <span class="Constant">65506/paste-end</span>
    <span class="muControl">break-unless</span> paste-end?
    indent?:address:boolean<span class="Special"> &lt;- </span>get-address *editor, <span class="Constant">indent?:offset</span>
    *indent?<span class="Special"> &lt;- </span>copy <span class="Constant">1/true</span>
    go-render?<span class="Special"> &lt;- </span>copy <span class="Constant">1/true</span>
    <span class="muControl">reply</span>
  <span class="Delimiter">}</span>
]

<span class="SalientComment">## helpers</span>

<span class="muRecipe">recipe</span> draw-horizontal screen:address:shared:screen, row:number, x:number, right:number<span class="muRecipe"> -&gt; </span>screen:address:shared:screen [
  <span class="Constant">local-scope</span>
  <span class="Constant">load-ingredients</span>
  style:character, style-found?:boolean<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Delimiter">{</span>
    <span class="muControl">break-if</span> style-found?
    style<span class="Special"> &lt;- </span>copy <span class="Constant">9472/horizontal</span>
  <span class="Delimiter">}</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">245/grey</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="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>move-cursor screen, row, x
  <span class="Delimiter">{</span>
    continue?:boolean<span class="Special"> &lt;- </span>lesser-or-equal x, right  <span class="Comment"># right is inclusive, to match editor-data semantics</span>
    <span class="muControl">break-unless</span> continue?
    print screen, style, color, bg-color
    x<span class="Special"> &lt;- </span>add x, <span class="Constant">1</span>
    <span class="muControl">loop</span>
  <span class="Delimiter">}</span>
]
</pre>
</body>
</html>
<!-- vim: set foldmethod=manual : -->