2006-07-19 18:46:33 -04:00
|
|
|
! Copyright (C) 2006 Slava Pestov.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
|
|
|
IN: gadgets-text
|
2006-07-31 16:49:26 -04:00
|
|
|
USING: gadgets gadgets-controls gadgets-panes generic hashtables
|
|
|
|
help io kernel namespaces prettyprint styles threads ;
|
2006-07-19 18:46:33 -04:00
|
|
|
|
2006-07-31 16:49:26 -04:00
|
|
|
TUPLE: interactor output continuation busy? ;
|
2006-07-19 18:46:33 -04:00
|
|
|
|
|
|
|
C: interactor ( output -- gadget )
|
|
|
|
[ set-interactor-output ] keep
|
2006-07-27 19:46:21 -04:00
|
|
|
f <field> over set-gadget-delegate
|
2006-07-21 18:07:26 -04:00
|
|
|
dup dup set-control-self ;
|
2006-07-19 18:46:33 -04:00
|
|
|
|
2006-07-31 16:49:26 -04:00
|
|
|
M: interactor graft* ( interactor -- )
|
|
|
|
f over set-interactor-busy? delegate graft* ;
|
|
|
|
|
|
|
|
: interactor-eval ( string interactor -- )
|
|
|
|
t over set-interactor-busy?
|
|
|
|
interactor-continuation schedule-thread-with ;
|
2006-07-19 18:46:33 -04:00
|
|
|
|
|
|
|
SYMBOL: structured-input
|
|
|
|
|
|
|
|
: interactor-call ( quot gadget -- )
|
2006-07-31 16:49:26 -04:00
|
|
|
dup interactor-busy? [
|
|
|
|
2drop
|
|
|
|
] [
|
|
|
|
dup interactor-output [
|
|
|
|
"Command: " write over short.
|
|
|
|
] with-stream*
|
|
|
|
>r structured-input set-global
|
|
|
|
"\"structured-input\" \"gadgets-text\" lookup get-global call"
|
|
|
|
r> interactor-eval
|
|
|
|
] if ;
|
2006-07-19 18:46:33 -04:00
|
|
|
|
|
|
|
: print-input ( string interactor -- )
|
|
|
|
interactor-output [
|
2006-07-25 00:14:59 -04:00
|
|
|
H{ { font-style bold } } [
|
|
|
|
dup <input> presented associate
|
|
|
|
[ write ] with-nesting terpri
|
|
|
|
] with-style
|
2006-07-19 18:46:33 -04:00
|
|
|
] with-stream* ;
|
|
|
|
|
2006-07-31 16:49:26 -04:00
|
|
|
: interactor-commit ( interactor -- )
|
|
|
|
dup interactor-busy? [
|
|
|
|
drop
|
|
|
|
] [
|
|
|
|
dup field-commit
|
|
|
|
over control-model clear-doc
|
|
|
|
swap 2dup print-input interactor-eval
|
|
|
|
] if ;
|
2006-07-19 18:46:33 -04:00
|
|
|
|
|
|
|
interactor H{
|
|
|
|
{ T{ key-down f f "RETURN" } [ interactor-commit ] }
|
2006-07-22 05:11:19 -04:00
|
|
|
{ T{ key-down f { C+ } "b" } [ interactor-output pane-clear ] }
|
2006-07-20 00:45:56 -04:00
|
|
|
{ T{ key-down f { C+ } "d" } [ f swap interactor-eval ] }
|
2006-07-19 18:46:33 -04:00
|
|
|
} set-gestures
|
|
|
|
|
2006-07-31 16:49:26 -04:00
|
|
|
M: interactor stream-readln ( interactor -- line )
|
|
|
|
f over set-interactor-busy?
|
2006-07-19 18:46:33 -04:00
|
|
|
[ over set-interactor-continuation stop ] callcc1 nip ;
|