From 9a183b817903c39fc33d38d73bf506ced3e5553e Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Wed, 13 Oct 2021 23:15:59 -0700 Subject: support backspace when reading line from keyboard --- 516read-line.mu | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to '516read-line.mu') diff --git a/516read-line.mu b/516read-line.mu index 1bb79c5a..5c96a832 100644 --- a/516read-line.mu +++ b/516read-line.mu @@ -2,13 +2,24 @@ # abort on stream overflow fn read-line-from-keyboard keyboard: (addr keyboard), out: (addr stream byte), screen: (addr screen), fg: int, bg: int { clear-stream out - { + $read-line-from-keyboard:loop: { draw-cursor screen, 0x20/space var key/eax: byte <- read-key keyboard compare key, 0xa/newline break-if-= compare key, 0 loop-if-= + compare key, 8/backspace + { + break-if-!= + undo-append-byte out + draw-code-point-at-cursor-over-full-screen screen, 0x20/space, fg 0/bg # clear cursor + move-cursor-left screen + move-cursor-left screen + draw-code-point-at-cursor-over-full-screen screen, 0x20/space, fg 0/bg # clear old cursor + move-cursor-left screen + loop $read-line-from-keyboard:loop + } var key2/eax: int <- copy key append-byte out, key2 var c/eax: code-point <- copy key2 -- cgit 1.4.1-2-gfad0