eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'TextStream':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: TextStream


Inheritance:

   Object
   |
   +--Stream
      |
      +--PeekableStream
         |
         +--PositionableStream
            |
            +--WriteStream
               |
               +--CharacterWriteStream
                  |
                  +--TextStream

Package:
stx:libbasic2
Category:
Streams
Version:
rev: 1.22 date: 2024/02/16 13:30:40
user: stefan
file: TextStream.st directory: libbasic2
module: stx stc-classLibrary: libbasic2

Description:


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.

copyright

COPYRIGHT (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.

Instance protocol:

accessing
o  contents
return the stream's 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.

o  stringContents
return the stream's collected string contents

emphasis
o  emphasis
return the current emphasis

o  emphasis: newEmphasis
change the emphasis; all followup elements are appended with
that emphasis in effect

Usage example(s):

     |s|

     s := TextStream on:String new.
     s emphasis:#italic;
       nextPutAll:'hello';
       emphasis:nil;
       space;
       emphasis:#bold;
       nextPutAll:'world'.
     s contents.
     Transcript showCR:s contents.

Usage example(s):

     |s|

     s := TextStream on:String new.
     s emphasis:#italic;
       nextPutAll:'hello';
       emphasis:nil;
       space;
       emphasis:{#bold. #color->Color red};
       nextPutAll:'world'.
     s contents.
     Transcript showCR:s contents.

private
o  closeRun

writing
o  nextPutAll: aCollection startingAt: start to: stop
'abc%1ghi' allBold bindWith:('def' allRed).

o  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.

Usage example(s):

     |t|
     
     t := TextStream new.
     t nextPutAll:'abc'.
     t nextPutAll:('def' allBold).
     t nextPutAllText:('ghi' allBold).
     t nextPutAllText:'jkl'.
     t contents.
     self assert:(t contents sameStringAndEmphasisAs:('abcdef','ghi' allBold,'jkl')).


Examples:


     |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


ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Mon, 18 Nov 2024 06:55:24 GMT