terminalpet

package
v0.14.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 27 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	// TextColumns and TextRows are the terminal cells a built-in companion
	// fills when it is drawn as text, for terminals that cannot show images.
	TextColumns = 18
	TextRows    = 8
)
View Source
const (
	DisabledID         = "disabled"
	DefaultManifestURL = "https://petdex.dev/api/manifest/v2"
	DefaultRankingURL  = "https://petdex.dev/api/pets/search?sort=installed&limit=60&includeMeta=0"
	TrustedAssetHost   = "assets.petdex.dev"
)

Variables

This section is empty.

Functions

func BuiltinSlug added in v0.14.0

func BuiltinSlug(form petart.Form) string

BuiltinSlug is the slug stored in config for a built-in companion.

Types

type Animation

type Animation struct {
	// contains filtered or unexported fields
}

func AtlasAnimation

func AtlasAnimation(sheet image.Image, spriteVersion int) (*Animation, error)

func BuiltinAnimation added in v0.14.0

func BuiltinAnimation(form petart.Form) *Animation

BuiltinAnimation returns the animation for a built-in companion, or nil for an unknown form. The animation is shared by every caller. Its frames are drawn when they are shown, and what is kept is the encoded PNG, not the much larger picture it was made from.

func PreviewAnimation

func PreviewAnimation(sheet image.Image) (*Animation, error)

func ThumbnailAnimation

func ThumbnailAnimation(imageValue image.Image) (*Animation, error)

func (*Animation) ClickAnimation

func (a *Animation) ClickAnimation(index int) (State, bool)

func (*Animation) ClickDuration

func (a *Animation) ClickDuration(state State) (time.Duration, bool)

ClickDuration reports the duration of an authored click action. The boolean is false for ordinary activity states and built-in interactions.

func (*Animation) Frame

func (a *Animation) Frame(state State, phase int) image.Image

func (*Animation) FrameDelay

func (a *Animation) FrameDelay(state State, phase int) time.Duration

func (*Animation) Has added in v0.14.0

func (a *Animation) Has(state State) bool

Has reports whether the animation has frames of its own for state. Frame shows the idle loop for any state the animation lacks.

func (*Animation) HasText added in v0.14.0

func (a *Animation) HasText() bool

HasText reports whether the animation can be drawn as text, for terminals that cannot show images. Only built-in companions can.

func (*Animation) PrimaryDuration

func (a *Animation) PrimaryDuration(state State) time.Duration

PrimaryDuration reports how long a non-idle action plays before it settles into its fallback loop. A zero duration means the state loops from its first frame or has no configured playback boundary.

func (*Animation) TextFrame added in v0.14.0

func (a *Animation) TextFrame(state State, phase int, colors TextColors) ([]string, bool)

TextFrame returns one frame as TextRows lines of styled text, TextColumns cells wide, in the given colour depth. The boolean is false for animations made from pictures, which have no text form.

type Client

type Client struct {
	RootDir      string
	ManifestURL  string
	RankingURL   string
	HTTPClient   *http.Client
	TrustedHosts map[string]bool
	// TrustedAssetHosts is narrower than TrustedHosts: catalog redirects may use
	// petdex.dev, while image and metadata downloads must stay on the asset host.
	TrustedAssetHosts map[string]bool
	Now               func() time.Time
}

func NewClient

func NewClient(rootDir string) *Client

func (*Client) Catalog

func (c *Client) Catalog(ctx context.Context) ([]Entry, error)

Catalog lists every companion: the built-in ones first, then installed pets, then the rest of the community catalog. The built-in ones are always returned. When the community catalog cannot be loaded the error comes back alongside whatever could be listed, so a caller can show both.

func (*Client) Install

func (c *Client) Install(ctx context.Context, entry Entry) (*Animation, error)

func (*Client) InstalledEntries

func (c *Client) InstalledEntries() ([]Entry, error)

InstalledEntries lists the companions that need no download: the built-in ones, then installed pets.

func (*Client) InstalledEntry

func (c *Client) InstalledEntry(slug string) (Entry, error)

func (*Client) LoadInstalled

func (c *Client) LoadInstalled(slug string) (*Animation, error)

func (*Client) Preview

func (c *Client) Preview(ctx context.Context, entry Entry) (*Animation, error)

type Entry

type Entry struct {
	Slug           string `json:"slug"`
	DisplayName    string `json:"displayName"`
	Kind           string `json:"kind,omitempty"`
	SubmittedBy    string `json:"submittedBy,omitempty"`
	SpritesheetURL string `json:"spritesheet"`
	PetJSONURL     string `json:"petJson,omitempty"`
	AssetBase      string `json:"assetBase,omitempty"`
	SpriteVersion  int    `json:"spriteVersionNumber"`
	Local          bool   `json:"-"`
	// Builtin marks a companion that ships inside Zero and is drawn by code.
	Builtin bool `json:"-"`
}

func BuiltinEntries added in v0.14.0

func BuiltinEntries() []Entry

BuiltinEntries lists the built-in companions in the order they are offered.

func ResolveBuiltin added in v0.14.0

func ResolveBuiltin(name string) (Entry, bool)

ResolveBuiltin finds a built-in companion by slug, id or display name, ignoring case and surrounding space.

func (Entry) Label

func (e Entry) Label() string

type ImageDraw

type ImageDraw struct {
	ID           uint32
	Animation    *Animation
	State        State
	Phase        int
	X            int
	Y            int
	OffsetX      int
	OffsetY      int
	Columns      int
	Rows         int
	HeightPixels int
}

type ImageProtocol

type ImageProtocol uint8
const (
	ImageProtocolNone ImageProtocol = iota
	ImageProtocolKitty
	ImageProtocolKittyLocalFile
	ImageProtocolSixel
)

type ImageRenderer

type ImageRenderer struct {
	// contains filtered or unexported fields
}

func NewImageRenderer

func NewImageRenderer(support ImageSupport) *ImageRenderer

func NewImageRendererWithCache

func NewImageRendererWithCache(support ImageSupport, cacheDir string) *ImageRenderer

func (*ImageRenderer) Clear

func (r *ImageRenderer) Clear(writer io.Writer) error

func (*ImageRenderer) DeleteImages

func (r *ImageRenderer) DeleteImages(writer io.Writer, ids ...uint32) error

DeleteImages removes known application-owned Kitty image placements even when this renderer no longer considers them active. This is intended for process shutdown and recovery from a previous interrupted render.

func (*ImageRenderer) Invalidate

func (r *ImageRenderer) Invalidate()

func (*ImageRenderer) Render

func (r *ImageRenderer) Render(writer io.Writer) error

func (*ImageRenderer) Set

func (r *ImageRenderer) Set(draw *ImageDraw)

func (*ImageRenderer) Support

func (r *ImageRenderer) Support() ImageSupport

type ImageSupport

type ImageSupport struct {
	Protocol ImageProtocol
	Reason   string
}

func DetectImageSupport

func DetectImageSupport(getenv func(string) string) ImageSupport

func (ImageSupport) Supported

func (s ImageSupport) Supported() bool

type State

type State string
const (
	Dance    State = "dance"
	Lunge    State = "lunge"
	Thinking State = "thinking"
	Sleeping State = "sleeping"
)

Extra states the built-in companions have. Dance and Lunge play when the companion is clicked. Thinking and Sleeping are agent states: pets without those animations show Running and Idle instead (see Animation.Has), and a community pet whose pet.json defines them gets them too.

const (
	Idle      State = "idle"
	MoveRight State = "running-right"
	MoveLeft  State = "running-left"
	Waving    State = "waving"
	Jumping   State = "jumping"
	Running   State = "running"
	Waiting   State = "waiting"
	Review    State = "review"
	Failed    State = "failed"
)

type TextColors added in v0.14.0

type TextColors uint8

TextColors is the colour depth text frames are drawn for.

const (
	// TextTrueColor draws with the art's exact 24-bit colours.
	TextTrueColor TextColors = iota
	// Text256 draws with a fixed 256-colour palette, the nearest colour to
	// each art colour by CIEDE2000, which keeps hues a generic conversion
	// would lose.
	Text256
)

Directories

Path Synopsis
Package petart draws Zero's built-in terminal companions.
Package petart draws Zero's built-in terminal companions.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL