diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-01-25 00:09:52 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-01-25 00:09:52 -0800 |
commit | 09e2e533ed6643cc586de3d9e51c0b1cb3da2e3e (patch) | |
tree | 6c96c50c207bf9dcd08a70ea0a0ae807f9d91296 | |
parent | 5bf97dd2d18cbf97c6aa21213f903f9d7708f151 (diff) | |
download | mu-09e2e533ed6643cc586de3d9e51c0b1cb3da2e3e.tar.gz |
616 - buffered-stdin handles backspace
Chessboard now *almost* handles backspace perfectly.
-rw-r--r-- | buffered-stdin.mu | 2 | ||||
-rw-r--r-- | chessboard-cursor.mu | 5 | ||||
-rw-r--r-- | mu.arc | 7 | ||||
-rw-r--r-- | mu.arc.t | 34 |
4 files changed, 46 insertions, 2 deletions
diff --git a/buffered-stdin.mu b/buffered-stdin.mu index 167b268b..7db3e291 100644 --- a/buffered-stdin.mu +++ b/buffered-stdin.mu @@ -7,8 +7,8 @@ ; hook up stdin (stdin:channel-address <- init-channel 1:literal) (fork-helper send-keys-to-stdin:fn nil:literal/globals nil:literal/limit nil:literal/keyboard stdin:channel-address) - (buffered-stdin:channel-address <- init-channel 1:literal) ; buffer stdin + (buffered-stdin:channel-address <- init-channel 1:literal) (fork-helper buffer-stdin:fn nil:literal/globals nil:literal/limit stdin:channel-address buffered-stdin:channel-address) ; now read characters from the buffer until a 'enter' is typed (s:string-address <- new "? ") diff --git a/chessboard-cursor.mu b/chessboard-cursor.mu index 2b13e8c9..e976e3ab 100644 --- a/chessboard-cursor.mu +++ b/chessboard-cursor.mu @@ -212,6 +212,9 @@ ; hook up stdin (stdin:channel-address <- init-channel 1:literal) (fork-helper send-keys-to-stdin:fn nil:literal/globals nil:literal/limit nil:literal/keyboard stdin:channel-address) + ; buffer stdin + (buffered-stdin:channel-address <- init-channel 1:literal) + (fork-helper buffer-stdin:fn nil:literal/globals nil:literal/limit stdin:channel-address buffered-stdin:channel-address) { begin ; print any stray characters from keyboard *before* clearing screen (clear-screen nil:literal/terminal) @@ -225,7 +228,7 @@ (print-primitive-to-host (("Hit 'q' to exit." literal))) (cursor-to-next-line nil:literal/terminal) (print-primitive-to-host (("move: " literal))) - (m:move-address <- read-move stdin:channel-address) + (m:move-address <- read-move buffered-stdin:channel-address) (break-unless m:move-address) (b:board-address <- make-move b:board-address m:move-address) (loop) diff --git a/mu.arc b/mu.arc index a4e423ee..ca98f72b 100644 --- a/mu.arc +++ b/mu.arc @@ -2030,6 +2030,13 @@ (x:tagged-value stdin:channel-address/deref <- read stdin:channel-address) (c:character <- maybe-coerce x:tagged-value character:literal) (assert c:character) + { begin + (backspace?:boolean <- equal c:character ((#\backspace literal))) + (break-unless backspace?:boolean) + (len:integer-address <- get-address line:buffer-address/deref length:offset) + (len:integer-address/deref <- subtract len:integer-address/deref 1:literal) + (loop 2:blocks) + } (line:buffer-address <- append line:buffer-address c:character) (line-contents:string-address <- get line:buffer-address/deref data:offset) ;? (print-primitive-to-host c:character) ;? 0 diff --git a/mu.arc.t b/mu.arc.t index 6ae86e96..9c321af6 100644 --- a/mu.arc.t +++ b/mu.arc.t @@ -4212,6 +4212,40 @@ " ")) (prn "F - 'buffer-stdin' prints lines to screen")) +(reset) +(new-trace "buffered-contents-skip-backspace") +(add-code + '((function main [ + (default-space:space-address <- new space:literal 30:literal) + (s:string-address <- new "fooa\b\nline2") + (k:keyboard-address <- init-keyboard s:string-address) + (stdin:channel-address <- init-channel 1:literal) + (fork send-keys-to-stdin:fn nil:literal/globals nil:literal/limit k:keyboard-address stdin:channel-address) + (buffered-stdin:channel-address <- init-channel 1:literal) + (r:integer/routine <- fork buffer-stdin:fn nil:literal/globals nil:literal/limit stdin:channel-address buffered-stdin:channel-address) + (screen:terminal-address <- init-fake-terminal 20:literal 10:literal) + (5:string-address/raw <- get screen:terminal-address/deref data:offset) + (fork-helper send-prints-to-stdout:fn nil:literal/globals nil:literal/limit screen:terminal-address buffered-stdin:channel-address) + (sleep until-routine-done:literal r:integer/routine) + ]))) +;? (= dump-trace* (obj whitelist '("schedule" "run"))) ;? 1 +(run 'main) +(each routine completed-routines* + (awhen rep.routine!error + (prn "error - " it))) +(when (~memory-contains-array memory*.5 + (+ "foo\n " + " " + " " + " " + " " + " " + " " + " " + " " + " ")) + (prn "F - 'buffer-stdin' handles backspace")) + ) ; section 100 (reset) |