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