Documentation
¶
Index ¶
- Constants
- func BuiltinSlug(form petart.Form) string
- type Animation
- func (a *Animation) ClickAnimation(index int) (State, bool)
- func (a *Animation) ClickDuration(state State) (time.Duration, bool)
- func (a *Animation) Frame(state State, phase int) image.Image
- func (a *Animation) FrameDelay(state State, phase int) time.Duration
- func (a *Animation) Has(state State) bool
- func (a *Animation) HasText() bool
- func (a *Animation) PrimaryDuration(state State) time.Duration
- func (a *Animation) TextFrame(state State, phase int, colors TextColors) ([]string, bool)
- type Client
- func (c *Client) Catalog(ctx context.Context) ([]Entry, error)
- func (c *Client) Install(ctx context.Context, entry Entry) (*Animation, error)
- func (c *Client) InstalledEntries() ([]Entry, error)
- func (c *Client) InstalledEntry(slug string) (Entry, error)
- func (c *Client) LoadInstalled(slug string) (*Animation, error)
- func (c *Client) Preview(ctx context.Context, entry Entry) (*Animation, error)
- type Entry
- type ImageDraw
- type ImageProtocol
- type ImageRenderer
- func (r *ImageRenderer) Clear(writer io.Writer) error
- func (r *ImageRenderer) DeleteImages(writer io.Writer, ids ...uint32) error
- func (r *ImageRenderer) Invalidate()
- func (r *ImageRenderer) Render(writer io.Writer) error
- func (r *ImageRenderer) Set(draw *ImageDraw)
- func (r *ImageRenderer) Support() ImageSupport
- type ImageSupport
- type State
- type TextColors
Constants ¶
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 )
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
BuiltinSlug is the slug stored in config for a built-in companion.
Types ¶
type Animation ¶
type Animation struct {
// contains filtered or unexported fields
}
func BuiltinAnimation ¶ added in v0.14.0
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 (*Animation) ClickDuration ¶
ClickDuration reports the duration of an authored click action. The boolean is false for ordinary activity states and built-in interactions.
func (*Animation) Has ¶ added in v0.14.0
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
HasText reports whether the animation can be drawn as text, for terminals that cannot show images. Only built-in companions can.
func (*Animation) PrimaryDuration ¶
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.
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 (*Client) Catalog ¶
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) InstalledEntries ¶
InstalledEntries lists the companions that need no download: the built-in ones, then installed pets.
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
ResolveBuiltin finds a built-in companion by slug, id or display name, ignoring case and surrounding space.
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) 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) 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.
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 )