[v4,1/2] Fix output word

Message ID 20180323101530.17490-2-lvivier@redhat.com
State New
Headers show
Series
  • Fix output word
Related show

Commit Message

Laurent Vivier March 23, 2018, 10:15 a.m.
We can select the console output, but it does not really work

Implement term-io-emit, as we have term-io-key to really
send characters to the output selected by stdout.

Signed-off-by: Laurent Vivier <lvivier@redhat.com>
---
 slof/fs/term-io.fs | 31 +++++++++++++++++++++++++++----
 1 file changed, 27 insertions(+), 4 deletions(-)

Patch

diff --git a/slof/fs/term-io.fs b/slof/fs/term-io.fs
index 52ce12a..d1a27aa 100644
--- a/slof/fs/term-io.fs
+++ b/slof/fs/term-io.fs
@@ -10,6 +10,14 @@ 
 \ *     IBM Corporation - initial implementation
 \ ****************************************************************************/
 
+0 VALUE write-xt
+
+VARIABLE stdout
+
+: set-stdout ( ihandle -- )
+   dup stdout !
+   encode-int s" stdout" set-chosen
+;
 
 : input  ( dev-str dev-len -- )
    open-dev ?dup IF
@@ -24,12 +32,18 @@ 
 
 : output  ( dev-str dev-len -- )
    open-dev ?dup IF
-      \ Close old stdout:
-      s" stdout" get-chosen IF
-         decode-int nip nip ?dup IF close-dev THEN
+      \ find new ihandle and xt handle
+      dup s" write" rot ihandle>phandle find-method
+      0= IF
+         drop
+         cr ." Cannot find the write method for the given output console " cr
+         EXIT
       THEN
+      \ Close old stdout:
+      stdout @ ?dup IF close-dev THEN
       \ Now set the new stdout:
-      encode-int s" stdout" set-chosen
+      to write-xt
+      set-stdout
    THEN
 ;
 
@@ -40,6 +54,15 @@ 
 
 1 BUFFER: (term-io-char-buf)
 
+: term-io-emit ( char -- )
+    write-xt 0= IF drop EXIT THEN
+    (term-io-char-buf) c!
+    (term-io-char-buf) 1 write-xt stdout @ call-package
+    drop
+;
+
+' term-io-emit to emit
+
 : term-io-key  ( -- char )
    s" stdin" get-chosen IF
       decode-int nip nip dup 0= IF 0 EXIT THEN