From: Tim Vaughan Date: Thu, 26 May 2016 10:02:39 +0000 (+1200) Subject: Added workable KEY. X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=commitdiff_plain;h=f3f77474664434c1330f74494463ea34ce148ff4;p=forth.jl.git Added workable KEY. --- diff --git a/src/forth.jl b/src/forth.jl index 6436f79..04771ea 100644 --- a/src/forth.jl +++ b/src/forth.jl @@ -620,6 +620,19 @@ EMIT = defPrimWord("EMIT", () -> begin return NEXT end) +function raw_mode!(mode::Bool) + if ccall(:jl_tty_set_mode, Int32, (Ptr{Void}, Int32), STDIN.handle, mode) != 0 + throw("FATAL: Terminal unable to enter raw mode.") + end +end + +KEY = defPrimWord("KEY", () -> begin + raw_mode!(true) + pushPS(Int(readbytes(STDIN, 1)[1])) + raw_mode!(false) + return NEXT +end) + SPAN, SPAN_CFA = defNewVar("SPAN", 0) EXPECT = defPrimWord("EXPECT", () -> begin maxLen = popPS() diff --git a/src/lib.4th b/src/lib.4th index d599036..664ff80 100644 --- a/src/lib.4th +++ b/src/lib.4th @@ -741,7 +741,7 @@ DOES> @ : HIDE BL WORD FIND DROP >NAME - DUP F_HIDDEN OR SWAP ! + DUP @ F_HIDDEN OR SWAP ! ; ( MEMORY ------------------------------------------------------------------ )