1 ! Copyright (C) 2003, 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors colors colors.constants
4 combinators.short-circuit compiler.units continuations debugger
5 fry io io.styles kernel lexer literals locals math math.parser
6 namespaces parser parser.notes prettyprint sequences sets
7 source-files.errors system vocabs vocabs.loader
11 GENERIC: stream-read-quot ( stream -- quot/f )
12 GENERIC# prompt. 1 ( stream prompt -- )
15 manifest get current-vocab>> [ name>> "IN: " prepend ] [ "" ] if*
16 auto-use? get [ " auto-use" append ] when ;
20 { background T{ rgba f 1 0.7 0.7 1 } }
21 { foreground COLOR: black }
22 } prompt-style set-global
25 nip prompt-style get-global format bl flush ;
27 SYMBOL: handle-ctrl-break
29 : maybe-enable-ctrl-break ( -- )
30 handle-ctrl-break get-global [ enable-ctrl-break ] when ;
32 : with-ctrl-break ( quot -- )
33 maybe-enable-ctrl-break
34 ! Always call disable-ctrl-break, no matter what handle-ctrl-break
35 ! says: it might've been changed just now by the user in the Listener.
36 ! It's a no-op if it's not enabled.
37 [ disable-ctrl-break ] [ ] cleanup ; inline
39 : parse-lines-interactive ( lines -- quot/f )
40 [ [ parse-lines ] with-ctrl-break ] with-compilation-unit ;
42 : read-quot-step ( lines -- quot/f )
43 [ parse-lines-interactive ] [
44 dup error>> unexpected-eof?
45 [ 2drop f ] [ rethrow ] if
48 : read-quot-loop ( stream accum -- quot/f )
49 over stream-readln dup [
51 dup read-quot-step dup
52 [ 2nip ] [ drop read-quot-loop ] if
57 M: object stream-read-quot
58 V{ } clone read-quot-loop ;
60 : read-quot ( -- quot/f ) input-stream get stream-read-quot ;
64 : show-var ( var -- ) visible-vars [ swap suffix ] change ;
66 : show-vars ( seq -- ) visible-vars [ swap union ] change ;
68 : hide-var ( var -- ) visible-vars [ remove ] change ;
70 : hide-vars ( seq -- ) visible-vars [ swap diff ] change ;
72 : hide-all-vars ( -- ) visible-vars off ;
76 : call-error-hook ( error -- )
77 error-continuation get error-hook get
78 call( continuation error -- ) ;
80 [ drop print-error-and-restarts ] error-hook set-global
82 SYMBOL: display-stacks?
84 t display-stacks? set-global
86 SYMBOL: max-stack-items
88 10 max-stack-items set-global
90 SYMBOL: error-summary?
92 t error-summary? set-global
96 : title. ( string -- )
97 H{ { foreground T{ rgba f 0.3 0.3 0.3 1 } } } format nl ;
99 : visible-vars. ( -- )
101 nl "--- Watched variables:" title.
102 standard-table-style [
105 [ [ short. ] with-cell ]
106 [ [ get short. ] with-cell ]
113 : trimmed-stack. ( seq -- )
114 dup length max-stack-items get > [
115 max-stack-items get cut*
117 [ length number>string "(" " more items)" surround ] keep
122 : datastack. ( datastack -- )
123 display-stacks? get [
124 [ nl "--- Data stack:" title. trimmed-stack. ] unless-empty
127 :: listener-step ( datastack -- datastack' )
128 error-summary? get [ error-summary ] when
131 input-stream get prompt prompt.
135 '[ [ datastack _ with-datastack ] with-ctrl-break ]
136 [ call-error-hook datastack ]
141 [ call-error-hook datastack ]
146 : (listener) ( datastack -- )
147 listener-step (listener) ;
151 SYMBOL: interactive-vocabs
195 "tools.profiler.sampling"
205 } interactive-vocabs set-global
207 : loaded-vocab? ( vocab-spec -- ? )
209 [ find-vocab-root not ]
210 [ source-loaded?>> +done+ eq? ]
213 : use-loaded-vocabs ( vocabs -- )
216 dup loaded-vocab? [ use-vocab ] [ drop ] if
220 : with-interactive-vocabs ( quot -- )
222 "scratchpad" set-current-vocab
223 interactive-vocabs get use-loaded-vocabs
225 ] with-manifest ; inline
230 [ { } (listener) ] with-return
231 ] with-interactive-vocabs ;
233 : listener-main ( -- )
234 version-info print flush listener ;