aboutsummaryrefslogtreecommitdiff
path: root/slof/fs/term-io.fs
blob: d352b9ebadfdbc45deaec1cfb5e1736f034ce3a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
\ *****************************************************************************
\ * Copyright (c) 2004, 2007 IBM Corporation
\ * All rights reserved.
\ * This program and the accompanying materials
\ * are made available under the terms of the BSD License
\ * which accompanies this distribution, and is available at
\ * http://www.opensource.org/licenses/bsd-license.php
\ *
\ * Contributors:
\ *     IBM Corporation - initial implementation
\ ****************************************************************************/


: input  ( dev-str dev-len -- )
   open-dev ?dup IF
      \ Close old stdin:
      s" stdin" get-chosen IF
         decode-int nip nip ?dup IF close-dev THEN
      THEN
      \ Now set the new stdin:
      encode-int s" stdin"  set-chosen
   THEN
;

: 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
      THEN
      \ Now set the new stdout:
      encode-int s" stdout" set-chosen
   THEN
;

: io  ( dev-str dev-len -- )
   2dup input output
;


1 BUFFER: (term-io-char-buf)

: 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
   THEN
;

' term-io-key to key

\ TODO: Implement: ' term-io-key? to key?