Documentation
¶
Index ¶
- Constants
- Variables
- func CfgText(cfg map[string]any, key string) string
- func ClampScale(scale float64) float64
- func ColsForScale(scale float64) int
- func DetectTerminalGraphics() string
- func DisplayNameFor(concept string) string
- func DownscaleCells(frame *image.NRGBA, targetCols int) [][]Cell
- func Enabled(cfg map[string]any) bool
- func ExportPet(h, slug string) (string, []byte, error)
- func KittyColorHex(imageID int) string
- func KittyImageID(slug string) int
- func KittyPlaceholderRows(cols, rows int) []string
- func PetsDir(h string) (string, error)
- func Prefetch(ctx context.Context, env *tools.Env)
- func RemovePet(h, slug string) (bool, error)
- func RenamePet(h, slug, displayName string) (string, error)
- func ResolveCols(scale float64, unicodeCols int) int
- func ResolveMode(configured string, isTTY bool) string
- func RowFrameCounts(path string) (map[string]int, error)
- func SheetFrameEscapes(sheet *image.NRGBA, state, mode string, frameW, frameH, framesPerState int, ...) ([]string, int, int)
- func SheetFrames(sheet *image.NRGBA, state string, frameW, frameH, framesPerState int) []*image.NRGBA
- func SheetRowCount(path string) (int, error)
- func Slugify(name string) string
- func StateAliasesFor(state string) []string
- func StateFrameCounts(sheetPath string) map[string]int
- func StateRowIndex(state string, rowCount int) int
- func StateRowsForGrid(rowCount int) []string
- func SupportsKittyPlaceholders() bool
- func UniqueSlug(h, name string) (string, error)
- type Cell
- type InstalledPet
- func InstallPet(ctx context.Context, env *tools.Env, h, slug string, force bool) (*InstalledPet, error)
- func InstalledPets(h string) ([]*InstalledPet, error)
- func LoadPet(h, slug string) (*InstalledPet, error)
- func RegisterLocalPet(h string, spritesheet image.Image, encoded []byte, ...) (*InstalledPet, error)
- func ResolveActivePet(h, configuredSlug string) (*InstalledPet, error)
- type KittyPayload
- type ManifestEntry
- type ManifestError
- type Renderer
- type Run
- type Signals
- type State
- type StoreError
Constants ¶
const ( FrameW = 192 FrameH = 208 FramesPerState = 6 LoopMS = 1100 DefaultScale = 0.33 MinScale = 0.1 MaxScale = 3.0 BaseUnicodeCols = FrameW / 8 UnicodeMinCols = 16 )
const (
ManifestURL = "https://petdex.dev/api/manifest"
)
Public petdex manifest and the fetch, cache and download bounds of the store
Variables ¶
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 }() )
var (
RenderModes = []string{"auto", "kitty", "iterm", "sixel", "unicode", "off"}
)
Functions ¶
func ClampScale ¶
ClampScale keeps a scale inside the user settable bounds
func ColsForScale ¶
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 ¶
Short name of the first three capitalized words of a concept cut to 28 runes, empty for none
func DownscaleCells ¶
Rows of half block cells of a frame downscaled to the target column count
func KittyColorHex ¶
KittyColorHex is the foreground colour that encodes an image id for kitty
func KittyImageID ¶
Deterministic non zero image id of a slug, carried to the terminal in the cell foreground colour
func KittyPlaceholderRows ¶
Builds the text grid kitty paints the image under, each row led by its row diacritic
func RenamePet ¶
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 ¶
ResolveCols returns the explicit column override when positive, else the width the scale implies
func ResolveMode ¶
ResolveMode returns the effective render mode from the configured one and the environment, off when not a tty
func RowFrameCounts ¶
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 ¶
Row count of a sheet in frame heights, at least one
func StateAliasesFor ¶
StateAliasesFor returns the accepted row names of a state, the state itself when it has none
func StateFrameCounts ¶
StateFrameCounts maps every driven state to its frame count with the blank padding trimmed
func StateRowIndex ¶
StateRowIndex returns the spritesheet row of a state, the idle row when the sheet has no such row
func StateRowsForGrid ¶
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 ¶
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 ¶
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 ¶
Every approved pet of the public manifest, cached for five minutes unless forced
func ManifestEntryFromDict ¶
func ManifestEntryFromDict(d *jsonutil.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) ErrorKind ¶
func (e *ManifestError) ErrorKind() 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 ¶
NewRenderer builds a renderer with the frame geometry defaults, an unknown mode reading as unicode
func (*Renderer) Available ¶
Available reports a renderer that is on and whose spritesheet file exists
func (*Renderer) Cells ¶
Cells returns one frame as a half block grid at cols columns, the renderer width when cols is zero
func (*Renderer) Frame ¶
Frame returns the encoded escape string of one frame, empty when the renderer is off or the state has none
func (*Renderer) FrameCount ¶
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 ¶
One pet operation with its profile home, output writer and tool environment
func (*Run) HasActivePet ¶
Whether a pet is enabled and a slug is configured
func (*Run) SetPetScale ¶
Persists the clamped display.pet.scale, numbers past either bound clamped, a message and nothing written when the value is not a number
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
func DeriveState ¶
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