I would be very interested in something like this.

Cheers,
Doru



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
> 

--
www.tudorgirba.com

"It's not how it is, it is how we see it."


Reply via email to