2009-01-08 18:02:54 -05:00
|
|
|
! Copyright (C) 2005, 2009 Slava Pestov.
|
2007-09-20 18:09:08 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2009-01-13 18:12:43 -05:00
|
|
|
USING: hashtables io io.streams.plain io.streams.string
|
|
|
|
colors summary make accessors splitting math.order
|
2009-01-15 01:52:05 -05:00
|
|
|
kernel namespaces assocs destructors strings sequences
|
2009-01-26 03:21:28 -05:00
|
|
|
present fry strings.tables ;
|
2007-09-20 18:09:08 -04:00
|
|
|
IN: io.styles
|
|
|
|
|
2009-01-13 18:12:43 -05:00
|
|
|
GENERIC: stream-format ( str style stream -- )
|
|
|
|
GENERIC: make-span-stream ( style stream -- stream' )
|
|
|
|
GENERIC: make-block-stream ( style stream -- stream' )
|
|
|
|
GENERIC: make-cell-stream ( style stream -- stream' )
|
|
|
|
GENERIC: stream-write-table ( table-cells style stream -- )
|
|
|
|
|
|
|
|
: format ( str style -- ) output-stream get stream-format ;
|
|
|
|
|
|
|
|
: tabular-output ( style quot -- )
|
|
|
|
swap [ { } make ] dip output-stream get stream-write-table ; inline
|
|
|
|
|
|
|
|
: with-row ( quot -- )
|
|
|
|
{ } make , ; inline
|
|
|
|
|
|
|
|
: with-cell ( quot -- )
|
|
|
|
H{ } output-stream get make-cell-stream
|
|
|
|
[ swap with-output-stream ] keep , ; inline
|
|
|
|
|
|
|
|
: write-cell ( str -- )
|
|
|
|
[ write ] with-cell ; inline
|
|
|
|
|
|
|
|
: with-style ( style quot -- )
|
|
|
|
swap dup assoc-empty? [
|
|
|
|
drop call
|
|
|
|
] [
|
|
|
|
output-stream get make-span-stream swap with-output-stream
|
|
|
|
] if ; inline
|
|
|
|
|
|
|
|
: with-nesting ( style quot -- )
|
|
|
|
[ output-stream get make-block-stream ] dip
|
|
|
|
with-output-stream ; inline
|
|
|
|
|
|
|
|
TUPLE: filter-writer stream ;
|
|
|
|
|
|
|
|
M: filter-writer stream-format
|
|
|
|
stream>> stream-format ;
|
|
|
|
|
|
|
|
M: filter-writer stream-write
|
|
|
|
stream>> stream-write ;
|
|
|
|
|
|
|
|
M: filter-writer stream-write1
|
|
|
|
stream>> stream-write1 ;
|
|
|
|
|
|
|
|
M: filter-writer make-span-stream
|
|
|
|
stream>> make-span-stream ;
|
|
|
|
|
|
|
|
M: filter-writer make-block-stream
|
|
|
|
stream>> make-block-stream ;
|
|
|
|
|
|
|
|
M: filter-writer make-cell-stream
|
|
|
|
stream>> make-cell-stream ;
|
|
|
|
|
|
|
|
M: filter-writer stream-flush
|
|
|
|
stream>> stream-flush ;
|
|
|
|
|
|
|
|
M: filter-writer stream-nl
|
|
|
|
stream>> stream-nl ;
|
|
|
|
|
|
|
|
M: filter-writer stream-write-table
|
|
|
|
stream>> stream-write-table ;
|
|
|
|
|
|
|
|
M: filter-writer dispose
|
|
|
|
stream>> dispose ;
|
|
|
|
|
|
|
|
TUPLE: ignore-close-stream < filter-writer ;
|
|
|
|
|
|
|
|
M: ignore-close-stream dispose drop ;
|
|
|
|
|
|
|
|
C: <ignore-close-stream> ignore-close-stream
|
|
|
|
|
|
|
|
TUPLE: style-stream < filter-writer style ;
|
|
|
|
|
|
|
|
: do-nested-style ( style style-stream -- style stream )
|
|
|
|
[ style>> swap assoc-union ] [ stream>> ] bi ; inline
|
|
|
|
|
|
|
|
C: <style-stream> style-stream
|
|
|
|
|
|
|
|
M: style-stream stream-format
|
|
|
|
do-nested-style stream-format ;
|
|
|
|
|
|
|
|
M: style-stream stream-write
|
|
|
|
[ style>> ] [ stream>> ] bi stream-format ;
|
|
|
|
|
|
|
|
M: style-stream stream-write1
|
|
|
|
[ 1string ] dip stream-write ;
|
|
|
|
|
|
|
|
M: style-stream make-span-stream
|
|
|
|
do-nested-style make-span-stream ;
|
|
|
|
|
|
|
|
M: style-stream make-block-stream
|
|
|
|
[ do-nested-style make-block-stream ] [ style>> ] bi
|
|
|
|
<style-stream> ;
|
|
|
|
|
|
|
|
M: style-stream make-cell-stream
|
|
|
|
[ do-nested-style make-cell-stream ] [ style>> ] bi
|
|
|
|
<style-stream> ;
|
|
|
|
|
|
|
|
M: style-stream stream-write-table
|
|
|
|
[ [ [ stream>> ] map ] map ] [ ] [ stream>> ] tri*
|
|
|
|
stream-write-table ;
|
|
|
|
|
|
|
|
M: plain-writer stream-format
|
|
|
|
nip stream-write ;
|
|
|
|
|
|
|
|
M: plain-writer make-span-stream
|
|
|
|
swap <style-stream> <ignore-close-stream> ;
|
|
|
|
|
|
|
|
M: plain-writer make-block-stream
|
|
|
|
nip <ignore-close-stream> ;
|
|
|
|
|
|
|
|
M: plain-writer stream-write-table
|
|
|
|
[ drop format-table [ print ] each ] with-output-stream* ;
|
|
|
|
|
|
|
|
M: plain-writer make-cell-stream 2drop <string-writer> ;
|
|
|
|
|
|
|
|
! Font styles
|
2007-09-20 18:09:08 -04:00
|
|
|
SYMBOL: plain
|
|
|
|
SYMBOL: bold
|
|
|
|
SYMBOL: italic
|
|
|
|
SYMBOL: bold-italic
|
|
|
|
|
|
|
|
! Character styles
|
|
|
|
SYMBOL: foreground
|
|
|
|
SYMBOL: background
|
2009-01-26 17:25:57 -05:00
|
|
|
SYMBOL: font-name
|
2007-09-20 18:09:08 -04:00
|
|
|
SYMBOL: font-size
|
|
|
|
SYMBOL: font-style
|
|
|
|
|
|
|
|
! Presentation
|
|
|
|
SYMBOL: presented
|
|
|
|
|
2008-09-29 05:09:02 -04:00
|
|
|
SYMBOL: href
|
|
|
|
|
2007-09-20 18:09:08 -04:00
|
|
|
! Paragraph styles
|
|
|
|
SYMBOL: page-color
|
|
|
|
SYMBOL: border-color
|
|
|
|
SYMBOL: border-width
|
|
|
|
SYMBOL: wrap-margin
|
|
|
|
|
|
|
|
! Table styles
|
|
|
|
SYMBOL: table-gap
|
|
|
|
SYMBOL: table-border
|
|
|
|
|
|
|
|
: standard-table-style ( -- style )
|
|
|
|
H{
|
|
|
|
{ table-gap { 5 5 } }
|
2008-08-01 16:11:42 -04:00
|
|
|
{ table-border T{ rgba f 0.8 0.8 0.8 1.0 } }
|
2007-09-20 18:09:08 -04:00
|
|
|
} ;
|
|
|
|
|
|
|
|
! Input history
|
|
|
|
TUPLE: input string ;
|
|
|
|
|
|
|
|
C: <input> input
|
2008-07-28 23:28:13 -04:00
|
|
|
|
2009-01-15 01:52:05 -05:00
|
|
|
M: input present string>> ;
|
|
|
|
|
2008-12-08 15:58:00 -05:00
|
|
|
M: input summary
|
|
|
|
[
|
|
|
|
"Input: " %
|
2009-01-25 23:56:47 -05:00
|
|
|
string>> "\n" split1
|
|
|
|
[ % ] [ "..." "" ? % ] bi*
|
2008-12-08 15:58:00 -05:00
|
|
|
] "" make ;
|
|
|
|
|
2008-07-28 23:28:13 -04:00
|
|
|
: write-object ( str obj -- ) presented associate format ;
|