Added workable KEY.
authorTim Vaughan <tgvaughan@gmail.com>
Thu, 26 May 2016 10:02:39 +0000 (22:02 +1200)
committerTim Vaughan <tgvaughan@gmail.com>
Thu, 26 May 2016 10:03:02 +0000 (22:03 +1200)
src/forth.jl
src/lib.4th

index 6436f79..04771ea 100644 (file)
@@ -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()
index d599036..664ff80 100644 (file)
@@ -741,7 +741,7 @@ DOES>   @
 
 : HIDE
         BL WORD FIND DROP >NAME
-        DUP F_HIDDEN OR SWAP !
+        DUP F_HIDDEN OR SWAP !
 ;
 
 ( MEMORY  ------------------------------------------------------------------ )