factor/library/ui/text/interactor.factor

49 lines
1.4 KiB
Factor
Raw Normal View History

! Copyright (C) 2006 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
IN: gadgets-text
2006-07-25 00:14:59 -04:00
USING: gadgets gadgets-controls gadgets-panes hashtables help io
kernel namespaces prettyprint styles threads ;
TUPLE: interactor output continuation ;
C: interactor ( output -- gadget )
[ set-interactor-output ] keep
2006-07-27 19:46:21 -04:00
f <field> over set-gadget-delegate
dup dup set-control-self ;
: interactor-eval ( string gadget -- )
interactor-continuation dup
2006-07-23 21:38:58 -04:00
[ [ continue-with ] in-thread ] when 2drop ;
SYMBOL: structured-input
: interactor-call ( quot gadget -- )
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 ;
: 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
] with-stream* ;
: interactor-commit ( gadget -- )
dup field-commit
2006-07-25 00:14:59 -04:00
over control-model clear-doc
swap 2dup print-input interactor-eval ;
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 ] }
{ T{ key-down f { C+ } "d" } [ f swap interactor-eval ] }
} set-gestures
M: interactor stream-readln ( pane -- line )
[ over set-interactor-continuation stop ] callcc1 nip ;