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 |
|
|
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 |
|
|
146 |
emphasis:aSymbol
|
343
|
147 |
"change the emphasis; all followup elements are appended with
|
|
148 |
that emphasis in effect"
|
|
149 |
|
340
|
150 |
position ~~ 1 ifTrue:[
|
|
151 |
self closeRun.
|
|
152 |
].
|
|
153 |
currentEmphasis := aSymbol
|
|
154 |
|
|
155 |
"
|
|
156 |
|s|
|
|
157 |
|
|
158 |
s := TextStream on:String new.
|
343
|
159 |
s emphasis:#italic;
|
|
160 |
nextPutAll:'hello';
|
|
161 |
emphasis:nil;
|
|
162 |
space;
|
|
163 |
emphasis:#bold;
|
|
164 |
nextPutAll:'world'.
|
340
|
165 |
s contents
|
|
166 |
"
|
|
167 |
! !
|
|
168 |
|
|
169 |
!TextStream methodsFor:'private'!
|
|
170 |
|
|
171 |
closeRun
|
|
172 |
position ~~ 1 ifTrue:[
|
|
173 |
runs isNil ifTrue:[
|
|
174 |
runs := RunArray new:position-1 withAll:currentEmphasis
|
|
175 |
] ifFalse:[
|
|
176 |
runs add:currentEmphasis withOccurrences:(position - runs size - 1)
|
|
177 |
]
|
|
178 |
]
|
|
179 |
! !
|
|
180 |
|
|
181 |
!TextStream class methodsFor:'documentation'!
|
|
182 |
|
|
183 |
version
|
562
|
184 |
^ '$Header: /cvs/stx/stx/libbasic2/TextStream.st,v 1.3 1997-08-22 13:16:15 cg Exp $'
|
340
|
185 |
! !
|