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.18 date: 2016/12/15 12:55:29
user: stefan
file: TextStream.st directory: libbasic2
module: stx stc-classLibrary: libbasic2
Author:
Claus Gittinger

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.


Related information:

    WriteStream
    Text
    String

Instance protocol:

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

o  stringContents
return the streams 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

private
o  closeRun

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


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.2.0.0; WebServer 1.670 at bd0aa1f87cdd.unknown:8081; Fri, 19 Apr 2024 06:09:16 GMT