StackedPrinter class final

A printer that processes ANSI escape codes, replaces the default text style, and tracks the Stack of styles.

Similar to Printer, but instead of maintaining only the currently active Style, StackedPrinter tracks the full history of applied styles using a Stack. This is useful for complex formatting where styles might be applied and reverted hierarchically across multiple print statements.

Choosing this printer chooses that hierarchical interpretation: a selective reset closes one stacked operation instead of clearing the terminal property. Use Printer for arbitrary ANSI whose terminal meaning must be preserved.

A hyperlink is carried from one line to the next the way Printer carries it: links do not nest, so there is no stack of them to keep.

ESC 7 and ESC 8 use one save slot for the lifetime of the printer. The saved stacked rendition, hyperlink and opaque SGR state cross line boundaries; another ESC 7 replaces them, while ESC 8 restores without consuming.

See also runZonedStackedPrinter for usage within a zone.

Implemented types

Constructors

StackedPrinter({Style defaultStyle = Style.terminalColors, void output(String s)?, bool ansiCodesEnabled = true})
Creates a printer that processes ANSI escape codes, replaces the default text style, and tracks the Stack of styles.

Properties

ansiCodesEnabled bool
Whether escape codes are written at all.
finalinherited
defaultStyle Style
The style the text is given where it asks for none of its own.
finalinherited
hashCode int
The hash code for this object.
no setterinherited
lastState Stack?
The state the last prepared line ended in, carried into the next one — and null where no line has been read, as it stays for a printer whose defaultStyle is a NoStyle: imposing nothing, it carries nothing. It stays null with ansiCodesEnabled off as well — the line is stripped and handed back before there is a state to keep.
getter/setter pairinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
stateDefaults Stack
The state a line is closed back to: the terminal's own colours.
finalinherited

Methods

flush() → void
Writes out a line the writes so far have not ended.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
prepare(String line) String
Prepares the given line for printing.
inherited
print(Object? object) → void
Prints the given object to the output.
inherited
toString() String
A string representation of this object.
inherited
write(Object? object) → void
Writes the given object to the buffer.
inherited
writeAll(Iterable<Object?> objects, [String separator = '']) → void
Writes the given objects to the buffer.
inherited
writeCharCode(int charCode) → void
Writes the given character code to the buffer.
inherited
writeln([Object? object = '']) → void
Writes the given object to the buffer and flush buffer.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited