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-10-03 18:17:21 -04:00
|
|
|
USING: arrays definitions gadgets gadgets-panes
|
2006-08-24 23:19:22 -04:00
|
|
|
generic hashtables help io kernel namespaces prettyprint styles
|
2006-10-10 02:47:58 -04:00
|
|
|
threads sequences vectors definitions parser words strings
|
|
|
|
math ;
|
2006-07-19 18:46:33 -04:00
|
|
|
|
2006-08-24 00:45:58 -04:00
|
|
|
TUPLE: interactor history output continuation queue busy? ;
|
2006-07-19 18:46:33 -04:00
|
|
|
|
|
|
|
C: interactor ( output -- gadget )
|
|
|
|
[ set-interactor-output ] keep
|
2006-10-06 04:15:34 -04:00
|
|
|
<editor> over set-gadget-delegate
|
2006-08-24 00:45:58 -04:00
|
|
|
V{ } clone over set-interactor-history
|
2006-07-21 18:07:26 -04:00
|
|
|
dup dup set-control-self ;
|
2006-07-19 18:46:33 -04:00
|
|
|
|
2006-08-15 03:01:24 -04:00
|
|
|
M: interactor graft*
|
2006-07-31 16:49:26 -04:00
|
|
|
f over set-interactor-busy? delegate graft* ;
|
|
|
|
|
2006-08-24 00:45:58 -04:00
|
|
|
: (interactor-eval) ( string interactor -- )
|
2006-07-31 16:49:26 -04:00
|
|
|
dup interactor-busy? [
|
|
|
|
2drop
|
|
|
|
] [
|
2006-07-31 16:50:40 -04:00
|
|
|
t over set-interactor-busy?
|
2006-08-19 15:33:55 -04:00
|
|
|
swap "\n" split <reversed> >vector
|
|
|
|
over set-interactor-queue
|
|
|
|
interactor-continuation schedule-thread
|
2006-07-31 16:49:26 -04:00
|
|
|
] if ;
|
2006-07-19 18:46:33 -04:00
|
|
|
|
2006-07-31 16:50:40 -04:00
|
|
|
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"
|
2006-08-24 00:45:58 -04:00
|
|
|
r> (interactor-eval) ;
|
2006-07-31 16:50:40 -04:00
|
|
|
|
2006-08-22 21:50:05 -04:00
|
|
|
: interactor-input. ( string interactor -- )
|
|
|
|
interactor-output [ dup print-input ] with-stream* ;
|
2006-07-19 18:46:33 -04:00
|
|
|
|
2006-08-24 00:45:58 -04:00
|
|
|
: interactor-eval ( string interactor -- )
|
|
|
|
dup control-model clear-doc
|
|
|
|
2dup interactor-history push-new
|
|
|
|
2dup interactor-input.
|
|
|
|
(interactor-eval) ;
|
|
|
|
|
2006-07-31 16:49:26 -04:00
|
|
|
: interactor-commit ( interactor -- )
|
|
|
|
dup interactor-busy? [
|
|
|
|
drop
|
|
|
|
] [
|
2006-10-06 04:15:34 -04:00
|
|
|
[ editor-text ] keep interactor-eval
|
2006-08-24 00:45:58 -04:00
|
|
|
] if ;
|
|
|
|
|
2006-08-15 03:01:24 -04:00
|
|
|
M: interactor stream-readln
|
2006-08-19 15:33:55 -04:00
|
|
|
dup interactor-queue empty? [
|
|
|
|
f over set-interactor-busy?
|
|
|
|
[ over set-interactor-continuation stop ] callcc0
|
|
|
|
] when interactor-queue pop ;
|
2006-09-19 02:30:21 -04:00
|
|
|
|
2006-10-10 01:28:21 -04:00
|
|
|
M: interactor stream-read
|
|
|
|
swap dup zero?
|
|
|
|
[ 2drop "" ] [ >r stream-readln r> head ] if ;
|
|
|
|
|
2006-10-09 23:57:32 -04:00
|
|
|
interactor "interactor" {
|
2006-09-20 03:22:26 -04:00
|
|
|
{ "Evaluate" T{ key-down f f "RETURN" } [ interactor-commit ] }
|
2006-10-05 17:15:41 -04:00
|
|
|
{ "Clear input" T{ key-down f { C+ } "k" } [ control-model clear-doc ] }
|
2006-09-19 02:30:21 -04:00
|
|
|
} define-commands
|