|
Class: InternalPipeStream
Object
|
+--Stream
|
+--InternalPipeStream
- Package:
- stx:libbasic2
- Category:
- Streams
- Version:
- rev:
1.6
date: 2017/02/15 21:06:09
- user: cg
- file: InternalPipeStream.st directory: libbasic2
- module: stx stc-classLibrary: libbasic2
not useful on its own, but can be used to talk to a vt100
terminal view ...
See example.
instance creation
-
new
-
accessing
-
atEnd
-
-
close
-
if there is any partner waiting at either side of the queue,
tell it that the pipe is no longer active.
(readers will read an EOF condition, writers will get a write error).
Either side may close the internal pipe.
-
isOpen
-
-
next
-
return the next element from the stream (might block until something is written)
-
nextAvailableBytes: nMax into: aBuffer startingAt: startIndex
-
-
nextPut: anObject
-
write an element (might wakeup readers)
-
size
-
initialization
-
contentsSpecies: aClass
-
by default, I will return a String of elements, if reading multiple elements.
However, you may change this to eg. an array, if desired
-
initialize
-
queries
-
contentsSpecies
-
synchronization
-
readWait
-
-
writeWaitWithTimeoutMs: timeout
-
|p|
p := InternalPipeStream new.
[
10 timesRepeat:[
p nextPutLine:'hello'
].
] fork.
[
10 timesRepeat:[
Transcript showCR:p nextLine
].
] fork.
|
|userInput elizasOutput top terminal|
userInput := InternalPipeStream new.
elizasOutput := InternalPipeStream new.
top := StandardSystemView new.
terminal := VT100TerminalView openOnInput: userInput output:elizasOutput in:top.
top extent:(terminal preferredExtent).
top label:'The doctor is in'.
top iconLabel:'doctor'.
top open.
top waitUntilVisible.
top onChangeEvaluate:[:what :aParameter :changedObject | what == #destroyed ifTrue:[userInput close]].
terminal translateNLToCRNL:true.
terminal inputTranslateCRToNL:true.
terminal localEcho:true.
elizasOutput nextPutLine:'Hi, I am Eliza'.
elizasOutput nextPutLine:'What is your problem (type end to finish conversation) ?'.
elizasOutput nextPutLine:''.
elizasOutput nextPutAll:'>'.
[top realized] whileTrue:[
|line answer matchingRule|
line := userInput nextLine.
((line isEmptyOrNil and:[userInput atEnd]) or:[ #('quit' 'exit' 'end' 'bye') includes:line ]) ifTrue:[
top destroy.
^ self
].
answer := 'Tell me more.'.
elizasOutput nextPutLine:answer.
elizasOutput nextPutAll:'>'.
].
|
|