2005-06-27 00:54:49 -04:00
|
|
|
! Copyright (C) 2005 Slava Pestov.
|
|
|
|
! See http://factor.sf.net/license.txt for BSD license.
|
2005-09-01 01:20:43 -04:00
|
|
|
IN: gadgets-presentations
|
|
|
|
DEFER: <presentation>
|
|
|
|
|
2005-08-31 21:06:13 -04:00
|
|
|
IN: gadgets-panes
|
|
|
|
USING: gadgets gadgets-editors gadgets-labels gadgets-layouts
|
|
|
|
gadgets-scrolling generic hashtables io kernel line-editor lists
|
2005-08-26 21:42:43 -04:00
|
|
|
math namespaces prettyprint sequences strings styles threads
|
|
|
|
vectors ;
|
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 )
|
2005-08-31 21:06:13 -04:00
|
|
|
2vector <shelf> [ add-gadgets ] keep ;
|
2005-06-27 00:54:49 -04:00
|
|
|
|
|
|
|
: init-active-line ( pane -- )
|
2005-06-27 16:50:21 -04:00
|
|
|
dup pane-active unparent
|
2005-08-26 21:42:43 -04:00
|
|
|
[ dup pane-current swap pane-input <active-line> ] keep
|
2005-06-27 00:54:49 -04:00
|
|
|
2dup set-pane-active add-gadget ;
|
|
|
|
|
|
|
|
: pop-continuation ( pane -- quot )
|
|
|
|
dup pane-continuation f rot set-pane-continuation ;
|
|
|
|
|
2005-07-06 03:29:42 -04:00
|
|
|
: pane-eval ( string pane -- )
|
2005-08-26 00:55:56 -04:00
|
|
|
pop-continuation in-thread drop ;
|
|
|
|
|
|
|
|
SYMBOL: structured-input
|
|
|
|
|
|
|
|
: elements. ( quot -- )
|
|
|
|
[
|
2005-08-26 18:18:07 -04:00
|
|
|
2 nesting-limit set
|
2005-08-26 00:55:56 -04:00
|
|
|
5 length-limit set
|
2005-08-29 18:18:10 -04:00
|
|
|
<block pprint-elements block> newline
|
2005-08-26 00:55:56 -04:00
|
|
|
] with-pprint ;
|
2005-07-06 03:29:42 -04:00
|
|
|
|
|
|
|
: pane-call ( quot pane -- )
|
2005-08-26 00:55:56 -04:00
|
|
|
2dup [ elements. ] with-stream*
|
|
|
|
>r structured-input global set-hash
|
2005-09-03 18:44:45 -04:00
|
|
|
"\"structured-input\" \"gadgets-panes\" lookup global hash call"
|
|
|
|
r> pane-eval ;
|
2005-08-26 00:55:56 -04:00
|
|
|
|
|
|
|
: editor-commit ( editor -- line )
|
|
|
|
#! Add current line to the history, and clear the editor.
|
|
|
|
[ commit-history line-text get line-clear ] with-editor ;
|
2005-06-29 00:33:07 -04:00
|
|
|
|
|
|
|
: pane-return ( pane -- )
|
2005-08-26 00:55:56 -04:00
|
|
|
[ pane-input editor-commit ] keep
|
|
|
|
2dup stream-print pane-eval ;
|
2005-08-31 21:06:13 -04:00
|
|
|
|
|
|
|
: pane-clear ( pane -- )
|
|
|
|
dup pane-output clear-incremental pane-current clear-gadget ;
|
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 ] ]]
|
2005-08-31 21:06:13 -04:00
|
|
|
[[ [ "CTRL" "l" ] [ pane get pane-clear ] ]]
|
2005-06-27 00:54:49 -04:00
|
|
|
] swap add-actions ;
|
|
|
|
|
|
|
|
C: pane ( -- pane )
|
2005-08-31 21:06:13 -04:00
|
|
|
<pile> over set-delegate
|
|
|
|
<pile> <incremental> over add-output
|
|
|
|
<shelf> over set-pane-current
|
2005-06-27 00:54:49 -04:00
|
|
|
"" <editor> over set-pane-input
|
|
|
|
dup init-active-line
|
|
|
|
dup pane-actions ;
|
|
|
|
|
2005-07-04 18:36:07 -04:00
|
|
|
M: pane focusable-child* ( pane -- editor )
|
|
|
|
pane-input ;
|
|
|
|
|
2005-06-29 00:33:07 -04:00
|
|
|
: pane-write-1 ( style text pane -- )
|
2005-08-24 21:52:10 -04:00
|
|
|
pick not pick empty? and [
|
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
|
|
|
|
2005-08-24 21:52:10 -04:00
|
|
|
: prepare-print ( current -- gadget )
|
|
|
|
#! Optimization: if line has 1 child, add the child.
|
|
|
|
dup gadget-children {
|
|
|
|
{ [ dup empty? ] [ 2drop "" <label> ] }
|
|
|
|
{ [ dup length 1 = ] [ nip first ] }
|
|
|
|
{ [ t ] [ drop ] }
|
|
|
|
} cond ;
|
|
|
|
|
|
|
|
: pane-print-1 ( current pane -- )
|
|
|
|
>r prepare-print r> pane-output add-incremental ;
|
|
|
|
|
2005-06-27 00:54:49 -04:00
|
|
|
: pane-terpri ( pane -- )
|
2005-08-24 21:52:10 -04:00
|
|
|
dup pane-current over pane-print-1
|
2005-08-31 21:06:13 -04:00
|
|
|
<shelf> over set-pane-current init-active-line ;
|
2005-06-27 00:54:49 -04:00
|
|
|
|
|
|
|
: 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-27 20:13:11 -04:00
|
|
|
M: pane stream-flush ( pane -- ) drop ;
|
2005-06-27 16:50:21 -04:00
|
|
|
|
2005-07-27 20:13:11 -04:00
|
|
|
M: pane stream-finish ( pane -- ) drop ;
|
2005-06-27 00:54:49 -04:00
|
|
|
|
2005-07-27 20:13:11 -04:00
|
|
|
M: pane stream-readln ( pane -- line )
|
2005-06-27 00:54:49 -04:00
|
|
|
[ over set-pane-continuation stop ] callcc1 nip ;
|
|
|
|
|
2005-07-27 20:13:11 -04:00
|
|
|
M: pane stream-write1 ( char pane -- )
|
|
|
|
[ >r ch>string <label> r> pane-current add-gadget ] keep
|
|
|
|
scroll>bottom ;
|
2005-07-17 14:48:55 -04:00
|
|
|
|
2005-07-27 20:13:11 -04:00
|
|
|
M: pane stream-format ( string style pane -- )
|
2005-06-27 00:54:49 -04:00
|
|
|
[ rot "\n" split pane-write ] keep scroll>bottom ;
|
|
|
|
|
2005-07-27 20:13:11 -04:00
|
|
|
M: pane stream-close ( pane -- ) drop ;
|