Squeak
  links to this page:    
View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
TextStream
Last updated at 3:49 pm UTC on 5 April 2019
The following example shows how to use a TextStream object.
It was posted to the Squeak list by Boris Gaertner on 5-Jan-2003.

TextStreamsExample1.png

  | 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'

Note: This no longer works in Squeak 5.2.
Instead of the last two lines use for example

 StringHolder 
  new textContents: ts contents 
  withSqueakLineEndings; 
  openLabel: 'TextStreams are powerful'

or

 ts contents asTextMorph openInHand


How to create a text with different font sizes

How to create a hyperlink in a Text

A third text example : Open a Workspace with content