Screenbuffer¶
- class tanmatsu.Screenbuffer(w: int, h: int)¶
Buffer holding characters to be written to the screen.
- set(x: int, y: int, character: str, clip: tanmatsu.geometry.Rectangle | None = None, style: tanmatsu.style.Style | None = None) int¶
Set the value at the given x, y to character. If style is given, the style of said value will be set to style as well.
This function does nothing if clip is given and x, y is outside the clip.
- Returns
The delta between the given x and the next valid column in the row. In other words, the width of character.
- Return type
int
- Raises
ValueError – If character is an empty string.
When looping over a string containing arbitrary text, the return value of this function should be used as a cumulative offset on the x argument in subsequent calls to this function.
Failure to account for the fact that any given character may have a width between 0 and 2 columns in the terminal may result in malformed output.
For example:
line = 'Hello! こんにちは!' x_offset = 0 for character in line: x_offset += s.set( x + x_offset, y, character, clip=clip, style=style )
- set_style(x: int, y: int, style: tanmatsu.style.Style | None, clip: tanmatsu.geometry.Rectangle | None = None)¶
Set the style of the character at the given x, y to style.
This function does nothing if clip is given and x, y is outside the clip.
- set_string(x: int, y: int, string: str, style: tanmatsu.style.Style | None = None, clip: tanmatsu.geometry.Rectangle | None = None) int¶
Convenience function. Works the same way as
set(), but writes an entire string, starting at x, y, rather than a single character.- Returns
The delta between the given x and the next valid column in the row, after all characters in string have been set.
- Return type
int