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
|
|
|
|
2005-07-13 22:51:43 -04:00
|
|
|
DEFER: <presentation>
|
|
|
|
|
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-07-06 03:29:42 -04:00
|
|
|
: pane-eval ( string pane -- )
|
|
|
|
2dup stream-print pop-continuation in-thread drop ;
|
|
|
|
|
|
|
|
: pane-call ( quot pane -- )
|
|
|
|
[ "(Structured input) " write dup . call ] with-stream* ;
|
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
|
2005-07-09 16:08:50 -04:00
|
|
|
<line-pile> <incremental> over add-output
|
2005-07-04 18:36:07 -04:00
|
|
|
<line-shelf> over set-pane-current
|
2005-06-27 00:54:49 -04:00
|
|
|
"" <editor> over set-pane-input
|
|
|
|
dup init-active-line
|
|
|
|
dup pane-paint
|
|
|
|
dup pane-actions ;
|
|
|
|
|
2005-07-04 18:36:07 -04:00
|
|
|
M: pane focusable-child* ( pane -- editor )
|
|
|
|
pane-input ;
|
|
|
|
|
2005-07-14 00:32:52 -04:00
|
|
|
: pane-clear ( pane -- )
|
|
|
|
dup pane-output clear-incremental pane-current clear-gadget ;
|
|
|
|
|
2005-07-19 22:29:57 -04:00
|
|
|
: pane-ignore? ( style text pane -- ? )
|
|
|
|
#! If we already have stuff in the current pack, and there
|
|
|
|
#! is no style information or text to write, ignore it.
|
|
|
|
#! Otherwise, we either have a fancy style (like an icon
|
|
|
|
#! or gadget being output), or we want the current pack to
|
|
|
|
#! have a minimal height so we put the empty label there.
|
|
|
|
pane-current gadget-children empty? not
|
|
|
|
rot not and swap empty? and ;
|
|
|
|
|
2005-06-29 00:33:07 -04:00
|
|
|
: pane-write-1 ( style text pane -- )
|
2005-07-19 22:29:57 -04:00
|
|
|
3dup pane-ignore? [
|
2005-07-19 17:51:59 -04:00
|
|
|
3drop
|
|
|
|
] [
|
|
|
|
>r <presentation> r> pane-current add-gadget
|
|
|
|
] ifte ;
|
2005-06-27 00:54:49 -04:00
|
|
|
|
|
|
|
: pane-terpri ( pane -- )
|
2005-07-09 16:08:50 -04:00
|
|
|
dup pane-current over pane-output add-incremental
|
2005-06-27 00:54:49 -04:00
|
|
|
<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.
|
2005-07-08 01:32:29 -04:00
|
|
|
M: pane stream-flush ( stream -- ) drop ;
|
2005-06-27 16:50:21 -04:00
|
|
|
|
2005-07-21 21:05:17 -04:00
|
|
|
M: pane stream-finish ( stream -- ) drop ;
|
2005-06-27 00:54:49 -04:00
|
|
|
|
|
|
|
M: pane stream-readln ( stream -- line )
|
|
|
|
[ over set-pane-continuation stop ] callcc1 nip ;
|
|
|
|
|
2005-07-17 14:48:55 -04:00
|
|
|
M: pane stream-write1 ( string style stream -- )
|
|
|
|
[ rot ch>string unit pane-write ] keep scroll>bottom ;
|
|
|
|
|
2005-07-21 21:43:37 -04:00
|
|
|
M: pane stream-format ( string style stream -- )
|
2005-06-27 00:54:49 -04:00
|
|
|
[ rot "\n" split pane-write ] keep scroll>bottom ;
|
|
|
|
|
|
|
|
M: pane stream-close ( stream -- ) drop ;
|