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:

"{ Package: 'stx:libbasic2' }"

"{ NameSpace: Smalltalk }"

WriteStream subclass:#IndentStream
	instanceVariableNames:'indentLevel indentString'
	classVariableNames:''
	poolDictionaries:''
	category:'Streams-Misc'
!

!IndentStream class methodsFor:'documentation'!

documentation
"
    a write stream which keeps a current indent and
    automatically emits the indent on every cr.

    [author:]
        Claus Gittinger (ported from Squeak)
"
! !

!IndentStream class methodsFor:'instance creation'!

on: aCollection

	^(super on: aCollection) initialize
!

with: aCollection

	^(super with: aCollection) initialize
! !

!IndentStream methodsFor:'accessing'!

indentLevel
    "the current indent"
    
    ^indentLevel

    "Modified (comment): / 01-07-2018 / 10:16:32 / Claus Gittinger"
!

indentString:aString
    "the string to use for indentation.
     If left unset, a tab is used"
     
    indentString := aString

    "Created: / 01-07-2018 / 10:16:17 / Claus Gittinger"
! !

!IndentStream methodsFor:'character writing'!

cr

        super cr.
        self putIndent.

    "Modified: / 01-07-2018 / 10:13:45 / Claus Gittinger"
!

crtab

	self cr.
	self indent.
!

putIndent
    indentString notNil ifTrue:[
        indentLevel timesRepeat:[
            self nextPutAll:indentString
        ].
        ^ self.
    ].
    "/ original
    self tab: self indentLevel.

    "Created: / 01-07-2018 / 10:13:40 / Claus Gittinger"
! !

!IndentStream methodsFor:'indentation'!

indent

	self tab.
	indentLevel := indentLevel + 1.
!

indentBack

	indentLevel := indentLevel - 1.
! !

!IndentStream methodsFor:'initialization'!

initialize

	super initialize.
	indentLevel := 0.
! !

!IndentStream class methodsFor:'documentation'!

version
    ^ '$Header$'
!

version_CVS
    ^ '$Header$'
! !