characters

package
v0.1.0-beta.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2025 License: MIT Imports: 9 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 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 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 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) 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) Success

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

Success shows the success state animation

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 FrameSpec

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

FrameSpec defines a single frame using text patterns

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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