]> gitweb.factorcode.org Git - factor.git/blob - core/io/stdio.factor
1fc6a7dfe14865b7bb631cc6a76e2caf2cc82538
[factor.git] / core / io / stdio.factor
1 ! Copyright (C) 2003, 2006 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 IN: io
4 USING: errors generic hashtables kernel namespaces sequences
5 strings styles ;
6
7 ! Default stream
8 SYMBOL: stdio
9
10 : close ( -- ) stdio get stream-close ;
11
12 : readln ( -- str/f ) stdio get stream-readln ;
13 : read1 ( -- ch/f ) stdio get stream-read1 ;
14 : read ( n -- str/f ) stdio get stream-read ;
15
16 : write1 ( ch -- ) stdio get stream-write1 ;
17 : write ( str -- ) stdio get stream-write ;
18 : flush ( -- ) stdio get stream-flush ;
19
20 : terpri ( -- ) stdio get stream-terpri ;
21 : format ( str style -- ) stdio get stream-format ;
22
23 : with-nesting ( style quot -- )
24     swap stdio get with-nested-stream ;
25
26 : tabular-output ( grid style quot -- )
27     swap stdio get with-stream-table ;
28
29 : with-style ( style quot -- )
30     swap dup hash-empty?
31     [ drop call ] [ stdio get with-stream-style ] if ;
32
33 : print ( string -- ) stdio get stream-print ;
34
35 : with-stream* ( stream quot -- )
36     [ swap stdio set call ] with-scope ; inline
37
38 : with-stream ( stream quot -- )
39     swap [ [ close ] cleanup ] with-stream* ; inline
40
41 : bl ( -- ) " " write ;
42
43 : write-object ( str obj -- )
44     presented associate format ;
45
46 : write-outliner ( str obj content -- )
47     outline associate [ write-object ] with-nesting ;