factor/library/io/stdio.factor

58 lines
1.5 KiB
Factor
Raw Normal View History

! Copyright (C) 2003, 2006 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
IN: io
USING: errors generic hashtables kernel namespaces sequences
strings styles ;
! Default stream
SYMBOL: stdio
: close ( -- ) stdio get stream-close ;
2006-08-16 21:55:53 -04:00
: readln ( -- str/f ) stdio get stream-readln ;
: read1 ( -- ch/f ) stdio get stream-read1 ;
: read ( n -- str/f ) stdio get stream-read ;
2006-08-16 21:55:53 -04:00
: write1 ( ch -- ) stdio get stream-write1 ;
: write ( str -- ) stdio get stream-write ;
: flush ( -- ) stdio get stream-flush ;
: terpri ( -- ) stdio get stream-terpri ;
2006-08-16 21:55:53 -04:00
: format ( str style -- ) stdio get stream-format ;
: with-nesting ( style quot -- )
swap stdio get with-nested-stream ;
: tabular-output ( grid style quot -- )
swap stdio get with-stream-table ;
: with-style ( style quot -- )
swap dup hash-empty?
[ drop call ] [ stdio get with-stream-style ] if ;
: print ( string -- ) stdio get stream-print ;
: with-stream* ( stream quot -- )
[ swap stdio set call ] with-scope ; inline
: with-stream ( stream quot -- )
swap [ [ close ] cleanup ] with-stream* ; inline
: bl ( -- ) " " write ;
2006-08-16 21:55:53 -04:00
: write-object ( str obj -- )
presented associate format ;
2006-08-16 21:55:53 -04:00
: write-outliner ( str obj content -- )
outline associate [ write-object ] with-nesting ;
2006-08-22 21:50:05 -04:00
2006-10-04 00:40:10 -04:00
: (print-input/quot)
associate [ H{ { font-style bold } } format ] with-nesting
2006-08-22 21:50:05 -04:00
terpri ;
2006-10-04 00:40:10 -04:00
: print-input ( string input -- )
<input> presented (print-input/quot) ;
: print-quot ( string quot -- )
quotation (print-input/quot) ;