1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
package vt
import uv "github.com/charmbracelet/ultraviolet"
// Damage represents a damaged area.
type Damage interface {
// Bounds returns the bounds of the damaged area.
Bounds() uv.Rectangle
}
// CellDamage represents a damaged cell.
type CellDamage struct {
X, Y int
Width int
}
// Bounds returns the bounds of the damaged area.
func (d CellDamage) Bounds() uv.Rectangle {
return uv.Rect(d.X, d.Y, d.Width, 1)
}
// RectDamage represents a damaged rectangle.
type RectDamage uv.Rectangle
// Bounds returns the bounds of the damaged area.
func (d RectDamage) Bounds() uv.Rectangle {
return uv.Rectangle(d)
}
// X returns the x-coordinate of the damaged area.
func (d RectDamage) X() int {
return uv.Rectangle(d).Min.X
}
// Y returns the y-coordinate of the damaged area.
func (d RectDamage) Y() int {
return uv.Rectangle(d).Min.Y
}
// Width returns the width of the damaged area.
func (d RectDamage) Width() int {
return uv.Rectangle(d).Dx()
}
// Height returns the height of the damaged area.
func (d RectDamage) Height() int {
return uv.Rectangle(d).Dy()
}
// ScreenDamage represents a damaged screen.
type ScreenDamage struct {
Width, Height int
}
// Bounds returns the bounds of the damaged area.
func (d ScreenDamage) Bounds() uv.Rectangle {
return uv.Rect(0, 0, d.Width, d.Height)
}
// MoveDamage represents a moved area.
// The area is moved from the source to the destination.
type MoveDamage struct {
Src, Dst uv.Rectangle
}
// ScrollDamage represents a scrolled area.
// The area is scrolled by the given deltas.
type ScrollDamage struct {
uv.Rectangle
Dx, Dy int
}
|