Output the results of the style and character buffers as ANSI styled text. This effectively normalizes all color codes to explicit RGB values and resolves all cursor motions and other control codes, and styling runs of identical styles with a single code.
the raw unstyled text of each line
Set the style that the terminal will use for text writes.
If a string, must be a valid \x1b[...m
ANSI style code.
The styles provided will be appended onto the current style in use, just as they would be by a real terminal if the relevant ANSI code is encountered.
A representation of a virtual "terminal" where we write out the character and style information as we parse through the ANSI encoded stream.
Important: this is not a full-fledged Stream class. You can write to it multiple times, and it will update appropriately, but it does zero buffering or input validation, so writing a partial ANSI code sequence will result in mochibake in the output.
The virtual terminal is an infinitely high and wide screen, with no scrollback buffer. So, when
scrollDown(n)
is called (either explicitly, or with a\x1b[<n>S
ANSI code),n
lines are removed from the top of the "screen". WhenscrollUp(n)
is called (explicitly or via a\x1b[<n>T
ANSI code),n
empty lines are added to the top of the screen; the lines lost to a previousscrollDown
action are not restored when scrolling up.Also, actions that move the cursor down or to the right, which would on a normal physical terminal be limited to the height/width of the terminal, are unbounded. For example, on an actual terminal,
echo $'\x1b[1000Bhello'
will print "hello" at the bottom of the screen (unless your screen happens to be more than 1000 lines high); in this virtual terminal, it will create 1000 empty lines.Most of the methods (other than
toString()
of course) returnthis
, allowing for things like this: