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

Reply via email to