]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/listener/listener.factor
ui.theme: updates to color scheme.
[factor.git] / basis / listener / listener.factor
index cdc85a79d784f223658d67894ff01afdc85aa684..5099c5ab905299966e028a2132c7c4a2a3edf44e 100644 (file)
@@ -1,23 +1,28 @@
 ! Copyright (C) 2003, 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: arrays hashtables io kernel math math.parser memory
-namespaces parser lexer sequences strings io.styles
-vectors words generic system combinators continuations debugger
-definitions compiler.units accessors colors prettyprint fry
-sets vocabs.parser source-files.errors locals vocabs vocabs.loader
-parser.notes ;
+USING: accessors colors colors.constants
+combinators.short-circuit compiler.units continuations debugger
+fry io io.styles kernel lexer literals locals math math.parser
+namespaces parser parser.notes prettyprint sequences sets
+source-files.errors system vocabs vocabs.loader
+vocabs.parser ;
 IN: listener
 
 GENERIC: stream-read-quot ( stream -- quot/f )
 GENERIC# prompt. 1 ( stream prompt -- )
 
 : prompt ( -- str )
-    manifest get current-vocab>> [ name>> "IN: " prepend ] [ "" ] if* 
+    manifest get current-vocab>> [ name>> "IN: " prepend ] [ "" ] if*
     auto-use? get [ " auto-use" append ] when ;
 
+SYMBOL: prompt-style
+H{
+    { background T{ rgba f 1 0.7 0.7 1 } }
+    { foreground COLOR: black }
+} prompt-style set-global
+
 M: object prompt.
-    nip H{ { background T{ rgba f 1 0.7 0.7 1 } } } format bl
-    flush ;
+    nip prompt-style get-global format bl flush ;
 
 : parse-lines-interactive ( lines -- quot/f )
     [ parse-lines ] with-compilation-unit ;
@@ -107,8 +112,7 @@ t error-summary? set-global
         [ nl "--- Data stack:" title. trimmed-stack. ] unless-empty
     ] [ drop ] if ;
 
-:: (listener) ( datastack -- )
-    parser-quiet? off
+:: listener-step ( datastack -- datastack' )
     error-summary? get [ error-summary ] when
     visible-vars.
     datastack datastack.
@@ -125,9 +129,10 @@ t error-summary? set-global
         [ call-error-hook datastack ]
         [ rethrow ]
         if
-    ] recover
+    ] recover ;
 
-    (listener) ;
+: (listener) ( datastack -- )
+    listener-step (listener) ;
 
 PRIVATE>
 
@@ -175,7 +180,7 @@ SYMBOL: interactive-vocabs
     "tools.dispatch"
     "tools.errors"
     "tools.memory"
-    "tools.counting-profiler"
+    "tools.profiler.sampling"
     "tools.test"
     "tools.threads"
     "tools.time"
@@ -185,27 +190,35 @@ SYMBOL: interactive-vocabs
     "vocabs.refresh"
     "vocabs.hierarchy"
     "words"
-    "scratchpad"
 } interactive-vocabs set-global
 
-: only-use-vocabs ( vocabs -- )
-    clear-manifest
-    [ lookup-vocab ] filter
-    [
-        lookup-vocab
+: loaded-vocab? ( vocab-spec -- ? )
+    {
         [ find-vocab-root not ]
-        [ source-loaded?>> +done+ eq? ] bi or
-    ] filter
-    [ use-vocab ] each ;
+        [ source-loaded?>> +done+ eq? ]
+    } 1|| ;
+
+: use-loaded-vocabs ( vocabs -- )
+    [
+        lookup-vocab [
+            dup loaded-vocab? [ use-vocab ] [ drop ] if
+        ] when*
+    ] each ;
 
 : with-interactive-vocabs ( quot -- )
     [
         "scratchpad" set-current-vocab
-        interactive-vocabs get only-use-vocabs
+        interactive-vocabs get use-loaded-vocabs
         call
     ] with-manifest ; inline
 
 : listener ( -- )
-    [ [ { } (listener) ] with-return ] with-interactive-vocabs ;
+    [
+        parser-quiet? off
+        [ { } (listener) ] with-return
+    ] with-interactive-vocabs ;
+
+: listener-main ( -- )
+    version-info print flush listener ;
 
-MAIN: listener
+MAIN: listener-main