TextBufferWriter

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.

Members

Functions

fill
TextBufferWriter fill(size_t x, size_t y, size_t width, size_t height, char ch)

Fills an area with a specific character.

get
AnsiChar get(size_t x, size_t y)

Assertions: The point (x, y) must be in bounds.

getArea
TextBufferRange getArea(size_t x, size_t y, size_t width, size_t height)

Returns a mutable, random-access (indexable) range (TextBufferRange) containing the characters of the specified area.

set
TextBufferWriter set(size_t x, size_t y, char ch)

Sets a character at a specific point.

updateSize
void updateSize()

Updates the size of this TextBufferWriter to reflect any size changes within the underlying TextBuffer.

write
TextBufferWriter write(size_t x, size_t y, char[] text)
TextBufferWriter write(size_t x, size_t y, AnsiText text)

Writes some text starting at the given point.

Properties

bg
AnsiColour bg [@property getter]

Get the foreground.

bg
AnsiColour bg [@property setter]

Set the background for any newly-written characters.

bounds
TextBufferBounds bounds [@property getter]

The bounds that this TextWriter is constrained to.

fg
AnsiColour fg [@property setter]

Set the foreground for any newly-written characters.

fg
AnsiColour fg [@property getter]

Get the foreground.

flags
AnsiTextFlags flags [@property setter]

Set the flags for any newly-written characters.

flags
AnsiTextFlags flags [@property getter]

Get the foreground.

Examples

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'));

Meta