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