snakia.core.tui

Classes

Canvas(width, height[, default_value])

A canvas is a 2D array of characters.

CanvasChar([char, fg_color, bg_color, bold, ...])

RenderContext(renderer)

RenderTarget(*args, **kwargs)

Renderer(target)

Widget()

class snakia.core.tui.Canvas(width, height, default_value=CanvasChar(' '))[source]

Bases: object

A canvas is a 2D array of characters.

__init__(width, height, default_value=CanvasChar(' '))[source]
clear()[source]

Clear the canvas.

Return type:

None

copy_from(other, x=0, y=0)[source]

Copy the given canvas to the current canvas.

Return type:

None

draw_filled_rect(x, y, width, height, char)[source]

Draw a filled rectangle.

Return type:

None

draw_line_h(x, y, length, char)[source]

Draw a horizontal line.

Return type:

None

draw_line_v(x, y, length, char)[source]

Draw a vertical line.

Return type:

None

draw_rect(x, y, width, height, char)[source]

Draw a rectangle.

Return type:

None

draw_text(x, y, text, char)[source]

Draw text on the canvas.

Return type:

None

fill(value, /)[source]

Fill the canvas with the given value.

Return type:

None

get(x, y, /)[source]

Get the character at the given position.

Return type:

CanvasChar

get_column(x, /)[source]

Get the column at the given position.

Return type:

Iterable[CanvasChar]

get_row(y, /)[source]

Get the row at the given position.

Return type:

Iterable[CanvasChar]

get_subcanvas(x, y, width, height)[source]

Get a subcanvas from the current canvas.

Return type:

Canvas

height: Final[int]
is_valid_position(x, y)[source]

Check if the given position is valid.

Return type:

bool

set(x, y, value, /)[source]

Set the character at the given position.

Return type:

None

set_area(x, y, width, height, value)[source]

Set the area at the given position.

Return type:

None

set_column(x, value, /)[source]

Set the column at the given position.

Return type:

None

set_row(y, value, /)[source]

Set the row at the given position.

Return type:

None

property total: int
width: Final[int]
class snakia.core.tui.CanvasChar(char=' ', fg_color=None, bg_color=None, bold=False, italic=False, underline=False)[source]

Bases: object

__init__(char=' ', fg_color=None, bg_color=None, bold=False, italic=False, underline=False)
bg_color: str | None
bold: bool
char: str
fg_color: str | None
italic: bool
underline: bool
class snakia.core.tui.RenderContext(renderer)[source]

Bases: object

__init__(renderer)[source]
render(canvas)[source]
Return type:

None

class snakia.core.tui.RenderTarget(*args, **kwargs)[source]

Bases: Protocol

__init__(*args, **kwargs)
flush()[source]
Return type:

None

write(text)[source]
Return type:

None

class snakia.core.tui.Renderer(target)[source]

Bases: ABC

__init__(target)[source]
abstract clear_screen()[source]
Return type:

None

abstract hide_cursor()[source]
Return type:

None

abstract render(canvas)[source]
Return type:

None

abstract set_cursor_position(x, y)[source]
Return type:

None

abstract show_cursor()[source]
Return type:

None

class snakia.core.tui.Widget[source]

Bases: ABC

__init__()[source]
final async_state(default_value)[source]
Return type:

AsyncBindable[TypeVar(T)]

abstract on_render()[source]
Return type:

Canvas

final render()[source]
Return type:

Canvas

final state(default_value)[source]
Return type:

Bindable[TypeVar(T)]

Modules

canvas

char

render

renderer

widget

widgets