/
StdioListener.class.st
53 lines (48 loc) · 1.25 KB
/
StdioListener.class.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
Class {
#name : #StdioListener,
#superclass : #Object,
#instVars : [
'quitOnEof',
'stdin',
'stdout',
'stderr'
],
#category : #'CogTools-Listener'
}
{ #category : #'initialize-release' }
StdioListener >> initialize [
quitOnEof := true.
stdin := FileStream stdin.
stdout := FileStream stdout.
stderr := FileStream stderr
]
{ #category : #'run loop' }
StdioListener >> logError: errMsg inContext: aContext to: aStream [
aStream nextPutAll: errMsg; cr.
aContext errorReportOn: aStream.
aStream cr
]
{ #category : #accessing }
StdioListener >> quitOnEof [
^quitOnEof
]
{ #category : #accessing }
StdioListener >> quitOnEof: aBoolean [
quitOnEof := aBoolean
]
{ #category : #'run loop' }
StdioListener >> run [
[stdin atEnd] whileFalse:
[| nextChunk |
stdout nextPutAll: 'squeak> '; flush.
nextChunk := stdin nextChunkNoTag.
[nextChunk notEmpty and: [nextChunk first isSeparator]] whileTrue:
[nextChunk := nextChunk allButFirst].
Transcript cr; nextPutAll: nextChunk; cr; flush.
[stdout print: (Compiler evaluate: nextChunk); cr; flush]
on: Error
do: [:ex| self logError: ex description inContext: ex signalerContext to: stderr]].
quitOnEof ifTrue:
[SourceFiles at: 2 put: nil.
Smalltalk snapshot: false andQuit: true]
]