about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-06-04 21:11:21 -0700
committerKartik K. Agaram <vc@akkartik.com>2021-06-04 21:47:36 -0700
commitd40dfea3eda6b7679d7d6584e6ddf5ae7bd85736 (patch)
treeb6d37b4b7595b76ee6c15c060df8ee948e23144b
parent9d1f0e6ecad32382034697f3cc3bd8ac10faaaf1 (diff)
downloadmu-d40dfea3eda6b7679d7d6584e6ddf5ae7bd85736.tar.gz
modal dialog for function name to jump to
-rw-r--r--shell/environment.mu101
-rw-r--r--shell/gap-buffer.mu16
2 files changed, 115 insertions, 2 deletions
diff --git a/shell/environment.mu b/shell/environment.mu
index 9cadbf4f..9b2f015a 100644
--- a/shell/environment.mu
+++ b/shell/environment.mu
@@ -15,7 +15,7 @@ fn initialize-environment _self: (addr environment) {
   var partial-function-name-ah/eax: (addr handle gap-buffer) <- get self, partial-function-name
   allocate partial-function-name-ah
   var partial-function-name/eax: (addr gap-buffer) <- lookup *partial-function-name-ah
-  initialize-gap-buffer partial-function-name, 0x40/capacity
+  initialize-gap-buffer partial-function-name, 0x40/function-name-capacity
 }
 
 fn render-environment screen: (addr screen), _self: (addr environment) {
@@ -27,6 +27,15 @@ fn render-environment screen: (addr screen), _self: (addr environment) {
   render-globals screen, globals
   var sandbox/edx: (addr sandbox) <- get self, sandbox
   render-sandbox screen, sandbox, 0x55/sandbox-left-margin, 0/sandbox-top-margin, 0x80/screen-width, 0x2f/screen-height-without-menu
+  # modal if necessary
+  {
+    var cursor-in-function-modal-a/eax: (addr boolean) <- get self, cursor-in-function-modal?
+    compare *cursor-in-function-modal-a, 0/false
+    break-if-=
+    render-function-modal screen, self
+    render-function-modal-menu screen, self
+    return
+  }
   # render menu
   {
     var cursor-in-globals?/eax: (addr boolean) <- get self, cursor-in-globals?
@@ -124,11 +133,19 @@ fn edit-environment _self: (addr environment), key: grapheme, data-disk: (addr d
     {
       compare key, 0xa/newline
       break-if-!=
-      var cursor-in-globals-a/eax: (addr boolean) <- get self, cursor-in-globals?
+      var cursor-in-globals-a/edx: (addr boolean) <- get self, cursor-in-globals?
       copy-to *cursor-in-globals-a, 1/true
       # TODO: use function name
       var partial-function-name-ah/eax: (addr handle gap-buffer) <- get self, partial-function-name
       var partial-function-name/eax: (addr gap-buffer) <- lookup *partial-function-name-ah
+      var cursor-in-globals-a/ecx: (addr boolean) <- get self, cursor-in-globals?
+      copy-to *cursor-in-globals-a, 1/true
+      {
+        var empty?/eax: boolean <- gap-buffer-empty? partial-function-name
+        compare empty?, 0/false
+        break-if-=
+        copy-to *cursor-in-globals-a, 0/false
+      }
       clear-gap-buffer partial-function-name
       var cursor-in-function-modal-a/eax: (addr boolean) <- get self, cursor-in-function-modal?
       copy-to *cursor-in-function-modal-a, 0/false
@@ -151,6 +168,86 @@ fn edit-environment _self: (addr environment), key: grapheme, data-disk: (addr d
   edit-sandbox sandbox, key, globals, data-disk, 1/tweak-real-screen
 }
 
+fn render-function-modal screen: (addr screen), _self: (addr environment) {
+  var self/esi: (addr environment) <- copy _self
+  var width/eax: int <- copy 0
+  var height/ecx: int <- copy 0
+  width, height <- screen-size screen
+  # xmin = max(0, width/2 - 0x20)
+  var xmin: int
+  var tmp/edx: int <- copy width
+  tmp <- shift-right 1
+  tmp <- subtract 0x20/half-function-name-capacity
+  {
+    compare tmp, 0
+    break-if->=
+    tmp <- copy 0
+  }
+  copy-to xmin, tmp
+  # xmax = min(width, width/2 + 0x20)
+  var xmax: int
+  tmp <- copy width
+  tmp <- shift-right 1
+  tmp <- add 0x20/half-function-name-capacity
+  {
+    compare tmp, width
+    break-if-<=
+    tmp <- copy width
+  }
+  copy-to xmax, tmp
+  # ymin = height/2 - 2
+  var ymin: int
+  tmp <- copy height
+  tmp <- shift-right 1
+  tmp <- subtract 2
+  copy-to ymin, tmp
+  # ymax = height/2 + 1
+  var ymax: int
+  tmp <- add 3
+  copy-to ymax, tmp
+  #
+  clear-rect screen, xmin, ymin, xmax, ymax, 0xf/bg=modal
+  add-to xmin, 4
+  set-cursor-position screen, xmin, ymin
+  draw-text-rightward-from-cursor screen, "go to function (or leave blank to go to REPL)", xmax, 8/fg=dark-grey, 0xf/bg=modal
+  var partial-function-name-ah/eax: (addr handle gap-buffer) <- get self, partial-function-name
+  var _partial-function-name/eax: (addr gap-buffer) <- lookup *partial-function-name-ah
+  var partial-function-name/edx: (addr gap-buffer) <- copy _partial-function-name
+  subtract-from xmin, 4
+  add-to ymin 2
+  var dummy/eax: int <- copy 0
+  var dummy2/ecx: int <- copy 0
+  dummy, dummy2 <- render-gap-buffer-wrapping-right-then-down screen, partial-function-name, xmin, ymin, xmax, ymax, 1/always-render-cursor, 0/fg=black, 0xf/bg=modal
+}
+
+fn render-function-modal-menu screen: (addr screen), _self: (addr environment) {
+  var self/esi: (addr environment) <- copy _self
+  var _width/eax: int <- copy 0
+  var height/ecx: int <- copy 0
+  _width, height <- screen-size screen
+  var width/edx: int <- copy _width
+  var y/ecx: int <- copy height
+  y <- decrement
+  var height/ebx: int <- copy y
+  height <- increment
+  clear-rect screen, 0/x, y, width, height, 0xc5/bg=blue-bg
+  set-cursor-position screen, 0/x, y
+  draw-text-rightward-from-cursor screen, " ^r ", width, 0/fg, 0x5c/bg=menu-highlight
+  draw-text-rightward-from-cursor screen, " run main  ", width, 7/fg, 0xc5/bg=blue-bg
+  draw-text-rightward-from-cursor screen, " enter ", width, 0/fg, 0x5c/bg=menu-highlight
+  draw-text-rightward-from-cursor screen, " submit  ", width, 7/fg, 0xc5/bg=blue-bg
+  draw-text-rightward-from-cursor screen, " esc ", width, 0/fg, 0x5c/bg=menu-highlight
+  draw-text-rightward-from-cursor screen, " cancel  ", width, 7/fg, 0xc5/bg=blue-bg
+  draw-text-rightward-from-cursor screen, " ^a ", width, 0/fg, 0x5c/bg=menu-highlight
+  draw-text-rightward-from-cursor screen, " <<  ", width, 7/fg, 0xc5/bg=blue-bg
+  draw-text-rightward-from-cursor screen, " ^b ", width, 0/fg, 0x5c/bg=menu-highlight
+  draw-text-rightward-from-cursor screen, " <word  ", width, 7/fg, 0xc5/bg=blue-bg
+  draw-text-rightward-from-cursor screen, " ^f ", width, 0/fg, 0x5c/bg=menu-highlight
+  draw-text-rightward-from-cursor screen, " word>  ", width, 7/fg, 0xc5/bg=blue-bg
+  draw-text-rightward-from-cursor screen, " ^e ", width, 0/fg, 0x5c/bg=menu-highlight
+  draw-text-rightward-from-cursor screen, " >>  ", width, 7/fg, 0xc5/bg=blue-bg
+}
+
 # Gotcha: some saved state may not load.
 fn load-state _self: (addr environment), data-disk: (addr disk) {
   var self/esi: (addr environment) <- copy _self
diff --git a/shell/gap-buffer.mu b/shell/gap-buffer.mu
index 8dada84a..c2f9b3b2 100644
--- a/shell/gap-buffer.mu
+++ b/shell/gap-buffer.mu
@@ -24,6 +24,22 @@ fn clear-gap-buffer _self: (addr gap-buffer) {
   clear-grapheme-stack right
 }
 
+fn gap-buffer-empty? _self: (addr gap-buffer) -> _/eax: boolean {
+  var self/esi: (addr gap-buffer) <- copy _self
+  # if !empty?(left) return false
+  {
+    var left/eax: (addr grapheme-stack) <- get self, left
+    var result/eax: boolean <- grapheme-stack-empty? left
+    compare result, 0/false
+    break-if-!=
+    return 0/false
+  }
+  # return empty?(right)
+  var left/eax: (addr grapheme-stack) <- get self, left
+  var result/eax: boolean <- grapheme-stack-empty? left
+  return result
+}
+
 fn gap-buffer-capacity _gap: (addr gap-buffer) -> _/ecx: int {
   var gap/esi: (addr gap-buffer) <- copy _gap
   var left/eax: (addr grapheme-stack) <- get gap, left