FocusIO.readText

Read text inserted by the user into a buffer.

Reads a UTF-8 sequence of characters from the system that was typed in by the user during the last frame. This will be keyboard input as interpreted by the system, using the system's input method, providing support for internationalization.

All the text will be written by reference into the provided buffer, overwriting previously stored text. The returned value will be a slice of this buffer, representing the entire value:

char[1024] buffer;
int offset;
auto text = focusIO.readText(buffer, offset);
writeln(text);
assert(text is buffer[0 .. text.length] || text is null);

The buffer may not fit the entire text. Because of this, the function should be called repeatedly until the returned value is null.

char[1024] buffer;
int offset;
while (true) {
    if (auto text = focusIO.readText(buffer, offset)) {
        writeln(text);
    }
    else {
        break;
    }
}

This function may not throw: In the instance the offset extends beyond text boundaries, the buffer is empty or text cannot be read, this function should return null, as if no text should remain to read.

interface FocusIO
nothrow
char[]
readText
(
return scope char[] buffer
,
ref int offset
)
out (text; text is null || text.length > 0, "Returned value must be null if it is empty")

Parameters

buffer char[]

Buffer to write the text to.

offset int

Number of leading bytes to skip when writing into the buffer. Updated to point to the end of the buffer. This makes it possible to keep track of position in the text if it doesn't fit in a single buffer.

Return Value

Type: char[]

A slice of the given buffer with text that was read. null if no text remains to read.

Meta