2005-06-27 00:54:49 -04:00
|
|
|
! Copyright (C) 2005 Slava Pestov.
|
|
|
|
! See http://factor.sf.net/license.txt for BSD license.
|
|
|
|
IN: gadgets
|
2005-06-27 16:50:21 -04:00
|
|
|
USING: generic hashtables io kernel line-editor listener lists
|
|
|
|
math namespaces prettyprint sequences strings styles threads ;
|
2005-06-27 00:54:49 -04:00
|
|
|
|
|
|
|
! A pane is an area that can display text.
|
|
|
|
|
|
|
|
! output: pile
|
|
|
|
! current: shelf
|
|
|
|
! input: editor
|
|
|
|
TUPLE: pane output active current input continuation ;
|
|
|
|
|
|
|
|
: add-output 2dup set-pane-output add-gadget ;
|
2005-06-27 16:50:21 -04:00
|
|
|
|
2005-06-27 00:54:49 -04:00
|
|
|
: add-input 2dup set-pane-input add-gadget ;
|
|
|
|
|
|
|
|
: <active-line> ( input current -- line )
|
|
|
|
<line-shelf> [ add-gadget ] keep [ add-gadget ] keep ;
|
|
|
|
|
|
|
|
: init-active-line ( pane -- )
|
2005-06-27 16:50:21 -04:00
|
|
|
dup pane-active unparent
|
2005-06-27 00:54:49 -04:00
|
|
|
[ dup pane-input swap pane-current <active-line> ] keep
|
|
|
|
2dup set-pane-active add-gadget ;
|
|
|
|
|
|
|
|
: pane-paint ( pane -- )
|
2005-06-27 03:47:22 -04:00
|
|
|
"Monospaced" font set-paint-prop ;
|
2005-06-27 00:54:49 -04:00
|
|
|
|
|
|
|
: pop-continuation ( pane -- quot )
|
|
|
|
dup pane-continuation f rot set-pane-continuation ;
|
|
|
|
|
2005-06-29 00:33:07 -04:00
|
|
|
: pane-eval ( line pane -- )
|
2005-06-27 00:54:49 -04:00
|
|
|
2dup stream-write "\n" over stream-write
|
|
|
|
pop-continuation in-thread drop ;
|
2005-06-29 00:33:07 -04:00
|
|
|
|
|
|
|
: pane-return ( pane -- )
|
|
|
|
[
|
|
|
|
pane-input
|
|
|
|
[ commit-history line-text get line-clear ] with-editor
|
|
|
|
] keep pane-eval ;
|
2005-06-27 00:54:49 -04:00
|
|
|
|
|
|
|
: pane-actions ( line -- )
|
|
|
|
[
|
|
|
|
[[ [ button-down 1 ] [ pane-input click-editor ] ]]
|
|
|
|
[[ [ "RETURN" ] [ pane-return ] ]]
|
|
|
|
[[ [ "UP" ] [ pane-input [ history-prev ] with-editor ] ]]
|
|
|
|
[[ [ "DOWN" ] [ pane-input [ history-next ] with-editor ] ]]
|
|
|
|
] swap add-actions ;
|
|
|
|
|
|
|
|
C: pane ( -- pane )
|
|
|
|
<line-pile> over set-delegate
|
|
|
|
<line-pile> over add-output
|
|
|
|
"" <label> over set-pane-current
|
|
|
|
"" <editor> over set-pane-input
|
|
|
|
dup init-active-line
|
|
|
|
dup pane-paint
|
|
|
|
dup pane-actions ;
|
|
|
|
|
2005-06-29 00:33:07 -04:00
|
|
|
: pane-write-1 ( style text pane -- )
|
|
|
|
[ <presentation> ] keep pane-current add-gadget ;
|
2005-06-27 00:54:49 -04:00
|
|
|
|
|
|
|
: pane-terpri ( pane -- )
|
|
|
|
dup pane-current over pane-output add-gadget
|
|
|
|
<line-shelf> over set-pane-current init-active-line ;
|
|
|
|
|
|
|
|
: pane-write ( style pane list -- )
|
2005-06-29 00:33:07 -04:00
|
|
|
3dup car swap pane-write-1 cdr dup
|
2005-06-27 00:54:49 -04:00
|
|
|
[ over pane-terpri pane-write ] [ 3drop ] ifte ;
|
|
|
|
|
|
|
|
! Panes are streams.
|
|
|
|
M: pane stream-flush ( stream -- ) relayout ;
|
2005-06-27 16:50:21 -04:00
|
|
|
|
2005-06-27 00:54:49 -04:00
|
|
|
M: pane stream-auto-flush ( stream -- ) stream-flush ;
|
|
|
|
|
|
|
|
M: pane stream-readln ( stream -- line )
|
|
|
|
[ over set-pane-continuation stop ] callcc1 nip ;
|
|
|
|
|
|
|
|
M: pane stream-write-attr ( string style stream -- )
|
|
|
|
[ rot "\n" split pane-write ] keep scroll>bottom ;
|
|
|
|
|
|
|
|
M: pane stream-close ( stream -- ) drop ;
|
|
|
|
|
|
|
|
: <console> ( -- pane )
|
|
|
|
<pane> dup
|
|
|
|
[ [ clear print-banner listener ] in-thread ] with-stream
|
|
|
|
<scroller> ;
|