about summary refs log tree commit diff stats
path: root/baremetal/shell/sandbox.mu
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-02-20 22:45:10 -0800
committerKartik K. Agaram <vc@akkartik.com>2021-02-20 22:45:35 -0800
commitcf5c8bc6b0e880a312a304a13712dce2b206c3c7 (patch)
tree609df0a156934531d97b6929ae1f47a80959cbd2 /baremetal/shell/sandbox.mu
parent684c09620304457825981eaaaf7af8af2dc64d15 (diff)
downloadmu-cf5c8bc6b0e880a312a304a13712dce2b206c3c7.tar.gz
7762 - baremetal/shell: backspace
The text buffer can now shrink, which means we need to be careful to erase
the old location of the cursor. Just clear screen before render each time.
Which means we need to be more efficient with our rendering.
Diffstat (limited to 'baremetal/shell/sandbox.mu')
-rw-r--r--baremetal/shell/sandbox.mu14
1 files changed, 14 insertions, 0 deletions
diff --git a/baremetal/shell/sandbox.mu b/baremetal/shell/sandbox.mu
index e360b9e6..4ca1082c 100644
--- a/baremetal/shell/sandbox.mu
+++ b/baremetal/shell/sandbox.mu
@@ -34,7 +34,15 @@ fn add-grapheme-to-sandbox _self: (addr sandbox), c: grapheme {
   add-grapheme-at-gap data, c
 }
 
+fn delete-grapheme-before-cursor _self: (addr sandbox) {
+  var self/esi: (addr sandbox) <- copy _self
+  var data-ah/eax: (addr handle gap-buffer) <- get self, data
+  var data/eax: (addr gap-buffer) <- lookup *data-ah
+  delete-before-gap data
+}
+
 fn render-sandbox screen: (addr screen), _self: (addr sandbox), x: int, y: int {
+  clear-screen screen
   var self/esi: (addr sandbox) <- copy _self
   var data-ah/eax: (addr handle gap-buffer) <- get self, data
   var data/eax: (addr gap-buffer) <- lookup *data-ah
@@ -43,5 +51,11 @@ fn render-sandbox screen: (addr screen), _self: (addr sandbox), x: int, y: int {
 
 fn edit-sandbox self: (addr sandbox), key: byte {
   var g/edx: grapheme <- copy key
+  {
+    compare g, 8/backspace
+    break-if-!=
+    delete-grapheme-before-cursor self
+    return
+  }
   add-grapheme-to-sandbox self, g
 }