4685
|
1 |
"{ Package: 'stx:libbasic2' }"
|
|
2 |
|
|
3 |
"{ NameSpace: Smalltalk }"
|
|
4 |
|
|
5 |
WriteStream subclass:#IndentStream
|
|
6 |
instanceVariableNames:'indentLevel indentString'
|
|
7 |
classVariableNames:''
|
|
8 |
poolDictionaries:''
|
4696
|
9 |
category:'Streams-Misc'
|
4685
|
10 |
!
|
|
11 |
|
|
12 |
!IndentStream class methodsFor:'documentation'!
|
|
13 |
|
|
14 |
documentation
|
|
15 |
"
|
|
16 |
a write stream which keeps a current indent and
|
|
17 |
automatically emits the indent on every cr.
|
|
18 |
|
|
19 |
[author:]
|
|
20 |
Claus Gittinger (ported from Squeak)
|
|
21 |
"
|
|
22 |
! !
|
|
23 |
|
|
24 |
!IndentStream class methodsFor:'instance creation'!
|
|
25 |
|
|
26 |
on: aCollection
|
|
27 |
|
|
28 |
^(super on: aCollection) initialize
|
|
29 |
!
|
|
30 |
|
|
31 |
with: aCollection
|
|
32 |
|
|
33 |
^(super with: aCollection) initialize
|
|
34 |
! !
|
|
35 |
|
|
36 |
!IndentStream methodsFor:'accessing'!
|
|
37 |
|
|
38 |
indentLevel
|
|
39 |
"the current indent"
|
|
40 |
|
|
41 |
^indentLevel
|
|
42 |
|
|
43 |
"Modified (comment): / 01-07-2018 / 10:16:32 / Claus Gittinger"
|
|
44 |
!
|
|
45 |
|
|
46 |
indentString:aString
|
|
47 |
"the string to use for indentation.
|
|
48 |
If left unset, a tab is used"
|
|
49 |
|
|
50 |
indentString := aString
|
|
51 |
|
|
52 |
"Created: / 01-07-2018 / 10:16:17 / Claus Gittinger"
|
|
53 |
! !
|
|
54 |
|
|
55 |
!IndentStream methodsFor:'character writing'!
|
|
56 |
|
|
57 |
cr
|
|
58 |
|
|
59 |
super cr.
|
|
60 |
self putIndent.
|
|
61 |
|
|
62 |
"Modified: / 01-07-2018 / 10:13:45 / Claus Gittinger"
|
|
63 |
!
|
|
64 |
|
|
65 |
crtab
|
|
66 |
|
|
67 |
self cr.
|
|
68 |
self indent.
|
|
69 |
!
|
|
70 |
|
|
71 |
putIndent
|
|
72 |
indentString notNil ifTrue:[
|
|
73 |
indentLevel timesRepeat:[
|
|
74 |
self nextPutAll:indentString
|
|
75 |
].
|
|
76 |
^ self.
|
|
77 |
].
|
|
78 |
"/ original
|
|
79 |
self tab: self indentLevel.
|
|
80 |
|
|
81 |
"Created: / 01-07-2018 / 10:13:40 / Claus Gittinger"
|
|
82 |
! !
|
|
83 |
|
|
84 |
!IndentStream methodsFor:'indentation'!
|
|
85 |
|
|
86 |
indent
|
|
87 |
|
|
88 |
self tab.
|
|
89 |
indentLevel := indentLevel + 1.
|
|
90 |
!
|
|
91 |
|
|
92 |
indentBack
|
|
93 |
|
|
94 |
indentLevel := indentLevel - 1.
|
|
95 |
! !
|
|
96 |
|
|
97 |
!IndentStream methodsFor:'initialization'!
|
|
98 |
|
|
99 |
initialize
|
|
100 |
|
|
101 |
super initialize.
|
|
102 |
indentLevel := 0.
|
|
103 |
! !
|
|
104 |
|
|
105 |
!IndentStream class methodsFor:'documentation'!
|
|
106 |
|
|
107 |
version
|
|
108 |
^ '$Header$'
|
|
109 |
!
|
|
110 |
|
|
111 |
version_CVS
|
|
112 |
^ '$Header$'
|
|
113 |
! !
|
|
114 |
|