TextStream.st
author Claus Gittinger <cg@exept.de>
Tue, 25 Jun 2019 14:28:51 +0200
changeset 5050 44fa8672d102
parent 4233 96704b0b6c5b
permissions -rw-r--r--
#DOCUMENTATION by cg class: SharedQueue comment/format in: #next #nextWithTimeout:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
340
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
 COPYRIGHT (c) 1996 by Claus Gittinger
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
              All Rights Reserved
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
 This software is furnished under a license and may be used
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 hereby transferred.
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
"
1002
ff7c1f0de146 code now independent of actual zeroPosition
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
    12
"{ Package: 'stx:libbasic2' }"
ff7c1f0de146 code now independent of actual zeroPosition
Claus Gittinger <cg@exept.de>
parents: 873
diff changeset
    13
3480
4afdd00dd4c1 class: TextStream
Claus Gittinger <cg@exept.de>
parents: 3001
diff changeset
    14
"{ NameSpace: Smalltalk }"
4afdd00dd4c1 class: TextStream
Claus Gittinger <cg@exept.de>
parents: 3001
diff changeset
    15
1941
3f0b0b5df9ab Inherit from CharacterWriteStream, in order to support Unicode
Stefan Vogel <sv@exept.de>
parents: 1899
diff changeset
    16
CharacterWriteStream subclass:#TextStream
340
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
	instanceVariableNames:'runs currentEmphasis'
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
	classVariableNames:''
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
	poolDictionaries:''
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
	category:'Streams'
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
!
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
!TextStream class methodsFor:'documentation'!
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
copyright
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
"
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
 COPYRIGHT (c) 1996 by Claus Gittinger
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
              All Rights Reserved
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
 This software is furnished under a license and may be used
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
 only in accordance with the terms of that license and with the
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
 inclusion of the above copyright notice.   This software may not
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
 be provided or otherwise made available to, or used by, any
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
 other person.  No title to or ownership of the software is
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
 hereby transferred.
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
"
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
!
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
documentation
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
"
562
e41abf509444 comments
Claus Gittinger <cg@exept.de>
parents: 343
diff changeset
    42
    a textStream is much like a regular writeStream;
340
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
    however, in addition to collecting characters, it keeps
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
    track of any change of the emphasis, and returns a Text instance
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
    as its contents (in contrast to a String instance).
3480
4afdd00dd4c1 class: TextStream
Claus Gittinger <cg@exept.de>
parents: 3001
diff changeset
    46
    Used to collect attributed text.
340
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
    [author:]
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
        Claus Gittinger
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
    [see also:]
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
        WriteStream
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
        Text String
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
"
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
!
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
examples
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
"
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
                                                                [exBegin]
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
     |s|
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
     s := TextStream on:''.
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
     s emphasis:#italic;
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
       nextPutAll:'hello';
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
       emphasis:nil;
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
       space;
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
       emphasis:#bold;
1941
3f0b0b5df9ab Inherit from CharacterWriteStream, in order to support Unicode
Stefan Vogel <sv@exept.de>
parents: 1899
diff changeset
    68
       nextPutAll:'world ';
3f0b0b5df9ab Inherit from CharacterWriteStream, in order to support Unicode
Stefan Vogel <sv@exept.de>
parents: 1899
diff changeset
    69
       nextPut:(Character codePoint:16r3C7).
340
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
     s contents inspect
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
                                                                [exEnd]
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
                                                                [exBegin]
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
     |s|
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    75
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    76
     s := TextStream on:''.
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    77
     s emphasis:#italic;
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
       nextPutAll:'hello';
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
       emphasis:nil;
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    80
       space;
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
       emphasis:#bold;
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
       nextPutAll:'world'.
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
562
e41abf509444 comments
Claus Gittinger <cg@exept.de>
parents: 343
diff changeset
    84
     Transcript nextPutAll:(s contents)
e41abf509444 comments
Claus Gittinger <cg@exept.de>
parents: 343
diff changeset
    85
                                                                [exEnd]
e41abf509444 comments
Claus Gittinger <cg@exept.de>
parents: 343
diff changeset
    86
e41abf509444 comments
Claus Gittinger <cg@exept.de>
parents: 343
diff changeset
    87
                                                                [exBegin]
e41abf509444 comments
Claus Gittinger <cg@exept.de>
parents: 343
diff changeset
    88
     |s|
e41abf509444 comments
Claus Gittinger <cg@exept.de>
parents: 343
diff changeset
    89
e41abf509444 comments
Claus Gittinger <cg@exept.de>
parents: 343
diff changeset
    90
     s := TextStream on:''.
e41abf509444 comments
Claus Gittinger <cg@exept.de>
parents: 343
diff changeset
    91
     s emphasis:#italic;
e41abf509444 comments
Claus Gittinger <cg@exept.de>
parents: 343
diff changeset
    92
       nextPutAll:'hello';
e41abf509444 comments
Claus Gittinger <cg@exept.de>
parents: 343
diff changeset
    93
       emphasis:nil;
e41abf509444 comments
Claus Gittinger <cg@exept.de>
parents: 343
diff changeset
    94
       space;
e41abf509444 comments
Claus Gittinger <cg@exept.de>
parents: 343
diff changeset
    95
       emphasis:#bold;
e41abf509444 comments
Claus Gittinger <cg@exept.de>
parents: 343
diff changeset
    96
       nextPutAll:'world'.
e41abf509444 comments
Claus Gittinger <cg@exept.de>
parents: 343
diff changeset
    97
340
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
     Dialog
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
        warn:(s contents)
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   100
                                                                [exEnd]
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   101
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   102
                                                                [exBegin]
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   103
     |s1 s2 flipFlop|
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   104
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   105
     s1 := PipeStream readingFrom:'ls -l'.
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   106
     s2 := TextStream on:''.
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   107
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
     flipFlop := true.
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   109
     [s1 atEnd] whileFalse:[
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
        flipFlop ifTrue:[
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
            s2 emphasis:(#color->Color red)
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   112
        ] ifFalse:[
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
            s2 emphasis:nil
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   114
        ].
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   115
        flipFlop := flipFlop not.
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   116
        s2 nextPutAll:(s1 nextLine).
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   117
        s2 cr.
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   118
     ].
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   119
     s1 close.
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   120
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   121
     (EditTextView new contents:s2 contents) open
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   122
                                                                [exEnd]
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   123
"
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   124
! !
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   125
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   126
!TextStream methodsFor:'accessing'!
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   127
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   128
contents
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   129
    "return the streams collected contents"
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   130
2525
4d6a0a5905e7 changed: #contents
Claus Gittinger <cg@exept.de>
parents: 2053
diff changeset
   131
    |stringContents|
4d6a0a5905e7 changed: #contents
Claus Gittinger <cg@exept.de>
parents: 2053
diff changeset
   132
4d6a0a5905e7 changed: #contents
Claus Gittinger <cg@exept.de>
parents: 2053
diff changeset
   133
    stringContents := super contents.
4d6a0a5905e7 changed: #contents
Claus Gittinger <cg@exept.de>
parents: 2053
diff changeset
   134
1943
63b23152a6d2 #contents does not convert the underlying collection to a Text, if there is
Stefan Vogel <sv@exept.de>
parents: 1941
diff changeset
   135
    (currentEmphasis isNil and:[runs isEmptyOrNil]) ifTrue:[
63b23152a6d2 #contents does not convert the underlying collection to a Text, if there is
Stefan Vogel <sv@exept.de>
parents: 1941
diff changeset
   136
        "no emphasis information: answer a string"
2525
4d6a0a5905e7 changed: #contents
Claus Gittinger <cg@exept.de>
parents: 2053
diff changeset
   137
        ^ stringContents
1943
63b23152a6d2 #contents does not convert the underlying collection to a Text, if there is
Stefan Vogel <sv@exept.de>
parents: 1941
diff changeset
   138
    ].
340
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   139
    self closeRun.
2525
4d6a0a5905e7 changed: #contents
Claus Gittinger <cg@exept.de>
parents: 2053
diff changeset
   140
    ^ Text string:stringContents emphasisCollection:runs
340
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   141
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   142
    "
1943
63b23152a6d2 #contents does not convert the underlying collection to a Text, if there is
Stefan Vogel <sv@exept.de>
parents: 1941
diff changeset
   143
     Answer a Text containing unicode characters:
63b23152a6d2 #contents does not convert the underlying collection to a Text, if there is
Stefan Vogel <sv@exept.de>
parents: 1941
diff changeset
   144
         (TextStream on:'')
63b23152a6d2 #contents does not convert the underlying collection to a Text, if there is
Stefan Vogel <sv@exept.de>
parents: 1941
diff changeset
   145
            emphasis:#italic;
63b23152a6d2 #contents does not convert the underlying collection to a Text, if there is
Stefan Vogel <sv@exept.de>
parents: 1941
diff changeset
   146
            nextPutAll:'hello';
63b23152a6d2 #contents does not convert the underlying collection to a Text, if there is
Stefan Vogel <sv@exept.de>
parents: 1941
diff changeset
   147
            emphasis:nil;
63b23152a6d2 #contents does not convert the underlying collection to a Text, if there is
Stefan Vogel <sv@exept.de>
parents: 1941
diff changeset
   148
            space;
63b23152a6d2 #contents does not convert the underlying collection to a Text, if there is
Stefan Vogel <sv@exept.de>
parents: 1941
diff changeset
   149
            emphasis:#bold;
63b23152a6d2 #contents does not convert the underlying collection to a Text, if there is
Stefan Vogel <sv@exept.de>
parents: 1941
diff changeset
   150
            nextPutAll:'world';
63b23152a6d2 #contents does not convert the underlying collection to a Text, if there is
Stefan Vogel <sv@exept.de>
parents: 1941
diff changeset
   151
            space;
63b23152a6d2 #contents does not convert the underlying collection to a Text, if there is
Stefan Vogel <sv@exept.de>
parents: 1941
diff changeset
   152
            nextPut:Character euro;
63b23152a6d2 #contents does not convert the underlying collection to a Text, if there is
Stefan Vogel <sv@exept.de>
parents: 1941
diff changeset
   153
            contents.
340
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   154
1943
63b23152a6d2 #contents does not convert the underlying collection to a Text, if there is
Stefan Vogel <sv@exept.de>
parents: 1941
diff changeset
   155
     Answer a String:
63b23152a6d2 #contents does not convert the underlying collection to a Text, if there is
Stefan Vogel <sv@exept.de>
parents: 1941
diff changeset
   156
         (TextStream on:'')
63b23152a6d2 #contents does not convert the underlying collection to a Text, if there is
Stefan Vogel <sv@exept.de>
parents: 1941
diff changeset
   157
            nextPutAll:'hello';
63b23152a6d2 #contents does not convert the underlying collection to a Text, if there is
Stefan Vogel <sv@exept.de>
parents: 1941
diff changeset
   158
            contents.
63b23152a6d2 #contents does not convert the underlying collection to a Text, if there is
Stefan Vogel <sv@exept.de>
parents: 1941
diff changeset
   159
63b23152a6d2 #contents does not convert the underlying collection to a Text, if there is
Stefan Vogel <sv@exept.de>
parents: 1941
diff changeset
   160
     Answer a Text:
63b23152a6d2 #contents does not convert the underlying collection to a Text, if there is
Stefan Vogel <sv@exept.de>
parents: 1941
diff changeset
   161
         (TextStream on:Text new)
63b23152a6d2 #contents does not convert the underlying collection to a Text, if there is
Stefan Vogel <sv@exept.de>
parents: 1941
diff changeset
   162
            nextPutAll:'hello';
63b23152a6d2 #contents does not convert the underlying collection to a Text, if there is
Stefan Vogel <sv@exept.de>
parents: 1941
diff changeset
   163
            contents.
340
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   164
    "
2525
4d6a0a5905e7 changed: #contents
Claus Gittinger <cg@exept.de>
parents: 2053
diff changeset
   165
4d6a0a5905e7 changed: #contents
Claus Gittinger <cg@exept.de>
parents: 2053
diff changeset
   166
    "Modified: / 28-01-2011 / 13:46:48 / cg"
340
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   167
!
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   168
4233
96704b0b6c5b #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 3833
diff changeset
   169
stringContents
96704b0b6c5b #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 3833
diff changeset
   170
    "return the streams collected string contents"
96704b0b6c5b #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 3833
diff changeset
   171
96704b0b6c5b #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 3833
diff changeset
   172
    ^ super contents
96704b0b6c5b #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 3833
diff changeset
   173
96704b0b6c5b #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 3833
diff changeset
   174
! !
96704b0b6c5b #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 3833
diff changeset
   175
96704b0b6c5b #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 3833
diff changeset
   176
!TextStream methodsFor:'emphasis'!
96704b0b6c5b #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 3833
diff changeset
   177
1159
5f674144ea70 emphasis access
Claus Gittinger <cg@exept.de>
parents: 1158
diff changeset
   178
emphasis
5f674144ea70 emphasis access
Claus Gittinger <cg@exept.de>
parents: 1158
diff changeset
   179
    "return the current emphasis"
5f674144ea70 emphasis access
Claus Gittinger <cg@exept.de>
parents: 1158
diff changeset
   180
5f674144ea70 emphasis access
Claus Gittinger <cg@exept.de>
parents: 1158
diff changeset
   181
    ^ currentEmphasis 
5f674144ea70 emphasis access
Claus Gittinger <cg@exept.de>
parents: 1158
diff changeset
   182
!
5f674144ea70 emphasis access
Claus Gittinger <cg@exept.de>
parents: 1158
diff changeset
   183
663
64bf2f5fec3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 562
diff changeset
   184
emphasis:newEmphasis
343
01f88d90c385 commentary
Claus Gittinger <cg@exept.de>
parents: 340
diff changeset
   185
    "change the emphasis; all followup elements are appended with
01f88d90c385 commentary
Claus Gittinger <cg@exept.de>
parents: 340
diff changeset
   186
     that emphasis in effect"
01f88d90c385 commentary
Claus Gittinger <cg@exept.de>
parents: 340
diff changeset
   187
3001
314f68c6ad13 class: TextStream
Claus Gittinger <cg@exept.de>
parents: 2537
diff changeset
   188
    position ~~ 0 ifTrue:[
1899
b856899327a9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1159
diff changeset
   189
        currentEmphasis ~= newEmphasis ifTrue:[
663
64bf2f5fec3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 562
diff changeset
   190
            self closeRun.
64bf2f5fec3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 562
diff changeset
   191
        ]
340
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   192
    ].
663
64bf2f5fec3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 562
diff changeset
   193
    currentEmphasis := newEmphasis
340
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   194
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   195
    "
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   196
     |s|
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   197
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   198
     s := TextStream on:String new.
343
01f88d90c385 commentary
Claus Gittinger <cg@exept.de>
parents: 340
diff changeset
   199
     s emphasis:#italic;
01f88d90c385 commentary
Claus Gittinger <cg@exept.de>
parents: 340
diff changeset
   200
       nextPutAll:'hello';
01f88d90c385 commentary
Claus Gittinger <cg@exept.de>
parents: 340
diff changeset
   201
       emphasis:nil;
01f88d90c385 commentary
Claus Gittinger <cg@exept.de>
parents: 340
diff changeset
   202
       space;
01f88d90c385 commentary
Claus Gittinger <cg@exept.de>
parents: 340
diff changeset
   203
       emphasis:#bold;
01f88d90c385 commentary
Claus Gittinger <cg@exept.de>
parents: 340
diff changeset
   204
       nextPutAll:'world'.
1899
b856899327a9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1159
diff changeset
   205
     s contents.
2537
d186547b3459 comment/format in: #emphasis:
Claus Gittinger <cg@exept.de>
parents: 2525
diff changeset
   206
     Transcript showCR:s contents.
340
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   207
    "
663
64bf2f5fec3c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 562
diff changeset
   208
2537
d186547b3459 comment/format in: #emphasis:
Claus Gittinger <cg@exept.de>
parents: 2525
diff changeset
   209
    "
d186547b3459 comment/format in: #emphasis:
Claus Gittinger <cg@exept.de>
parents: 2525
diff changeset
   210
     |s|
d186547b3459 comment/format in: #emphasis:
Claus Gittinger <cg@exept.de>
parents: 2525
diff changeset
   211
d186547b3459 comment/format in: #emphasis:
Claus Gittinger <cg@exept.de>
parents: 2525
diff changeset
   212
     s := TextStream on:String new.
d186547b3459 comment/format in: #emphasis:
Claus Gittinger <cg@exept.de>
parents: 2525
diff changeset
   213
     s emphasis:#italic;
d186547b3459 comment/format in: #emphasis:
Claus Gittinger <cg@exept.de>
parents: 2525
diff changeset
   214
       nextPutAll:'hello';
d186547b3459 comment/format in: #emphasis:
Claus Gittinger <cg@exept.de>
parents: 2525
diff changeset
   215
       emphasis:nil;
d186547b3459 comment/format in: #emphasis:
Claus Gittinger <cg@exept.de>
parents: 2525
diff changeset
   216
       space;
d186547b3459 comment/format in: #emphasis:
Claus Gittinger <cg@exept.de>
parents: 2525
diff changeset
   217
       emphasis:{#bold. #color->Color red};
d186547b3459 comment/format in: #emphasis:
Claus Gittinger <cg@exept.de>
parents: 2525
diff changeset
   218
       nextPutAll:'world'.
d186547b3459 comment/format in: #emphasis:
Claus Gittinger <cg@exept.de>
parents: 2525
diff changeset
   219
     s contents.
d186547b3459 comment/format in: #emphasis:
Claus Gittinger <cg@exept.de>
parents: 2525
diff changeset
   220
     Transcript showCR:s contents.
d186547b3459 comment/format in: #emphasis:
Claus Gittinger <cg@exept.de>
parents: 2525
diff changeset
   221
    "
d186547b3459 comment/format in: #emphasis:
Claus Gittinger <cg@exept.de>
parents: 2525
diff changeset
   222
d186547b3459 comment/format in: #emphasis:
Claus Gittinger <cg@exept.de>
parents: 2525
diff changeset
   223
    "Modified: / 17-02-2011 / 14:13:07 / cg"
340
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   224
! !
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   225
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   226
!TextStream methodsFor:'private'!
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   227
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   228
closeRun
3001
314f68c6ad13 class: TextStream
Claus Gittinger <cg@exept.de>
parents: 2537
diff changeset
   229
    position ~~ 0 ifTrue:[
340
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   230
        runs isNil ifTrue:[
3001
314f68c6ad13 class: TextStream
Claus Gittinger <cg@exept.de>
parents: 2537
diff changeset
   231
            runs := RunArray new:position withAll:currentEmphasis.
340
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   232
        ] ifFalse:[
3001
314f68c6ad13 class: TextStream
Claus Gittinger <cg@exept.de>
parents: 2537
diff changeset
   233
            runs add:currentEmphasis withOccurrences:(position-runs size)
340
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   234
        ]
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   235
    ]
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   236
! !
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   237
2053
7592e3ecdca4 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 1943
diff changeset
   238
!TextStream methodsFor:'writing'!
7592e3ecdca4 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 1943
diff changeset
   239
7592e3ecdca4 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 1943
diff changeset
   240
nextPutAllText:aText
3833
bd6ce7a78e48 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3480
diff changeset
   241
    "write some text to the stream and keep the emphasis
bd6ce7a78e48 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3480
diff changeset
   242
     (notice: 
bd6ce7a78e48 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3480
diff changeset
   243
        nextPutAll: ignores the argument's emphasis,
bd6ce7a78e48 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3480
diff changeset
   244
        and instead writes with the current emphasis.
bd6ce7a78e48 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3480
diff changeset
   245
        In contrast, this ignores the current emphasis, and writes with
bd6ce7a78e48 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3480
diff changeset
   246
        the argument's emphasis."
2053
7592e3ecdca4 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 1943
diff changeset
   247
7592e3ecdca4 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 1943
diff changeset
   248
    |string pos oldEmphasis|
7592e3ecdca4 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 1943
diff changeset
   249
7592e3ecdca4 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 1943
diff changeset
   250
    string := aText string.
7592e3ecdca4 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 1943
diff changeset
   251
    pos := 1.
7592e3ecdca4 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 1943
diff changeset
   252
7592e3ecdca4 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 1943
diff changeset
   253
    oldEmphasis := currentEmphasis.
7592e3ecdca4 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 1943
diff changeset
   254
    aText emphasis runsDo:[:len :emphasis |
7592e3ecdca4 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 1943
diff changeset
   255
        |nextPos|
7592e3ecdca4 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 1943
diff changeset
   256
7592e3ecdca4 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 1943
diff changeset
   257
        nextPos := pos + len.
7592e3ecdca4 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 1943
diff changeset
   258
7592e3ecdca4 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 1943
diff changeset
   259
        self emphasis:emphasis.
7592e3ecdca4 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 1943
diff changeset
   260
        self nextPutAll:string startingAt:pos to:nextPos - 1.
7592e3ecdca4 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 1943
diff changeset
   261
        pos := nextPos
7592e3ecdca4 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 1943
diff changeset
   262
    ].
7592e3ecdca4 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 1943
diff changeset
   263
    self emphasis:oldEmphasis
3833
bd6ce7a78e48 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3480
diff changeset
   264
bd6ce7a78e48 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3480
diff changeset
   265
    "
bd6ce7a78e48 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3480
diff changeset
   266
     |t|
bd6ce7a78e48 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3480
diff changeset
   267
     
bd6ce7a78e48 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3480
diff changeset
   268
     t := TextStream new.
bd6ce7a78e48 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3480
diff changeset
   269
     t nextPutAll:'abc'.
bd6ce7a78e48 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3480
diff changeset
   270
     t nextPutAll:('def' allBold).
bd6ce7a78e48 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3480
diff changeset
   271
     t nextPutAllText:('ghi' allBold).
bd6ce7a78e48 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3480
diff changeset
   272
     t nextPutAllText:'jkl'.
bd6ce7a78e48 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3480
diff changeset
   273
     t contents.
bd6ce7a78e48 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3480
diff changeset
   274
     self assert:(t contents sameStringAndEmphasisAs:('abcdef','ghi' allBold,'jkl')).
bd6ce7a78e48 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3480
diff changeset
   275
    "
2053
7592e3ecdca4 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 1943
diff changeset
   276
! !
7592e3ecdca4 Unicode handling:
Stefan Vogel <sv@exept.de>
parents: 1943
diff changeset
   277
340
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   278
!TextStream class methodsFor:'documentation'!
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   279
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   280
version
3833
bd6ce7a78e48 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3480
diff changeset
   281
    ^ '$Header$'
2525
4d6a0a5905e7 changed: #contents
Claus Gittinger <cg@exept.de>
parents: 2053
diff changeset
   282
!
4d6a0a5905e7 changed: #contents
Claus Gittinger <cg@exept.de>
parents: 2053
diff changeset
   283
4d6a0a5905e7 changed: #contents
Claus Gittinger <cg@exept.de>
parents: 2053
diff changeset
   284
version_CVS
3833
bd6ce7a78e48 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3480
diff changeset
   285
    ^ '$Header$'
340
dcc2bb30c0c9 intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   286
! !
3001
314f68c6ad13 class: TextStream
Claus Gittinger <cg@exept.de>
parents: 2537
diff changeset
   287