--- a/FilteringLineStream.st Fri Oct 24 20:44:43 2014 +0200
+++ b/FilteringLineStream.st Sat Nov 08 11:20:41 2014 +0100
@@ -66,17 +66,35 @@
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:
- [exBegin]
+ [exBegin]
|in pusher|
in := 'Makefile' asFilename readStream.
pusher := FilteringLineStream readingFrom:in writingTo:Transcript.
pusher filterUpToEnd
- [exEnd]
+ [exEnd]
+
+
+ collect a command's stdout and stderr, colorizing error output in red and normal output in green:
+ [exBegin]
+ |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]).
+ [exEnd]
filter through an ActorStream:
- [exBegin]
+ [exBegin]
|lineNr in pusher actorPerLine|
lineNr := 0.
@@ -87,11 +105,11 @@
in := 'Makefile' asFilename readStream.
pusher := FilteringLineStream readingFrom:in writingTo:actorPerLine.
pusher filterUpToEnd
- [exEnd]
+ [exEnd]
filter all comments (starting with '#') from a Makefile:
- [exBegin]
+ [exBegin]
|in filter|
in := 'Makefile' asFilename readStream.
@@ -102,11 +120,11 @@
filter outputStream:Transcript.
filter filterUpToEnd
- [exEnd]
+ [exEnd]
the inverse - remove all comments from the Makefile:
- [exBegin]
+ [exBegin]
|in filter|
in := 'Makefile' asFilename readStream.
@@ -117,12 +135,12 @@
filter outputStream:Transcript.
filter filterUpToEnd
- [exEnd]
+ [exEnd]
feed a second filter from the first filters output;
(the remains are all lines starting with '#' and ending with '-'):
- [exBegin]
+ [exBegin]
|in filter1 filter2|
in := 'Makefile' asFilename readStream.
@@ -136,7 +154,7 @@
filter2 outputStream:Transcript.
filter2 filterUpToEnd
- [exEnd]
+ [exEnd]
"
! !
@@ -219,6 +237,10 @@
"Created: 11.1.1997 / 16:13:25 / cg"
!
+isBinary
+ ^ (inputStream ? outputStream) isBinary
+!
+
size
"mhmh - please use isEmpty; anything else is unknown"
@@ -230,9 +252,10 @@
!FilteringLineStream class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic2/FilteringLineStream.st,v 1.8 2012-08-06 06:22:00 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic2/FilteringLineStream.st,v 1.9 2014-11-08 10:20:41 cg Exp $'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libbasic2/FilteringLineStream.st,v 1.8 2012-08-06 06:22:00 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic2/FilteringLineStream.st,v 1.9 2014-11-08 10:20:41 cg Exp $'
! !
+