Fills an area with a specific character.
Assertions: The point (x, y) must be in bounds.
Returns a mutable, random-access (indexable) range (TextBufferRange) containing the characters of the specified area.
Sets a character at a specific point.
Updates the size of this TextBufferWriter to reflect any size changes within the underlying TextBuffer.
Writes some text starting at the given point.
Get the foreground.
Set the background for any newly-written characters.
The bounds that this TextWriter is constrained to.
Set the foreground for any newly-written characters.
Get the foreground.
Set the flags for any newly-written characters.
Get the foreground.
import std.format : format; import jaster.cli.ansi; auto buffer = new TextBuffer(5, 4); auto writer = buffer.createWriter(1, 1, 3, 2); // Offset X, Offset Y, Width, Height. auto fullGridWriter = buffer.createWriter(0, 0, TextBuffer.USE_REMAINING_SPACE, TextBuffer.USE_REMAINING_SPACE); // Clear grid to be just spaces. fullGridWriter.fill(0, 0, TextBuffer.USE_REMAINING_SPACE, TextBuffer.USE_REMAINING_SPACE, ' '); // Write some stuff in the center. with(writer) { set(0, 0, 'A'); set(1, 0, 'B'); set(2, 0, 'C'); fg = AnsiColour(Ansi4BitColour.green); set(0, 1, 'D'); set(1, 1, 'E'); set(2, 1, 'F'); } assert(buffer.toStringNoDupe() == " " ~" ABC " ~" \033[32mDEF\033[0m " // \033 stuff is of course, the ANSI codes. In this case, green foreground, as we set above. ~" ", buffer.toStringNoDupe() ~ "\n%s".format(buffer.toStringNoDupe()) ); assert(writer.get(1, 1) == AnsiChar(AnsiColour(Ansi4BitColour.green), AnsiColour.bgInit, AnsiTextFlags.none, 'E'));
The main way to modify and read data into/from a TextBuffer.
Performance: Outside of error messages (only in asserts), there shouldn't be any allocations.