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