about summary refs log tree commit diff stats
path: root/baremetal/shell
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-02-14 14:30:46 -0800
committerKartik K. Agaram <vc@akkartik.com>2021-02-14 14:30:46 -0800
commit4961a020b47d89a09ed5cbcf51ddac2b3e8bfcc2 (patch)
tree70b405e0ae039ba1d99968c8a9c4728e5cb36e0a /baremetal/shell
parent1a9d3cb7efa84c0399fc852b93021eff89195d9d (diff)
downloadmu-4961a020b47d89a09ed5cbcf51ddac2b3e8bfcc2.tar.gz
7741 - baremetal/shell: first run: single number
Diffstat (limited to 'baremetal/shell')
-rw-r--r--baremetal/shell/line.mu34
1 files changed, 34 insertions, 0 deletions
diff --git a/baremetal/shell/line.mu b/baremetal/shell/line.mu
index f0831c36..67901ffa 100644
--- a/baremetal/shell/line.mu
+++ b/baremetal/shell/line.mu
@@ -11,6 +11,8 @@ fn initialize-line _line: (addr line) {
   var line/esi: (addr line) <- copy _line
   var word-ah/eax: (addr handle word) <- get line, data
   allocate word-ah
+  var cursor-ah/ecx: (addr handle word) <- get line, cursor
+  copy-object word-ah, cursor-ah
   var word/eax: (addr word) <- lookup *word-ah
   initialize-word word
 }
@@ -164,3 +166,35 @@ fn test-render-line-with-stack-singleton {
   check-screen-row screen, 1/y, " 1 ", "F - test-render-line-with-stack-singleton/1"
   # not bothering to test hash colors for numbers
 }
+
+fn edit-line _self: (addr line), key: byte {
+  var self/esi: (addr line) <- copy _self
+  var cursor-word-ah/eax: (addr handle word) <- get self, cursor
+  var _cursor-word/eax: (addr word) <- lookup *cursor-word-ah
+  var cursor-word/ecx: (addr word) <- copy _cursor-word
+  # otherwise insert key within current word
+  var g/edx: grapheme <- copy key
+  add-grapheme-to-word cursor-word, g
+  # silently ignore other hotkeys
+}
+
+fn main {
+  var line-storage: line
+  var line/esi: (addr line) <- address line-storage
+  initialize-line line
+  $main:loop: {
+    clear-screen 0/screen
+    var dummy1/eax: int <- copy 0
+    var dummy2/ecx: int <- copy 0
+    dummy1, dummy2 <- render-line-with-stack 0/screen, line, 2/x, 2/y, 1/show-cursor
+    {
+      var key/eax: byte <- read-key 0/keyboard
+      compare key, 0
+      loop-if-=
+      compare key, 0x71/q
+      break-if-= $main:loop
+      edit-line line, key
+    }
+    loop
+  }
+}