Paste: Print across window
Author: | tgunr |
Mode: | factor |
Date: | Sun, 23 Dec 2012 17:43:19 |
Plain Text |
USING: accessors assocs colors.constants fonts io io.styles kernel ui.private
math math.order math.parser namespaces prettyprint.sections sequences ui.text vocabs.parser ;
IN: ui.gadgets.world
: front-window ( -- world )
windows get
[ second focused?>> ] map-find nip
second ;
: window-width ( world -- width )
dim>> first ;
IN: kernel
: 1+ ( n -- n )
1 + ;
IN: splitting
: split-nth ( seq n -- seq )
0 swap
[ drop 1 + 2dup = [ drop 0 t ] [ f ] if ] split*-when 2nip
;
IN: prettyprint
: abullet ( -- )
"•" write ;
: bullets ( n -- )
iota [ drop abullet ] each ;
: column-numbers ( n -- )
iota [ 10 mod number>string write ] each ;
: space ( -- )
"\s" write ;
: spaces ( n -- )
iota [ drop space ] each ;
<PRIVATE
: (max-length) ( seq -- seq columnSize )
0 over [ length max ] each 1+
;
: (printx) ( seq -- seq columnSize columns )
(max-length) dup
front-window window-width
swap "*" <repetition> concat monospace-font swap text-width /i
1 max
;
: (assemble-word) ( len seq -- string )
dup [ length - ] dip
[ " " <repetition> concat ] dip
prepend ;
: (assemble-line) ( colsize seq -- line )
"" -rot [ (assemble-word) append ] with each ;
PRIVATE>
: printx-split ( seq -- columnSize rows )
(printx) rot split-nth ;
: tablex ( seq -- )
printx-split nip
H{
{ font-name "monospace" }
{ font-size 9 }
{ table-border COLOR: black }
}
[
0 swap [ [ [ [ over pprint pprint 1 + ] with-cell output-stream get stream-flush ] each ] with-row ] each
drop
] tabular-output
;
: printx ( seq -- )
printx-split
H{
{ foreground COLOR: DarkRed }
}
[ [ [ (assemble-line) write nl ] with each
] with with-pprint
] with-style
;
IN: vocabs
: current-vocab-str ( -- str )
current-vocab name>> ;
: vwords ( -- )
current-vocab-str vocab-words keys
[ printx ] unless-empty ;
IN: sequences
vwords
New Annotation