pet

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 37 Imported by: 1 module, 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 (
	FrameW          = 192
	FrameH          = 208
	FramesPerState  = 6
	LoopMS          = 1100
	DefaultScale    = 0.33
	MinScale        = 0.1
	MaxScale        = 3.0
	BaseUnicodeCols = FrameW / 8
	UnicodeMinCols  = 16
)
View Source
const (
	ManifestURL = "https://petdex.dev/api/manifest"
)

Public petdex manifest and the fetch, cache and download bounds of the store

Variables

View Source
var (
	States          = []State{StateIdle, StateWave, StateRun, StateFailed, StateReview, StateJump, StateWaiting}
	LegacyStateRows = []string{"idle", "wave", "run", "failed", "review", "jump", "extra1", "extra2"}
	CodexStateRows  = []string{"idle", "running-right", "running-left", "waving", "jumping", "failed", "waiting", "running", "review"}
	StateRows       = CodexStateRows

	StateAliases = func() map[string][]string {
		out := map[string][]string{}
		for _, s := range []string{"idle", "wave", "jump", "run", "failed", "review", "waiting"} {
			out[s] = []string{s}
			if alias, ok := codexNames[s]; ok {
				out[s] = []string{s, alias}
			}
		}
		return out
	}()
)
View Source
var (
	RenderModes = []string{"auto", "kitty", "iterm", "sixel", "unicode", "off"}
)

Functions

func CfgText

func CfgText(cfg map[string]any, key string) string

str of a config value or empty when falsy

func ClampScale

func ClampScale(scale float64) float64

ClampScale keeps a scale inside the user settable bounds

func ColsForScale

func ColsForScale(scale float64) int

ColsForScale is the half block width a scale implies, never under the legibility floor

func DetectTerminalGraphics

func DetectTerminalGraphics() string

DetectTerminalGraphics names the richest protocol the environment variables promise, never querying the terminal

func DisplayNameFor

func DisplayNameFor(concept string) string

Short name of the first three capitalized words of a concept cut to 28 runes, empty for none

func DownscaleCells

func DownscaleCells(frame *image.NRGBA, targetCols int) [][]Cell

Rows of half block cells of a frame downscaled to the target column count

func Enabled

func Enabled(cfg map[string]any) bool

Whether display.pet.enabled is truthy

func ExportPet

func ExportPet(h, slug string) (string, []byte, error)

Zips an installed pet's folder as its file name and bytes, dotfiles skipped

func KittyColorHex

func KittyColorHex(imageID int) string

KittyColorHex is the foreground colour that encodes an image id for kitty

func KittyImageID

func KittyImageID(slug string) int

Deterministic non zero image id of a slug, carried to the terminal in the cell foreground colour

func KittyPlaceholderRows

func KittyPlaceholderRows(cols, rows int) []string

Builds the text grid kitty paints the image under, each row led by its row diacritic

func PetsDir

func PetsDir(h string) (string, error)

PetsDir returns the pets directory of a home, created on demand

func Prefetch

func Prefetch(ctx context.Context, env *tools.Env)

Warms the manifest cache on its own goroutine, idempotent and never blocking

func RemovePet

func RemovePet(h, slug string) (bool, error)

Deletes an installed pet and its cached thumbnail, true when the directory is gone

func RenamePet

func RenamePet(h, slug, displayName string) (string, error)

Renames a pet's display name and moves its directory and thumb to the slug of that name when free, empty on failure

func ResolveCols

func ResolveCols(scale float64, unicodeCols int) int

ResolveCols returns the explicit column override when positive, else the width the scale implies

func ResolveMode

func ResolveMode(configured string, isTTY bool) string

ResolveMode returns the effective render mode from the configured one and the environment, off when not a tty

func RowFrameCounts

func RowFrameCounts(path string) (map[string]int, error)

Real frame count of every concrete row of a sheet, the frames before its first blank cell

func SheetFrameEscapes

func SheetFrameEscapes(sheet *image.NRGBA, state, mode string, frameW, frameH, framesPerState int, scale float64) ([]string, int, int)

Frames of a state of a decoded sheet scaled and encoded as the renderer frame does in sixel or iterm mode, with their pixel size

func SheetFrames

func SheetFrames(sheet *image.NRGBA, state string, frameW, frameH, framesPerState int) []*image.NRGBA

Cropped frames of one state row of a decoded spritesheet up to the first blank column

func SheetRowCount

func SheetRowCount(path string) (int, error)

Row count of a sheet in frame heights, at least one

func Slugify

func Slugify(name string) string

Lowercased hyphenated filesystem slug of a display name, pet when nothing remains

func StateAliasesFor

func StateAliasesFor(state string) []string

StateAliasesFor returns the accepted row names of a state, the state itself when it has none

func StateFrameCounts

func StateFrameCounts(sheetPath string) map[string]int

StateFrameCounts maps every driven state to its frame count with the blank padding trimmed

func StateRowIndex

func StateRowIndex(state string, rowCount int) int

StateRowIndex returns the spritesheet row of a state, the idle row when the sheet has no such row

func StateRowsForGrid

func StateRowsForGrid(rowCount int) []string

StateRowsForGrid returns the row taxonomy of a spritesheet with the given row count

func SupportsKittyPlaceholders

func SupportsKittyPlaceholders() bool

Reports a terminal that paints the kitty virtual image cells, which WezTerm speaks but cannot draw

func UniqueSlug

func UniqueSlug(h, name string) (string, error)

Slug of the name that does not collide with an existing pet directory

Types

type Cell

type Cell [2][4]uint8

Cell is one half block cell, its top and bottom pixel as red, green, blue and alpha

type InstalledPet

type InstalledPet struct {
	Slug, DisplayName, Description, Directory, Spritesheet, CreatedBy string
}

InstalledPet is a pet present on disk

func InstallPet

func InstallPet(ctx context.Context, env *tools.Env, h, slug string, force bool) (*InstalledPet, error)

Downloads a manifest pet into the pets directory, idempotent unless forced

func InstalledPets

func InstalledPets(h string) ([]*InstalledPet, error)

InstalledPets returns every pet directory holding a usable spritesheet, in name order

func LoadPet

func LoadPet(h, slug string) (*InstalledPet, error)

LoadPet returns the installed pet of a slug, nil when the pets directory holds no such pet

func RegisterLocalPet

func RegisterLocalPet(h string, spritesheet image.Image, encoded []byte, slug, displayName, description string) (*InstalledPet, error)

Writes a locally generated pet into the store as a lossless WebP spritesheet marked as generator made

func ResolveActivePet

func ResolveActivePet(h, configuredSlug string) (*InstalledPet, error)

ResolveActivePet returns the configured pet when installed, else the first pet alphabetically

func (*InstalledPet) Exists

func (p *InstalledPet) Exists() bool

Exists reports the spritesheet file on disk

func (*InstalledPet) Generated

func (p *InstalledPet) Generated() bool

Generated reports a pet hatched locally by the generator

type KittyPayload

type KittyPayload struct {
	Cols, Rows  int
	Placeholder []string
	Frames      []string
}

KittyPayload carries one state as kitty virtual placements, the transmit escapes plus the static text grid

type ManifestEntry

type ManifestEntry struct {
	Slug, DisplayName, Kind, SubmittedBy, SpritesheetURL, PetJSONURL, ZipURL string
}

One pet row of the public petdex manifest

func FetchManifest

func FetchManifest(ctx context.Context, env *tools.Env, force bool) ([]ManifestEntry, error)

Every approved pet of the public manifest, cached for five minutes unless forced

func FindEntry

func FindEntry(ctx context.Context, env *tools.Env, slug string) (*ManifestEntry, error)

Manifest entry of a slug compared case insensitively, nil when not listed

func ManifestEntryFromDict

func ManifestEntryFromDict(d *pyjson.Object) ManifestEntry

Manifest row from its dict with the display name, kind and URLs defaulted

type ManifestError

type ManifestError struct{ Msg string }

Raised when the manifest cannot be fetched or parsed

func (*ManifestError) Error

func (e *ManifestError) Error() string

func (*ManifestError) PyTypeName

func (e *ManifestError) PyTypeName() string

type Renderer

type Renderer struct {
	Spritesheet                    string
	Mode                           string
	Scale                          float64
	UnicodeCols                    int
	FrameW, FrameH, FramesPerState int
}

Renderer holds a pet spritesheet and yields encoded frames per state and index

func BuildRenderer

func BuildRenderer(spritesheet, configuredMode string, scale float64, unicodeCols int, isTTY bool) *Renderer

BuildRenderer resolves the mode from the configured one and the environment and constructs the renderer

func NewRenderer

func NewRenderer(spritesheet, mode string, scale float64, unicodeCols int) *Renderer

NewRenderer builds a renderer with the frame geometry defaults, an unknown mode reading as unicode

func (*Renderer) Available

func (r *Renderer) Available() bool

Available reports a renderer that is on and whose spritesheet file exists

func (*Renderer) Cells

func (r *Renderer) Cells(state string, index, cols int) [][]Cell

Cells returns one frame as a half block grid at cols columns, the renderer width when cols is zero

func (*Renderer) Frame

func (r *Renderer) Frame(state string, index int) string

Frame returns the encoded escape string of one frame, empty when the renderer is off or the state has none

func (*Renderer) FrameCount

func (r *Renderer) FrameCount(state string) int

FrameCount returns how many frames the state animates through

func (*Renderer) KittyPayload

func (r *Renderer) KittyPayload(state string, imageID int) *KittyPayload

Builds the virtual placement escapes and text grid of a state, nil when the state has no frames

type Run

type Run struct {
	Ctx  context.Context
	Home string
	W    io.Writer
	Env  *tools.Env
}

One pet operation with its profile home, output writer and tool environment

func (*Run) HasActivePet

func (r *Run) HasActivePet() (bool, error)

Whether a pet is enabled and a slug is configured

func (*Run) PetConfig

func (r *Run) PetConfig() (map[string]any, error)

display.pet config dict, empty when absent or not a dict

func (*Run) SetActive

func (r *Run) SetActive(slug string) error

func (*Run) SetPetScale

func (r *Run) SetPetScale(value any) (float64, string, error)

Persists the clamped display.pet.scale, a message and nothing written when the value is not a number

func (*Run) UpdatePetConfig

func (r *Run) UpdatePetConfig(whenSlug *string, values ...any) (bool, error)

Writes display.pet keys and saves config, only when the configured slug matches whenSlug if given

type Signals

type Signals struct {
	Busy, AwaitingInput, Error, Celebrate, JustCompleted, ToolRunning, Reasoning bool
}

Signals are the coarse activity flags an animation state is derived from

type State

type State string

State is an animation state a pet can be shown in

const (
	StateIdle    State = "idle"
	StateWave    State = "wave"
	StateRun     State = "run"
	StateFailed  State = "failed"
	StateReview  State = "review"
	StateJump    State = "jump"
	StateWaiting State = "waiting"
)

func DeriveState

func DeriveState(s Signals) State

DeriveState resolves the animation state from the activity signals, the most salient one winning

type StoreError

type StoreError struct{ Msg string }

StoreError is raised on install and IO failures of the pet store

func (*StoreError) Error

func (e *StoreError) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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