TextStream
Last updated at 2:57 pm UTC on 14 January 2006
The following example shows how to use class TextStream.
It was posted to the Squeak list by Boris Gaertner on 5-Jan-03.
| ts |
ts := TextStream on: (Text new: 100).
ts nextPutAll: 'Class ';
withAttribute: TextEmphasis bold
do: [ts nextPutAll: 'TextStream'];
cr.
ts nextPutAll: 'This class is used to create ';
withAttributes: (Set with: TextEmphasis bold with: TextEmphasis underlined)
do: [ts nextPutAll: 'styled text.'];
cr;
withAttribute: TextEmphasis italic
do: [ts nextPutAll: 'Styled text'];
withAttribute: TextEmphasis normal
do: [ts nextPutAll: ' has display properties like '];
withAttribute: TextEmphasis bold
do: [ts nextPutAll: 'bold '];
withAttribute: TextEmphasis italic
do: [ts nextPutAll: 'italic '];
withAttribute: TextEmphasis struckOut
do: [ts nextPutAll: 'struck out '];
cr.
(Workspace new contents: ts contents)
openLabel: 'TextStreams are powerful'
Another example was posted by Boris Gaertner 5-Jul-03
Create a text with a hyperlink in it:
| ts |
ts := TextStream on: (Text new).
ts nextPutAll: 'Squeak is a beautiful language. Look at '.
ts withAttribute: (TextURL new url: 'http:\\www.squeak.org')
do:
[ ts nextPutAll: 'http:\\www.squeak.org'].
ts nextPutAll: ' to learn more about it.'.
(Workspace new contents: ts contents) openLabel: 'Here is your Hyperlink:'