Skip to content

Commit e403d15

Browse files
committed
6794 - cleaner interface for keyboard
So far I've been assuming that read-key only works for ascii, and that I'd need to get more sophisticated both for multi-byte utf-8 and multi-byte terminal escape codes like arrow keys. Rather to my surprise, both work fine. We just need to adjust the types to reflect this fact.
1 parent 797c93e commit e403d15

File tree

37 files changed

+61
-53
lines changed

37 files changed

+61
-53
lines changed

305keyboard.subx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,22 @@ $enable-keyboard-type-mode:end:
119119
5d/pop-to-ebp
120120
c3/return
121121

122-
read-key-from-real-keyboard: # -> result/eax: byte
122+
# read keys or escapes up to 4 bytes
123+
#
124+
# fun fact: terminal escapes and graphemes in utf-8 don't conflict!
125+
# - in graphemes all but the first/lowest byte will have a 1 in the MSB (be
126+
# greater than 0x7f)
127+
# - in escapes every byte will have a 0 in the MSB
128+
# the two categories overlap only when the first/lowest byte is 0x1b or 'esc'
129+
read-key-from-real-keyboard: # -> result/eax: grapheme
123130
# . prologue
124131
55/push-ebp
125132
89/<- %ebp 4/r32/esp
126133
# . save registers
127134
51/push-ecx
128-
# var buf/ecx: (stream byte 1)
135+
# var buf/ecx: (stream byte 4)
129136
68/push 0/imm32/data
130-
68/push 1/imm32/size # 3 bytes of data unused
137+
68/push 4/imm32/size
131138
68/push 0/imm32/read
132139
68/push 0/imm32/write
133140
89/<- %ecx 4/r32/esp

400.mu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ sig hide-cursor-on-real-screen
161161
sig show-cursor-on-real-screen
162162
sig enable-keyboard-immediate-mode
163163
sig enable-keyboard-type-mode
164-
sig read-key-from-real-keyboard -> result/eax: byte
164+
sig read-key-from-real-keyboard -> result/eax: grapheme
165165
sig read-line-from-real-keyboard in: (addr stream byte)
166166
sig open filename: (addr array byte), write?: boolean, out: (addr handle buffered-file)
167167
sig populate-buffered-file-containing contents: (addr array byte), out: (addr handle buffered-file)

prototypes/browse/10.mu

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

prototypes/browse/11.mu

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

prototypes/browse/12.mu

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

prototypes/browse/13.mu

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

prototypes/browse/14.mu

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

prototypes/browse/15-headers-broken.mu

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

prototypes/browse/16-screen-state-broken.mu

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

prototypes/browse/17-file-state-broken/main.mu

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)