Hi Pavel, Last week I was playing with a REPL exported over a local socket, I am reading input until an empty line, like this:
NeoREPLServer new start. $ telnet localhost 13731 Trying ::1... telnet: connect to address ::1: Connection refused Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. Welcome to Pharo2.0a of '18 April 2012' update 20372 Type a multi-line Smalltalk expression and an empty line to evaluate it Type !quit to exit, !help for information about other special commands 42 factorial 1405006117752879898543142606244511569936384000000000 'Pavel' reverse 'levaP' 3 timesRepeat: [ Smalltalk garbageCollect ] 3 ZTimestampFormat verbose german; format: ZTimestamp now 'Dienstag, 13-November-2012 10:06:13 AM (+00:00)' !quit Bye! Connection closed by foreign host. If you want I can share the code, it is very small (but incomplete). Sven -- Sven Van Caekenberghe http://stfx.eu Smalltalk is the Red Pill On 13 Nov 2012, at 10:01, Pavel Krivanek <[email protected]> wrote: > Hi, > > is there a way how to use nonblocking input from stdin? I have a > simple REPL but the stdin is blocking the VM. > > | stdin input lineEnd | > > stdin := FileStream stdin ifNil: [ ^ self ]. > stdin atEnd ifTrue: [ ^ self ]. > > [ > lineEnd := false. > FileStream stdout nextPutAll: '> '. > input := String streamContents: [:s| > [ stdin atEnd or: [lineEnd] ] whileFalse: [ > stdin next ifNotNilDo: [:char| > char = Character lf ifTrue: [lineEnd := true]. > s nextPut: char ]]]. > > [ FileStream stdout print: (Compiler evaluate: input); lf ] > ifError: [:error | FileStream stdout nextPutAll: 'ERROR: ', > error asString; lf]. > > Processor yield. > ] repeat > > Cheers, > -- Pavel >
