|
Class: TextStream
Object
|
+--Stream
|
+--PeekableStream
|
+--PositionableStream
|
+--WriteStream
|
+--CharacterWriteStream
|
+--TextStream
- Package:
- stx:libbasic2
- Category:
- Streams
- Version:
- rev:
1.18
date: 2016/12/15 12:55:29
- user: stefan
- file: TextStream.st directory: libbasic2
- module: stx stc-classLibrary: libbasic2
- Author:
- Claus Gittinger
a textStream is much like a regular writeStream;
however, in addition to collecting characters, it keeps
track of any change of the emphasis, and returns a Text instance
as its contents (in contrast to a String instance).
Used to collect attributed text.
WriteStream
Text
String
accessing
-
contents
-
return the streams collected contents
usage example(s):
Answer a Text containing unicode characters:
(TextStream on:'')
emphasis:#italic;
nextPutAll:'hello';
emphasis:nil;
space;
emphasis:#bold;
nextPutAll:'world';
space;
nextPut:Character euro;
contents.
Answer a String:
(TextStream on:'')
nextPutAll:'hello';
contents.
Answer a Text:
(TextStream on:Text new)
nextPutAll:'hello';
contents.
|
-
stringContents
-
return the streams collected string contents
emphasis
-
emphasis
-
return the current emphasis
-
emphasis: newEmphasis
-
change the emphasis; all followup elements are appended with
that emphasis in effect
private
-
closeRun
-
writing
-
nextPutAllText: aText
-
write some text to the stream and keep the emphasis
(notice:
nextPutAll: ignores the argument's emphasis,
and instead writes with the current emphasis.
In contrast, this ignores the current emphasis, and writes with
the argument's emphasis.
|s|
s := TextStream on:''.
s emphasis:#italic;
nextPutAll:'hello';
emphasis:nil;
space;
emphasis:#bold;
nextPutAll:'world ';
nextPut:(Character codePoint:16r3C7).
s contents inspect
|
|s|
s := TextStream on:''.
s emphasis:#italic;
nextPutAll:'hello';
emphasis:nil;
space;
emphasis:#bold;
nextPutAll:'world'.
Transcript nextPutAll:(s contents)
|
|s|
s := TextStream on:''.
s emphasis:#italic;
nextPutAll:'hello';
emphasis:nil;
space;
emphasis:#bold;
nextPutAll:'world'.
Dialog
warn:(s contents)
|
|s1 s2 flipFlop|
s1 := PipeStream readingFrom:'ls -l'.
s2 := TextStream on:''.
flipFlop := true.
[s1 atEnd] whileFalse:[
flipFlop ifTrue:[
s2 emphasis:(#color->Color red)
] ifFalse:[
s2 emphasis:nil
].
flipFlop := flipFlop not.
s2 nextPutAll:(s1 nextLine).
s2 cr.
].
s1 close.
(EditTextView new contents:s2 contents) open
|
|