2005-01-30 15:57:25 -05:00
|
|
|
! Copyright (C) 2003, 2005 Slava Pestov.
|
|
|
|
! See http://factor.sf.net/license.txt for BSD license.
|
2005-06-19 17:50:35 -04:00
|
|
|
IN: io
|
2005-07-11 22:47:38 -04:00
|
|
|
USING: errors generic kernel lists namespaces strings styles ;
|
2004-11-28 21:56:58 -05:00
|
|
|
|
2005-02-14 22:15:02 -05:00
|
|
|
: flush ( -- ) stdio get stream-flush ;
|
|
|
|
: read-line ( -- string ) stdio get stream-readln ;
|
2005-07-19 22:29:57 -04:00
|
|
|
: read1 ( -- char/f ) stdio get stream-read1 ;
|
2005-02-14 22:15:02 -05:00
|
|
|
: read ( count -- string ) stdio get stream-read ;
|
|
|
|
: write ( string -- ) stdio get stream-write ;
|
2005-07-17 14:48:55 -04:00
|
|
|
: write1 ( char -- ) stdio get stream-write1 ;
|
2005-02-14 22:15:02 -05:00
|
|
|
: write-attr ( string style -- ) stdio get stream-write-attr ;
|
|
|
|
: print ( string -- ) stdio get stream-print ;
|
2004-11-28 21:56:58 -05:00
|
|
|
: terpri ( -- ) "\n" write ;
|
2005-05-02 00:18:34 -04:00
|
|
|
: crlf ( -- ) "\r\n" write ;
|
|
|
|
: bl ( -- ) " " write ;
|
2005-02-14 22:15:02 -05:00
|
|
|
: close ( -- ) stdio get stream-close ;
|
2004-07-16 02:26:21 -04:00
|
|
|
|
2004-08-30 20:24:19 -04:00
|
|
|
: write-icon ( resource -- )
|
|
|
|
#! Write an icon. Eg, /library/icons/File.png
|
2005-07-11 22:47:38 -04:00
|
|
|
icon swons unit "" swap write-attr ;
|
2004-08-30 20:24:19 -04:00
|
|
|
|
2004-07-16 02:26:21 -04:00
|
|
|
: with-stream ( stream quot -- )
|
2005-05-02 00:18:34 -04:00
|
|
|
#! Close the stream no matter what happends.
|
2004-11-29 23:14:12 -05:00
|
|
|
[ swap stdio set [ close rethrow ] catch ] with-scope ;
|
2004-08-22 01:46:26 -04:00
|
|
|
|
2005-05-02 00:18:34 -04:00
|
|
|
: with-stream* ( stream quot -- )
|
|
|
|
#! Close the stream if there is an error.
|
|
|
|
[
|
|
|
|
swap stdio set
|
|
|
|
[ [ close rethrow ] when* ] catch
|
|
|
|
] with-scope ;
|