characters

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ColorizeFrame added in v0.2.0

func ColorizeFrame(frame domain.Frame, hexColor string) []string

ColorizeFrame compiles pattern codes and applies ANSI RGB colors. Returns compiled lines with color codes applied. If hexColor is empty, returns compiled lines without color.

This is useful for consumers who need pre-colored frames for custom animation systems (e.g., Bubble Tea TUI frameworks).

Example:

agent, _ := characters.LibraryAgent("mercury")
char := agent.GetCharacter()
frame := char.States["wait"].Frames[0]
coloredLines := ColorizeFrame(frame, char.Color)
for _, line := range coloredLines {
    fmt.Println(line)  // Prints in silver color
}

func ColorizeString added in v0.2.0

func ColorizeString(text, hexColor string) string

ColorizeString wraps text with ANSI RGB color escape codes. Format: \x1b[38;2;R;G;Bm{text}\x1b[0m If hexColor is empty, returns text unchanged.

This is useful for applying colors to arbitrary strings or for consumers who already have compiled frame lines.

Example:

text := "  ▐▛███▜▌  "
colored := ColorizeString(text, "#C0C0C0")
fmt.Println(colored)  // Prints in silver color

func GetCurrentTheme added in v0.2.0

func GetCurrentTheme() string

GetCurrentTheme returns the name of the currently active theme

func HexToRGB added in v0.2.0

func HexToRGB(hex string) (r, g, b int)

HexToRGB converts hex color string to RGB values. Accepts both "#RRGGBB" and "RRGGBB" formats. Returns (0, 0, 0) for invalid input.

Example:

r, g, b := HexToRGB("#C0C0C0")  // r=192, g=192, b=192
r, g, b := HexToRGB("FF6B35")   // r=255, g=107, b=53

func LibraryInfo

func LibraryInfo(name string) (string, error)

LibraryInfo returns information about a library character

func ListLibrary

func ListLibrary() []string

ListLibrary returns all available library character names

func ListMicroLibrary added in v0.3.0

func ListMicroLibrary() []string

ListMicroLibrary returns all available micro character names

func ListThemes added in v0.2.0

func ListThemes() []string

ListThemes returns all available theme names

func SetTheme added in v0.2.0

func SetTheme(themeName string) error

SetTheme sets the global theme for all characters

func ShowIdle

func ShowIdle(writer interface{}, character *domain.Character) error

ShowIdle displays the idle state of a character

Types

type AgentCharacter added in v0.2.0

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

AgentCharacter wraps a Character with state-based API methods for AI agents

func LibraryAgent added in v0.2.0

func LibraryAgent(name string) (*AgentCharacter, error)

LibraryAgent retrieves a pre-built character from the built-in library with state-based API

func LibraryAgentMicro added in v0.3.0

func LibraryAgentMicro(name string) (*AgentCharacter, error)

LibraryAgentMicro retrieves a micro (10x2) character variant from the library

func NewAgentCharacter added in v0.2.0

func NewAgentCharacter(character *domain.Character) *AgentCharacter

NewAgentCharacter creates a new AgentCharacter wrapper

func (*AgentCharacter) AnimateState added in v0.2.0

func (a *AgentCharacter) AnimateState(writer io.Writer, stateName string, fps int, loops int) error

AnimateState animates a specific state with proper frame animation

func (*AgentCharacter) Error added in v0.2.0

func (a *AgentCharacter) Error(writer io.Writer) error

Error shows the error state animation

func (*AgentCharacter) Execute added in v0.2.0

func (a *AgentCharacter) Execute(writer io.Writer) error

Execute shows the executing state animation

func (*AgentCharacter) GetCharacter added in v0.2.0

func (a *AgentCharacter) GetCharacter() *domain.Character

GetCharacter returns the underlying domain.Character

func (*AgentCharacter) GetFrameCache added in v0.2.0

func (a *AgentCharacter) GetFrameCache() *FrameCache

GetFrameCache returns a pre-rendered frame cache for this character. All frames are compiled from patterns and colorized with the character's color. This provides O(1) frame access for high-performance animation systems.

Example:

agent, _ := characters.LibraryAgent("sam")
cache := agent.GetFrameCache()

// Get base frame
baseLines := cache.GetBaseFrame()
for _, line := range baseLines {
    fmt.Println(line)  // Already compiled and colored
}

// Get state frames
planFrames := cache.GetStateFrames("plan")
for _, frame := range planFrames {
    for _, line := range frame {
        fmt.Println(line)  // Already compiled and colored
    }
}

func (*AgentCharacter) GetStateDescription added in v0.2.0

func (a *AgentCharacter) GetStateDescription(stateName string) (string, error)

GetStateDescription returns the description of a specific state

func (*AgentCharacter) HasState added in v0.2.0

func (a *AgentCharacter) HasState(stateName string) bool

HasState checks if a specific state exists

func (*AgentCharacter) ListStates added in v0.2.0

func (a *AgentCharacter) ListStates() []string

ListStates returns all available state names for this character

func (*AgentCharacter) Name added in v0.2.0

func (a *AgentCharacter) Name() string

Name returns the character's name

func (*AgentCharacter) Personality added in v0.2.0

func (a *AgentCharacter) Personality() string

Personality returns the character's personality

func (*AgentCharacter) Plan added in v0.2.0

func (a *AgentCharacter) Plan(writer io.Writer) error

Plan shows the planning state animation

func (*AgentCharacter) ShowBase added in v0.2.0

func (a *AgentCharacter) ShowBase(writer io.Writer) error

ShowBase displays the base (idle) character

func (*AgentCharacter) ShowState added in v0.2.0

func (a *AgentCharacter) ShowState(writer io.Writer, stateName string) error

ShowState displays a specific agent state by name

func (*AgentCharacter) Think added in v0.2.0

func (a *AgentCharacter) Think(writer io.Writer) error

Think shows the thinking state animation

func (*AgentCharacter) Wait added in v0.2.0

func (a *AgentCharacter) Wait(writer io.Writer) error

Wait shows the waiting state animation

type CharacterService added in v0.2.0

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

CharacterService provides character creation functionality

func NewCharacterService added in v0.2.0

func NewCharacterService() *CharacterService

NewCharacterService creates a new character service with default implementations

func (*CharacterService) CreateCharacter added in v0.2.0

func (cs *CharacterService) CreateCharacter(spec domain.CharacterSpec) (*domain.Character, error)

CreateCharacter creates a character from a domain spec

type CharacterSpec

type CharacterSpec struct {
	Name   string      `json:"name"`
	Width  int         `json:"width"`
	Height int         `json:"height"`
	Frames []FrameSpec `json:"frames"`
}

CharacterSpec defines a character using simple text patterns

func NewCharacterSpec

func NewCharacterSpec(name string, width, height int) *CharacterSpec

NewCharacterSpec creates a new character specification

func (*CharacterSpec) AddFrame

func (cs *CharacterSpec) AddFrame(name string, patterns []string) *CharacterSpec

AddFrame adds a frame to the character specification

func (*CharacterSpec) AddFrameFromString

func (cs *CharacterSpec) AddFrameFromString(name, pattern string) *CharacterSpec

AddFrameFromString adds a frame from a single string pattern

func (*CharacterSpec) Build

func (cs *CharacterSpec) Build() (*domain.Character, error)

Build compiles the character specification into a domain.Character

func (*CharacterSpec) String

func (cs *CharacterSpec) String() string

String returns a string representation of the character specification

func (*CharacterSpec) Validate

func (cs *CharacterSpec) Validate() error

Validate checks if the character specification is valid

type FrameCache added in v0.2.0

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

FrameCache provides O(1) access to pre-rendered, pre-colored frames This is useful for TUI frameworks that need fast frame access during 60 FPS animations without repeated pattern compilation and colorization.

func (*FrameCache) GetBaseFrame added in v0.2.0

func (fc *FrameCache) GetBaseFrame() []string

GetBaseFrame returns the pre-rendered base (idle) frame

func (*FrameCache) GetCharacterName added in v0.2.0

func (fc *FrameCache) GetCharacterName() string

GetCharacterName returns the character name

func (*FrameCache) GetColor added in v0.2.0

func (fc *FrameCache) GetColor() string

GetColor returns the character's hex color

func (*FrameCache) GetStateFrames added in v0.2.0

func (fc *FrameCache) GetStateFrames(stateName string) [][]string

GetStateFrames returns all pre-rendered frames for a given state. Returns nil if the state doesn't exist. Each element in the outer slice is a frame ([]string lines).

func (*FrameCache) HasState added in v0.2.0

func (fc *FrameCache) HasState(stateName string) bool

HasState checks if a state exists in the cache

func (*FrameCache) ListStates added in v0.2.0

func (fc *FrameCache) ListStates() []string

ListStates returns all available state names in the cache

type FrameSpec

type FrameSpec struct {
	Name     string   `json:"name"`
	Patterns []string `json:"patterns"`
}

FrameSpec defines a single frame using text patterns

Directories

Path Synopsis
Package client provides a framework-agnostic animation controller for tangent characters.
Package client provides a framework-agnostic animation controller for tangent characters.
Package microstateregistry provides types and loading for micro (10x2) avatar definitions.
Package microstateregistry provides types and loading for micro (10x2) avatar definitions.

Jump to

Keyboard shortcuts

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