about summary refs log tree commit diff stats
path: root/shell
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-04-05 22:28:26 -0700
committerKartik K. Agaram <vc@akkartik.com>2021-04-05 22:37:27 -0700
commit143cce94eea904ef025c94238fe3541b87ad694e (patch)
tree594a28c8f9008fc812ce09403c09fcddacf81168 /shell
parent316bf37541c820e3c9d4b6640f4db324c4b2963b (diff)
downloadmu-143cce94eea904ef025c94238fe3541b87ad694e.tar.gz
support for arrow keys
Mu's keyboard handling is currently a bit of a mess, and this commit might
be a bad idea.

Ideally keyboards would return Unicode. Currently Mu returns single bytes.
Mostly ASCII. No support for international keyboards yet.

ASCII and Unicode have some keyboard scancodes grandfathered in, that don't
really make sense for data transmission. Like backspace and delete. However,
other keyboard scancodes don't have any place in Unicode. Including arrow keys.

So Mu carves out an exception to Unicode for arrow keys. We'll place the
arrow keys in a part of Unicode that is set aside for implementation-defined
behavior (https://en.wikipedia.org/wiki/C0_and_C1_control_codes#C1_controls):

  0x80: left arrow
  0x81: down arrow
  0x82: up arrow
  0x83: right arrow

The order is same as hjkl for mnemonic convenience. I'd _really_ to follow
someone else's cannibalization here. If I find one later, I'll switch to
it.

Applications that blindly assume the keyboard generates Unicode will have
a bad time. Events like backspace, delete and arrow keys are intended to
be processed early and should not be in text.

With a little luck I won't need to modify this convention when I support
international keyboards.
Diffstat (limited to 'shell')
-rw-r--r--shell/gap-buffer.mu12
-rw-r--r--shell/trace.mu14
2 files changed, 26 insertions, 0 deletions
diff --git a/shell/gap-buffer.mu b/shell/gap-buffer.mu
index b3c84532..616500b0 100644
--- a/shell/gap-buffer.mu
+++ b/shell/gap-buffer.mu
@@ -759,6 +759,18 @@ fn edit-gap-buffer self: (addr gap-buffer), key: grapheme {
     delete-before-gap self
     return
   }
+  {
+    compare g, 0x80/left-arrow
+    break-if-!=
+    var dummy/eax: grapheme <- gap-left self
+    return
+  }
+  {
+    compare g, 0x83/right-arrow
+    break-if-!=
+    var dummy/eax: grapheme <- gap-right self
+    return
+  }
   # default: insert character
   add-grapheme-at-gap self, g
 }
diff --git a/shell/trace.mu b/shell/trace.mu
index 0736f796..b0c43f74 100644
--- a/shell/trace.mu
+++ b/shell/trace.mu
@@ -690,6 +690,13 @@ fn edit-trace _self: (addr trace), key: grapheme {
     increment *cursor-y
     return
   }
+  {
+    compare key, 0x81/down-arrow
+    break-if-!=
+    var cursor-y/eax: (addr int) <- get self, cursor-y
+    increment *cursor-y
+    return
+  }
   # cursor up
   {
     compare key, 0x6b/k
@@ -698,6 +705,13 @@ fn edit-trace _self: (addr trace), key: grapheme {
     decrement *cursor-y
     return
   }
+  {
+    compare key, 0x82/up-arrow
+    break-if-!=
+    var cursor-y/eax: (addr int) <- get self, cursor-y
+    decrement *cursor-y
+    return
+  }
   # enter = expand
   {
     compare key, 0xa/newline