factor/library/io/stdio.factor

74 lines
2.0 KiB
Factor
Raw Normal View History

2005-08-19 21:46:12 -04:00
! Copyright (C) 2003, 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: io
USING: errors generic hashtables kernel namespaces sequences
strings styles ;
2005-08-19 21:46:12 -04:00
! Default stream
2005-12-16 21:12:35 -05:00
SYMBOL: stdio
: close ( -- ) stdio get stream-close ;
: readln ( -- string/f ) stdio get stream-readln ;
: read1 ( -- char/f ) stdio get stream-read1 ;
2005-12-16 21:12:35 -05:00
: read ( count -- string ) stdio get stream-read ;
: write1 ( char -- ) stdio get stream-write1 ;
: write ( string -- ) stdio get stream-write ;
: flush ( -- ) stdio get stream-flush ;
: terpri ( -- ) stdio get stream-terpri ;
2005-08-19 21:46:12 -04:00
: format ( string style -- ) stdio get stream-format ;
2005-12-16 22:24:39 -05:00
: with-nesting ( style quot -- )
swap stdio get with-nested-stream ;
2005-12-16 21:12:35 -05:00
: tabular-output ( grid style quot -- )
-rot stdio get with-stream-table ;
2006-06-07 23:04:37 -04:00
2005-12-16 21:12:35 -05:00
: print ( string -- ) stdio get stream-print ;
2005-08-19 21:46:12 -04:00
: with-stream* ( stream quot -- )
[ swap stdio set call ] with-scope ; inline
: with-stream ( stream quot -- )
swap [ [ close ] cleanup ] with-stream* ; inline
SYMBOL: style-stack
V{ } clone style-stack set-global
2005-12-19 23:18:15 -05:00
: >style ( style -- )
dup hashtable? [ "Style must be a hashtable" throw ] unless
style-stack get push ;
2005-12-19 23:18:15 -05:00
: drop-style ( -- ) style-stack get pop* ;
: with-style ( style quot -- )
swap >style call drop-style ; inline
: with-style-stack ( quot -- )
[ V{ } clone style-stack set call ] with-scope ;
2005-12-28 20:25:17 -05:00
: current-style ( -- style )
style-stack get hash-concat ;
: format* ( string -- ) current-style format ;
: bl ( -- ) " " format* ;
2005-12-28 20:25:17 -05:00
: with-nesting* ( style quot -- )
swap [ current-style swap with-nesting ] with-style ; inline
2005-12-19 23:18:15 -05:00
: write-object ( object quot -- )
>r presented associate r> with-style ;
: simple-object ( string object -- )
[ format* ] write-object ;
: write-outliner ( content caption -- )
>r outline associate r> with-nesting* ;
: simple-outliner ( string object content -- )
[ simple-object ] write-outliner ;