Optionalinput: stringOutput 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.
An array of Block objects each representing a string of text with a
given style.
the raw unstyled text of each line
Delete the contents of the current line.
Delete printed data from the start of the current line to the cursor.
Delete printed data from the cursor to the end of the current line.
Delete all printed data from the screen.
Note that this is used for both \x1b[2J and \x1b[3J, because there
is no scrollback buffer in this virtual terminal.
Delete all printed data from the top of the screen to the cursor.
Delete all printed data from the cursor to the end of the screen.
Move to the n-th column (1-indexed), limited by the left-most column.
Move to the 1-indexed row and column specified, limited by the top and left sides of the screen.
Move to the start of the n-th previous line, stopping at the top of the
screen.
Remove n lines from the start of the buffer, effectively moving the
cursor down as a result.
Prepend n empty lines at the start of the buffer, effectively moving the
cursor up as a result.
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.
Called when an OSC code of \x1b]0;...\x1b is encountered.
Sets the title attribute on the root <pre> in html output,
and creates a corresponding OSC title sequence in the ansi output.
Output the results of the style and character buffers as a <pre>
tag with <span> elements setting effective styles.
Parse the ANSI encoded string provided, updating the internal character and style buffers appropriately.
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>SANSI code),nlines are removed from the top of the "screen". WhenscrollUp(n)is called (explicitly or via a\x1b[<n>TANSI code),nempty lines are added to the top of the screen; the lines lost to a previousscrollDownaction 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: