author | Claus Gittinger <cg@exept.de> |
Mon, 17 Mar 2003 17:44:21 +0100 | |
changeset 1158 | 30a06aebed97 |
parent 1002 | ff7c1f0de146 |
child 1159 | 5f674144ea70 |
permissions | -rw-r--r-- |
340 | 1 |
" |
2 |
COPYRIGHT (c) 1996 by Claus Gittinger |
|
3 |
All Rights Reserved |
|
4 |
||
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
13 |
||
1002
ff7c1f0de146
code now independent of actual zeroPosition
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
14 |
"{ Package: 'stx:libbasic2' }" |
ff7c1f0de146
code now independent of actual zeroPosition
Claus Gittinger <cg@exept.de>
parents:
873
diff
changeset
|
15 |
|
340 | 16 |
WriteStream subclass:#TextStream |
17 |
instanceVariableNames:'runs currentEmphasis' |
|
18 |
classVariableNames:'' |
|
19 |
poolDictionaries:'' |
|
20 |
category:'Streams' |
|
21 |
! |
|
22 |
||
23 |
!TextStream class methodsFor:'documentation'! |
|
24 |
||
25 |
copyright |
|
26 |
" |
|
27 |
COPYRIGHT (c) 1996 by Claus Gittinger |
|
28 |
All Rights Reserved |
|
29 |
||
30 |
This software is furnished under a license and may be used |
|
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
||
38 |
! |
|
39 |
||
40 |
documentation |
|
41 |
" |
|
562 | 42 |
a textStream is much like a regular writeStream; |
340 | 43 |
however, in addition to collecting characters, it keeps |
44 |
track of any change of the emphasis, and returns a Text instance |
|
45 |
as its contents (in contrast to a String instance). |
|
46 |
Can be used to collect up attributed text. |
|
47 |
||
48 |
[author:] |
|
49 |
Claus Gittinger |
|
50 |
||
51 |
[see also:] |
|
52 |
WriteStream |
|
53 |
Text String |
|
54 |
" |
|
55 |
||
56 |
! |
|
57 |
||
58 |
examples |
|
59 |
" |
|
60 |
[exBegin] |
|
61 |
|s| |
|
62 |
||
63 |
s := TextStream on:''. |
|
64 |
s emphasis:#italic; |
|
65 |
nextPutAll:'hello'; |
|
66 |
emphasis:nil; |
|
67 |
space; |
|
68 |
emphasis:#bold; |
|
69 |
nextPutAll:'world'. |
|
70 |
s contents inspect |
|
71 |
[exEnd] |
|
72 |
||
73 |
[exBegin] |
|
74 |
|s| |
|
75 |
||
76 |
s := TextStream on:''. |
|
77 |
s emphasis:#italic; |
|
78 |
nextPutAll:'hello'; |
|
79 |
emphasis:nil; |
|
80 |
space; |
|
81 |
emphasis:#bold; |
|
82 |
nextPutAll:'world'. |
|
83 |
||
562 | 84 |
Transcript nextPutAll:(s contents) |
85 |
[exEnd] |
|
86 |
||
87 |
[exBegin] |
|
88 |
|s| |
|
89 |
||
90 |
s := TextStream on:''. |
|
91 |
s emphasis:#italic; |
|
92 |
nextPutAll:'hello'; |
|
93 |
emphasis:nil; |
|
94 |
space; |
|
95 |
emphasis:#bold; |
|
96 |
nextPutAll:'world'. |
|
97 |
||
340 | 98 |
Dialog |
99 |
warn:(s contents) |
|
100 |
[exEnd] |
|
101 |
||
102 |
[exBegin] |
|
103 |
|s1 s2 flipFlop| |
|
104 |
||
105 |
s1 := PipeStream readingFrom:'ls -l'. |
|
106 |
s2 := TextStream on:''. |
|
107 |
||
108 |
flipFlop := true. |
|
109 |
[s1 atEnd] whileFalse:[ |
|
110 |
flipFlop ifTrue:[ |
|
111 |
s2 emphasis:(#color->Color red) |
|
112 |
] ifFalse:[ |
|
113 |
s2 emphasis:nil |
|
114 |
]. |
|
115 |
flipFlop := flipFlop not. |
|
116 |
s2 nextPutAll:(s1 nextLine). |
|
117 |
s2 cr. |
|
118 |
]. |
|
119 |
s1 close. |
|
120 |
||
121 |
(EditTextView new contents:s2 contents) open |
|
122 |
[exEnd] |
|
123 |
" |
|
124 |
! ! |
|
125 |
||
126 |
!TextStream methodsFor:'accessing'! |
|
127 |
||
128 |
contents |
|
129 |
"return the streams collected contents" |
|
130 |
||
131 |
self closeRun. |
|
132 |
^ Text string:super contents emphasisCollection:runs |
|
133 |
||
134 |
" |
|
135 |
|s| |
|
136 |
||
137 |
s := TextStream on:String new. |
|
138 |
s emphasis:#italic. |
|
139 |
s nextPutAll:'hello'. |
|
140 |
s emphasis:nil. |
|
141 |
s space. |
|
142 |
s emphasis:#bold. |
|
143 |
s nextPutAll:'world'. |
|
144 |
s contents |
|
145 |
" |
|
146 |
! |
|
147 |
||
663 | 148 |
emphasis:newEmphasis |
343 | 149 |
"change the emphasis; all followup elements are appended with |
150 |
that emphasis in effect" |
|
151 |
||
1158 | 152 |
position ~~ ZeroPosition ifTrue:[ |
663 | 153 |
currentEmphasis ~~ newEmphasis ifTrue:[ |
154 |
self closeRun. |
|
155 |
] |
|
340 | 156 |
]. |
663 | 157 |
currentEmphasis := newEmphasis |
340 | 158 |
|
159 |
" |
|
160 |
|s| |
|
161 |
||
162 |
s := TextStream on:String new. |
|
343 | 163 |
s emphasis:#italic; |
164 |
nextPutAll:'hello'; |
|
165 |
emphasis:nil; |
|
166 |
space; |
|
167 |
emphasis:#bold; |
|
168 |
nextPutAll:'world'. |
|
340 | 169 |
s contents |
170 |
" |
|
663 | 171 |
|
172 |
"Modified: / 20.6.1998 / 17:11:30 / cg" |
|
873
2582affa063b
added #stringContents (for ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
663
diff
changeset
|
173 |
! |
2582affa063b
added #stringContents (for ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
663
diff
changeset
|
174 |
|
2582affa063b
added #stringContents (for ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
663
diff
changeset
|
175 |
stringContents |
2582affa063b
added #stringContents (for ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
663
diff
changeset
|
176 |
"return the streams collected string contents" |
2582affa063b
added #stringContents (for ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
663
diff
changeset
|
177 |
|
2582affa063b
added #stringContents (for ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
663
diff
changeset
|
178 |
^ super contents |
2582affa063b
added #stringContents (for ST80 compatibility)
Claus Gittinger <cg@exept.de>
parents:
663
diff
changeset
|
179 |
|
340 | 180 |
! ! |
181 |
||
182 |
!TextStream methodsFor:'private'! |
|
183 |
||
184 |
closeRun |
|
1158 | 185 |
position ~~ ZeroPosition ifTrue:[ |
340 | 186 |
runs isNil ifTrue:[ |
1158 | 187 |
runs := RunArray new:position-ZeroPosition withAll:currentEmphasis |
340 | 188 |
] ifFalse:[ |
1158 | 189 |
runs add:currentEmphasis withOccurrences:(position-ZeroPosition-runs size) |
340 | 190 |
] |
191 |
] |
|
192 |
! ! |
|
193 |
||
194 |
!TextStream class methodsFor:'documentation'! |
|
195 |
||
196 |
version |
|
1158 | 197 |
^ '$Header: /cvs/stx/stx/libbasic2/TextStream.st,v 1.7 2003-03-17 16:44:21 cg Exp $' |
340 | 198 |
! ! |