diff mbox series

[v3,2/2] resolve ihandle and xt handle in the input command (like for the output)

Message ID 20180320110735.15119-3-lvivier@redhat.com
State Superseded
Headers show
Series Fix output word | expand

Commit Message

Laurent Vivier March 20, 2018, 11:07 a.m. UTC
Signed-off-by: Laurent Vivier <lvivier@redhat.com>
---
 slof/fs/term-io.fs | 78 ++++++++++++++++++++++++++----------------------------
 1 file changed, 37 insertions(+), 41 deletions(-)
diff mbox series

Patch

diff --git a/slof/fs/term-io.fs b/slof/fs/term-io.fs
index 69ec901..07a8f6d 100644
--- a/slof/fs/term-io.fs
+++ b/slof/fs/term-io.fs
@@ -10,13 +10,19 @@ 
 \ *     IBM Corporation - initial implementation
 \ ****************************************************************************/
 
+0 value stdin-ihandle
+0 value read-xt
+
 : input  ( dev-str dev-len -- )
    open-dev ?dup IF
+      \ find new ihandle and xt handle
+      dup s" read" rot ihandle>phandle find-method
+      0= IF drop cr ." Cannot change input console " cr EXIT THEN
       \ Close old stdin:
-      s" stdin" get-chosen IF
-         decode-int nip nip ?dup IF close-dev THEN
-      THEN
+      stdin-ihandle ?dup IF close-dev THEN
       \ Now set the new stdin:
+      to read-xt
+      dup to stdin-ihandle
       encode-int s" stdin"  set-chosen
    THEN
 ;
@@ -55,17 +61,12 @@ 
 ' term-io-emit to emit
 
 : term-io-key  ( -- char )
-   s" stdin" get-chosen IF
-      decode-int nip nip dup 0= IF 0 EXIT THEN
-      >r BEGIN
-         (term-io-char-buf) 1 s" read" r@ $call-method
-         0 >
-      UNTIL
-      (term-io-char-buf) c@
-      r> drop
-   ELSE
-      [ ' key behavior compile, ]
-   THEN
+   read-xt 0= IF 0 EXIT THEN
+   BEGIN
+     (term-io-char-buf) 1 read-xt stdin-ihandle call-package
+     0 >
+   UNTIL
+   (term-io-char-buf) c@
 ;
 
 ' term-io-key to key
@@ -76,35 +77,30 @@ 
 \ - if it's an hv console, use hvterm-key?
 \ otherwise it will always return false
 : term-io-key?  ( -- true|false )
-   s" stdin" get-chosen IF
-      decode-int nip nip dup 0= IF drop 0 EXIT THEN \ return false and exit if no stdin set
-      >r \ store ihandle on return stack
-      s" device_type" r@ ihandle>phandle ( propstr len phandle )
-      get-property ( true | data dlen false )
-      IF
-         \ device_type not found, return false and exit
-         false
-      ELSE
-         1 - \ remove 1 from length to ignore null-termination char
-         \ device_type found, check wether it is serial or keyboard
-         2dup s" serial" str= IF
-	    2drop serial-key? r> drop EXIT
-	 THEN \ call serial-key, cleanup return-stack, exit
-         2dup s" keyboard" str= IF 
-            2drop ( )
-            \ keyboard found, check for key-available? method, execute it or return false 
-            s" key-available?" r@ ihandle>phandle find-method IF 
-               drop s" key-available?" r@ $call-method  
-            ELSE 
-               false 
-            THEN
-            r> drop EXIT \ cleanup return-stack, exit
+   stdin-ihandle ?dup 0= IF false EXIT THEN \ stdin not set, return false
+   >r \ store ihandle on return stack
+   s" device_type" r@ ihandle>phandle ( propstr len phandle )
+   get-property ( true | data dlen false )
+   IF
+      \ device_type not found, return false and exit
+      false
+   ELSE
+      1 - \ remove 1 from length to ignore null-termination char
+      \ device_type found, check wether it is serial or keyboard
+      2dup s" serial" str= IF
+         2drop serial-key? r> drop EXIT
+      THEN \ call serial-key, cleanup return-stack, exit
+      2dup s" keyboard" str= IF
+         2drop ( )
+         \ keyboard found, check for key-available? method, execute it or return false
+         s" key-available?" r@ ihandle>phandle find-method IF
+            drop s" key-available?" r@ $call-method
+         ELSE
+            false
          THEN
-         2drop r> drop false EXIT \ unknown device_type cleanup return-stack, return false
+         r> drop EXIT \ cleanup return-stack, exit
       THEN
-   ELSE
-      \ stdin not set, return false
-      false
+      2drop r> drop false EXIT \ unknown device_type cleanup return-stack, return false
    THEN
 ;