1 USING: sequences kernel namespaces make splitting math math.order ;
4 ! Very stupid word wrapping/line breaking
5 ! This will be replaced by a Unicode-aware method,
6 ! which works with variable-width fonts
10 : line-chunks ( string -- words-lines )
11 "\n" split [ " \t" split harvest ] map ;
13 : (split-chunk) ( words -- )
14 -1 over [ length + 1+ dup width get > ] find drop nip
15 [ 1 max cut-slice swap , (split-chunk) ] [ , ] if* ;
17 : split-chunk ( words -- lines )
18 [ (split-chunk) ] { } make ;
20 : join-spaces ( words-seqs -- lines )
21 [ [ " " join ] map ] map concat ;
23 : broken-lines ( string width -- lines )
25 line-chunks [ split-chunk ] map join-spaces
28 : line-break ( string width -- newstring )
29 broken-lines "\n" join ;
31 : indented-break ( string width indent -- newstring )
32 [ length - broken-lines ] keep [ prepend ] curry map "\n" join ;