Simplify listener

slava 2006-08-25 03:06:07 +00:00
parent 63403999df
commit 16cd70a8fe
5 changed files with 37 additions and 55 deletions

View File

@ -5,8 +5,8 @@ new browser:
- scroll to existing won't work
- initial scroll dim is wrong
- show callers
listener:
- show IN:
- alternative way to invoke 2/3 buttons on one-button mice using modifiers
- list of key bindings
- RT_WORD should refer to XTs not word objects.
- services do not launch if factor not running

View File

@ -1,6 +1,6 @@
USING: definitions errors help image inspector io kernel
listener memory modules parser prettyprint sequences test
words jedit ;
words jedit shells ;
ARTICLE: "tools" "Development tools"
"This section covers words which are used during development, and not usually invoked directly by user code."
@ -36,10 +36,9 @@ $terpri
"Note that calls to " { $link .s } " can also be included inside words as a debugging aid, however a more convenient way to achieve this is to use the annotation facility. See " { $link "annotations" } "."
$terpri
"You can start a nested listener or exit a listener using the following words:"
{ $subsection listener }
{ $subsection tty }
{ $subsection bye }
"The following variables can be rebound inside a nested scope to customize the behavior of a listener; this can be done to create a development tool with a custom interaction loop:"
{ $subsection listener-prompt }
{ $subsection listener-hook }
"Finally, the multi-line expression reading word can be used independently of the rest of the listener:"
{ $subsection read-multiline } ;

View File

@ -19,27 +19,21 @@ SYMBOL: inspector-stack
dup summary print
sheet sheet-numbers sheet. ;
: inspector-help ( -- )
terpri
"Object inspector." print
terpri
"inspecting ( -- obj ) push current object" print
"go ( n -- ) inspect nth slot" print
"up -- return to previous object" print
"bye -- exit inspector" print ;
: inspector ( obj -- )
[
inspector-help
terpri
"inspector " listener-prompt set
V{ } clone inspector-stack set
(inspect)
] listener ;
: inspect ( obj -- )
inspector-stack get [ (inspect) ] [ inspector ] if ;
: go ( n -- ) 1- inspector-slots get nth (inspect) ;
: up ( -- ) inspector-stack get dup pop* pop (inspect) ;
: inspector-help ( -- )
"Object inspector." print
terpri
"up -- return to previous object" [ up ] print-input
"inspecting ( -- obj ) push current object" [ inspecting ] print-input
"go ( n -- ) inspect nth slot" print ;
: inspector ( obj -- )
inspector-help
V{ } clone inspector-stack set
(inspect) ;
: inspect ( obj -- )
inspector-stack get [ (inspect) ] [ inspector ] if ;

View File

@ -4,13 +4,8 @@ IN: listener
USING: errors hashtables io kernel math memory namespaces
parser sequences strings styles vectors words ;
SYMBOL: listener-prompt
SYMBOL: quit-flag
SYMBOL: listener-hook
SYMBOL: eval-hook
"ok " listener-prompt set-global
: bye ( -- ) quit-flag on ;
@ -31,21 +26,13 @@ SYMBOL: eval-hook
] with-parser in set ;
: listen ( -- )
listener-prompt get write flush [
in get write "> " write flush [
listener-hook get call
read-multiline [ eval-hook get call ] [ drop bye ] if
read-multiline [ call ] [ drop bye ] if
] try ;
: (listener) ( -- )
quit-flag get [ quit-flag off ] [ listen (listener) ] if ;
: listener ( quot -- )
[
use [ clone ] change
[ call ] eval-hook set
call
(listener)
] with-scope ;
: listener ( -- )
quit-flag get [ quit-flag off ] [ listen listener ] if ;
: print-banner ( -- )
"Factor " write version write
@ -53,7 +40,12 @@ SYMBOL: eval-hook
IN: shells
: tty [ print-banner ] listener ;
: tty ( -- )
[
use [ clone ] change
print-banner
listener
] with-scope ;
IN: listener

View File

@ -1,11 +1,8 @@
IN: listener
USING: help kernel ;
HELP: listener-prompt
{ $var-description "Variable holding a string printed before each line of input read by the listener." } ;
USING: help kernel shells ;
HELP: quit-flag
{ $var-description "Variable set to true by " { $link bye } " word; it forces the next iteration of the " { $link (listener) } " loop to end." } ;
{ $var-description "Variable set to true by " { $link bye } " word; it forces the next iteration of the " { $link listener } " loop to end." } ;
HELP: listener-hook
{ $var-description "Variable holding a quotation called by the listener before reading each line of input. The UI sets this variable to a quotation which updates the stack display in a listener gadget." } ;
@ -22,11 +19,11 @@ HELP: listen
{ $description "Prompts for an expression on the default stream and evaluates it. On end of file, " { $link quit-flag } " is set to terminate the listener loop." }
{ $errors "If the expression input by the user throws an error, the error is printed to the default stream and the word returns normally." } ;
HELP: (listener)
{ $description "Prompts for expressions on the default stream and evaluates them until end of file is reached. This is an internal word; call " { $link listener } " instead." } ;
HELP: listener
{ $description "Starts a listener prompting for expressions on the default stream." } ;
HELP: print-banner
{ $description "Print Factor version, operating system, and CPU architecture." } ;
HELP: listener
{ $description "Prompts for expressions on the default stream and evaluates them until end of file is reached. This is an internal word; call " { $link tty } " instead." } ;
HELP: tty
{ $description "Starts a listener prompting for expressions on the default stream." } ;