1package uv
2
3// Drawable represents a drawable component on a [Screen].
4type Drawable interface {
5 // Draw renders the component on the screen for the given area.
6 Draw(scr Screen, area Rectangle)
7}
8
9// WidthMethod determines how many columns a grapheme occupies on the screen.
10type WidthMethod interface {
11 StringWidth(s string) int
12}
13
14// Screen represents a screen that can be drawn to.
15type Screen interface {
16 // Bounds returns the bounds of the screen. This is the rectangle that
17 // includes the start and end points of the screen.
18 Bounds() Rectangle
19
20 // CellAt returns the cell at the given position. If the position is out of
21 // bounds, it returns nil. Otherwise, it always returns a cell, even if it
22 // is empty (i.e., a cell with a space character and a width of 1).
23 CellAt(x, y int) *Cell
24
25 // SetCell sets the cell at the given position. A nil cell is treated as an
26 // empty cell with a space character and a width of 1.
27 SetCell(x, y int, c *Cell)
28
29 // WidthMethod returns the width method used by the screen.
30 WidthMethod() WidthMethod
31}
32
33// CursorShape represents a terminal cursor shape.
34type CursorShape int
35
36// Cursor shapes.
37const (
38 CursorBlock CursorShape = iota
39 CursorUnderline
40 CursorBar
41)
42
43// Encode returns the encoded value for the cursor shape.
44func (s CursorShape) Encode(blink bool) int {
45 // We're using the ANSI escape sequence values for cursor styles.
46 // We need to map both [style] and [steady] to the correct value.
47 s = (s * 2) + 1 //nolint:mnd
48 if !blink {
49 s++
50 }
51 return int(s)
52}