[v3,1/2] Fix output word

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

Commit Message

Laurent Vivier March 20, 2018, 11:07 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 | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

Comments

Segher Boessenkool March 20, 2018, 12:12 p.m. | #1
Hi!

On Tue, Mar 20, 2018 at 12:07:34PM +0100, Laurent Vivier wrote:
>  : output  ( dev-str dev-len -- )
>     open-dev ?dup IF
> +      \ find new ihandle and xt handle
> +      dup s" write" rot ihandle>phandle find-method
> +      0= IF drop cr ." Cannot change output console " cr EXIT THEN
>        \ Close old stdout:
> -      s" stdout" get-chosen IF
> -         decode-int nip nip ?dup IF close-dev THEN
> -      THEN
> +      stdout-ihandle ?dup IF close-dev THEN
>        \ Now set the new stdout:
> +      to write-xt
> +      dup to stdout-ihandle
>        encode-int s" stdout" set-chosen
>     THEN
>  ;

The ihandle variables should be called stdin and stdout, and be variables
(not values).  These are standard words.

Things can be factored better with e.g. a
  : set-stdout ( ihandle -- )
method (that also handles setting the /chosen thing).  Or you could
make the /chosen property use the actual same stdout variable.

In general, if a word is too long, factor it, don't make it spaghetti :-)

The error messages could be more specific (say *what* is wrong).


Segher

Patch

diff --git a/slof/fs/term-io.fs b/slof/fs/term-io.fs
index 52ce12a..69ec901 100644
--- a/slof/fs/term-io.fs
+++ b/slof/fs/term-io.fs
@@ -10,7 +10,6 @@ 
 \ *     IBM Corporation - initial implementation
 \ ****************************************************************************/
 
-
 : input  ( dev-str dev-len -- )
    open-dev ?dup IF
       \ Close old stdin:
@@ -22,13 +21,19 @@ 
    THEN
 ;
 
+0 VALUE stdout-ihandle
+0 VALUE write-xt
+
 : output  ( dev-str dev-len -- )
    open-dev ?dup IF
+      \ find new ihandle and xt handle
+      dup s" write" rot ihandle>phandle find-method
+      0= IF drop cr ." Cannot change output console " cr EXIT THEN
       \ Close old stdout:
-      s" stdout" get-chosen IF
-         decode-int nip nip ?dup IF close-dev THEN
-      THEN
+      stdout-ihandle ?dup IF close-dev THEN
       \ Now set the new stdout:
+      to write-xt
+      dup to stdout-ihandle
       encode-int s" stdout" set-chosen
    THEN
 ;
@@ -40,6 +45,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-ihandle 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