Skip to main content

IndentedWriter

Summary

A utility for writing indented text.

Signature

export declare class IndentedWriter 

Constructors

constructor

Constructs a new instance of the class

Properties

defaultIndentPrefix

Type:defaultIndentPrefix: string; Default: “ The text characters used to create one level of indentation. Two spaces by default.

Methods

decreaseIndent

Decreases the indentation, reverting the effect of the corresponding call to IndentedWriter.increaseIndent().

ensureNewLine

Adds a newline if the file pointer is not already at the start of the line (or start of the stream).

ensureSkippedLine

Adds up to two newlines to ensure that there is a blank line above the current line.

getText

Retrieves the output that was built so far.

increaseIndent

Increases the indentation. Normally the indentation is two spaces, however an arbitrary prefix can optional be specified. (For example, the prefix could be ”// ” to indent and comment simultaneously.) Each call to IndentedWriter.increaseIndent() must be followed by a corresponding call to IndentedWriter.decreaseIndent().

indentScope

A shorthand for ensuring that increaseIndent()/decreaseIndent() occur in pairs.

peekLastCharacter

Returns the last character that was written, or an empty string if no characters have been written yet.

peekSecondLastCharacter

Returns the second to last character that was written, or an empty string if less than one characters have been written yet.

toString

write

Writes some text to the internal string buffer, applying indentation according to the current indentation level. If the string contains multiple newlines, each line will be indented separately.

writeLine

A shorthand for writing an optional message, followed by a newline. Indentation is applied following the semantics of IndentedWriter.write().

writeTentative

Writes and messages if and only if writes anything.If writes “CONTENT”, this method will write “CONTENT”. If writes nothing, this method will write nothing.

Events

No events defined.

Remarks

Note that the indentation is inserted at the last possible opportunity. For example, this code… …would produce this output: