|
Class: FilteringLineStream
Object
|
+--Stream
|
+--PeekableStream
|
+--FilteringStream
|
+--FilteringLineStream
|
+--FilteringLineStream::AnsiControlSequenceInterpretingStream
- Package:
- stx:libbasic2
- Category:
- Streams-Misc
- Version:
- rev:
1.17
date: 2024/03/25 16:31:31
- user: cg
- file: FilteringLineStream.st directory: libbasic2
- module: stx stc-classLibrary: libbasic2
A FilteringLineStream is much like a FilteringStream, but
processes its input line-wise.
A FilteringLineStream can be connected to some input
(from which characters are read via the ReadStream protocol),
and/or to some output (to which characters are written via
the WriteStream protocol).
The FilteringLineStream itself performs some filtering/processing
on the (usually textline) elements as they arrive, optionally suppressing filtering
(i.e. removing) some elements.
copyrightCOPYRIGHT (c) 1996 by Claus Gittinger
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
class access
-
ansiControlSequenceInterpretingStream
-
access - pull-reading
-
filterUpToEnd
-
pull input from inputStream up to the end,
push it filtered into the outputStream.
access - push-writing
-
cr
-
finish a line, push it filtered into the outputStream
-
nextPut: something
-
collect a character or line and push it when a cr arrives.
Answer the argument.
-
nextPutAll: something
-
collect a line and push it when a cr arrives
accessing
-
filter
-
return the filter
-
filter: aBlock
-
set the filter
-
isBinary
-
(comment from inherited method)
return true, if in binary mode.
Defined here to make internalStreams protocol compatible with externalStreams.
-
size
-
mhmh - please use isEmpty; anything else is unknown
AnsiControlSequenceInterpretingStream
pushing the contents of a stream onto another stream
(here, the Transcript) without a need to read everyting into a
buffer or to reinvent the read-loop:
|in pusher|
in := 'Makefile' asFilename readStream.
pusher := FilteringLineStream readingFrom:in writingTo:Transcript.
pusher filterUpToEnd
|
collect a command's stdout and stderr, colorizing error output in red and normal output in green:
|in out stdoutColorizer errColorizer|
out := Transcript.
in := OperatingSystem
executeCommand:'bc'
inputFrom:
'4+5
bla bla foo
4+5
bar
' readStream
outputTo:((FilteringLineStream writingTo:out) filter:[:line | line colorizeAllWith:Color green darkened])
errorTo:((FilteringLineStream writingTo:out) filter:[:line | line colorizeAllWith:Color red]).
|
filter through an ActorStream:
|lineNr in pusher actorPerLine|
lineNr := 0.
actorPerLine := ActorStream new.
actorPerLine nextPutLineBlock:[:line | lineNr := lineNr + 1. Transcript show:lineNr; showCR:line].
in := 'Makefile' asFilename readStream.
pusher := FilteringLineStream readingFrom:in writingTo:actorPerLine.
pusher filterUpToEnd
|
filter all comments (starting with '#') from a Makefile:
|in filter|
in := 'Makefile' asFilename readStream.
filter := FilteringLineStream readingFrom:in.
filter filter:[:line | (line startsWith:'#') ifTrue:[line] ifFalse:[nil]].
filter outputStream:Transcript.
filter filterUpToEnd
|
the inverse - remove all comments from the Makefile:
|in filter|
in := 'Makefile' asFilename readStream.
filter := FilteringLineStream readingFrom:in.
filter filter:[:line | (line startsWith:'#') ifTrue:[nil] ifFalse:[line]].
filter outputStream:Transcript.
filter filterUpToEnd
|
feed a second filter from the first filters output;
(the remains are all lines starting with '#' and ending with '-'):
|in filter1 filter2|
in := 'Makefile' asFilename readStream.
filter1 := FilteringLineStream readingFrom:in.
filter1 filter:[:line | (line startsWith:'#') ifTrue:[line] ifFalse:[nil]].
filter2 := FilteringLineStream readingFrom:filter1.
filter2 filter:[:line | (line endsWith:'-') ifTrue:[line] ifFalse:[nil]].
filter2 outputStream:Transcript.
filter2 filterUpToEnd
|
|