about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-06-08 11:57:03 -0700
committerKartik K. Agaram <vc@akkartik.com>2021-06-08 11:57:03 -0700
commit227d18f8a235701ea10b067ab4e1d3d8d2b579ed (patch)
tree128d9c5bdac594dd029c255fc2b159f1b4af46a6
parent9d2c64455a87edd4d241cbedd18963010b110a32 (diff)
downloadmu-227d18f8a235701ea10b067ab4e1d3d8d2b579ed.tar.gz
shell: first test for entire environment
This introduces some ergonomic issues. But we have to start somewhere.
-rw-r--r--shell/environment.mu71
-rw-r--r--shell/gap-buffer.mu12
2 files changed, 77 insertions, 6 deletions
diff --git a/shell/environment.mu b/shell/environment.mu
index d4ca72e4..7eef0d5a 100644
--- a/shell/environment.mu
+++ b/shell/environment.mu
@@ -1,3 +1,10 @@
+# The top-level data structure for the Mu shell.
+#
+# vim:textwidth&
+# It would be nice for this test to use a narrower screen than the standard
+# 0x80 of 1024 pixels with 8px-wide graphemes. But it complicates rendering
+# logic, so we need longer lines than usual.
+
 type environment {
   globals: global-table
   sandbox: sandbox
@@ -6,6 +13,68 @@ type environment {
   cursor-in-function-modal?: boolean
 }
 
+# Here's a sample usage session and what it will look like on the screen.
+fn test-environment {
+  var env-storage: environment
+  var env/esi: (addr environment) <- address env-storage
+  initialize-environment env
+  # setup: screen
+  var screen-on-stack: screen
+  var screen/edi: (addr screen) <- address screen-on-stack
+  initialize-screen screen, 0x80/width=72, 0x10/height, 0/no-pixel-graphics
+  #
+  edit-environment env, 0x61/a, 0/no-disk
+  render-environment screen, env
+#?   type-into-repl env, screen, "(define fn1 (fn() 42))"
+  #                                                         | global function definitions                                                        | sandbox
+  # top row blank for now
+  check-screen-row                     screen,         0/y, "                                                                                                                                ", "F - test-environment/0"
+  check-screen-row                     screen,         1/y, "                                                                                      screen:                                   ", "F - test-environment/1"
+  # starting at the same screen row, render the fake screen that exists within the sandbox within env
+  check-background-color-in-screen-row screen, 0/bg,   1/y, "                                                                                                ........                        ", "F - test-environment/1-2"
+  check-background-color-in-screen-row screen, 0/bg,   2/y, "                                                                                                ........                        ", "F - test-environment/2"
+  check-background-color-in-screen-row screen, 0/bg,   3/y, "                                                                                                ........                        ", "F - test-environment/3"
+  check-screen-row                     screen,         4/y, "                                                                                                                                ", "F - test-environment/4"
+  check-screen-row                     screen,         5/y, "                                                                                      keyboard:                                 ", "F - test-environment/5"
+  check-background-color-in-screen-row screen, 0/bg,   5/y, "                                                                                                ................                ", "F - test-environment/5-2"
+  check-screen-row                     screen,         6/y, "                                                                                                                                ", "F - test-environment/6"
+  check-screen-row                     screen,         7/y, "                                                                                      a                                         ", "F - test-environment/7"
+  check-screen-row                     screen,         8/y, "                                                                                                                                ", "F - test-environment/8"
+  check-screen-row                     screen,         9/y, "                                                                                                                                ", "F - test-environment/9"
+  check-screen-row                     screen,       0xa/y, "                                                                                                                                ", "F - test-environment/0xa"
+  check-screen-row                     screen,       0xb/y, "                                                                                                                                ", "F - test-environment/0xb"
+  check-screen-row                     screen,       0xc/y, "                                                                                                                                ", "F - test-environment/0xc"
+  check-screen-row                     screen,       0xd/y, "                                                                                                                                ", "F - test-environment/0xd"
+  check-screen-row                     screen,       0xe/y, "                                                                                                                                ", "F - test-environment/0xe"
+  # bottom row is for a wordstar-style menu
+  check-screen-row                     screen,       0xf/y, " ^r  run main   ^s  run sandbox   ^g  go to   ^m  to keyboard   ^a  <<   ^b  <word   ^f  word>   ^e  >>                         ", "F - test-environment/0xf"
+}
+
+# helper for testing
+fn type-into-repl self: (addr environment), screen: (addr screen), keys: (addr array byte) {
+  # clear the buffer
+  edit-environment self, 0x15/ctrl-u, 0/no-disk
+  render-environment screen, self
+  # type in all the keys
+  var input-stream-storage: (stream byte 0x40/capacity)
+  var input-stream/ecx: (addr stream byte) <- address input-stream-storage
+  write input-stream, keys
+  {
+    var done?/eax: boolean <- stream-empty? input-stream
+    compare done?, 0/false
+    break-if-!=
+    var key/eax: grapheme <- read-grapheme input-stream
+    edit-environment self, key, 0/no-disk
+    render-environment screen, self
+    loop
+  }
+  # hit 'enter'
+  edit-environment self, 0xa/newline, 0/no-disk
+  render-environment screen, self
+}
+
+## interface
+
 fn initialize-environment _self: (addr environment) {
   var self/esi: (addr environment) <- copy _self
   var globals/eax: (addr global-table) <- get self, globals
@@ -221,6 +290,8 @@ fn edit-environment _self: (addr environment), key: grapheme, data-disk: (addr d
   edit-sandbox sandbox, key, globals, data-disk, 1/tweak-real-screen
 }
 
+## details
+
 fn word-at-cursor _self: (addr environment), out: (addr stream byte) {
   var self/esi: (addr environment) <- copy _self
   var cursor-in-function-modal-a/eax: (addr boolean) <- get self, cursor-in-function-modal?
diff --git a/shell/gap-buffer.mu b/shell/gap-buffer.mu
index 13f66f40..64b7a9a4 100644
--- a/shell/gap-buffer.mu
+++ b/shell/gap-buffer.mu
@@ -50,16 +50,16 @@ fn gap-buffer-capacity _gap: (addr gap-buffer) -> _/ecx: int {
 }
 
 # just for tests
-fn initialize-gap-buffer-with self: (addr gap-buffer), s: (addr array byte) {
+fn initialize-gap-buffer-with self: (addr gap-buffer), keys: (addr array byte) {
   initialize-gap-buffer self, 0x40/capacity
-  var stream-storage: (stream byte 0x40/capacity)
-  var stream/ecx: (addr stream byte) <- address stream-storage
-  write stream, s
+  var input-stream-storage: (stream byte 0x40/capacity)
+  var input-stream/ecx: (addr stream byte) <- address input-stream-storage
+  write input-stream, keys
   {
-    var done?/eax: boolean <- stream-empty? stream
+    var done?/eax: boolean <- stream-empty? input-stream
     compare done?, 0/false
     break-if-!=
-    var g/eax: grapheme <- read-grapheme stream
+    var g/eax: grapheme <- read-grapheme input-stream
     add-grapheme-at-gap self, g
     loop
   }