pokesay

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2025 License: BSD-3-Clause Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Rand rand.Source = rand.NewSource(time.Now().UnixNano())
)

Functions

func BuildANSIString added in v0.16.0

func BuildANSIString(lines [][]ANSILineToken, padding int) string

func ChooseByCategory added in v0.11.0

func ChooseByCategory(category string, categoryDir []fs.DirEntry, categoryFiles embed.FS, categoryRootDir string, metadataFiles embed.FS, metadataRootDir string) (pokedex.PokemonMetadata, pokedex.PokemonEntryMapping)

ChooseByCategory chooses a pokemon via a requested category 1. It loads the category search structure and finds the name of a random Pokemon matching the entry e.g. if given the category "small", this function might pick the file `1.cat` in - categories/

  • small/
  • 1.cat
  • 44.cat

This file contains entries representing the <pokemon metadata index>/<the pokemon entry index>, e.g. "4/1" would represent 4.metadata, and the 2nd entry in that file 2. Using the indexes, load the corresponding metadata file and entry, and then return it

func ChooseByIndex added in v0.17.0

func ChooseByIndex(idx int, entryIdx int, metadataFiles embed.FS, metadataRootDir string) (pokedex.PokemonMetadata, pokedex.PokemonEntryMapping, error)

func ChooseByName added in v0.11.0

func ChooseByName(names map[string][]int, nameToken string, metadataFiles embed.FS, metadataRootDir string) (pokedex.PokemonMetadata, pokedex.PokemonEntryMapping)

func ChooseByNameAndCategory added in v0.12.2

func ChooseByNameAndCategory(names map[string][]int, nameToken string, metadataFiles embed.FS, metadataRootDir string, category string) (pokedex.PokemonMetadata, pokedex.PokemonEntryMapping)

func ChooseByRandomIndex added in v0.11.0

func ChooseByRandomIndex(totalInBytes []byte) (int, int)

func ListNames added in v0.11.3

func ListNames(names map[string][]int) []string

func Print added in v0.11.0

func Print(args Args, choice int, names []string, categories []string, cows embed.FS)

The main print function! This uses a chosen pokemon's index, names and categories, and an embedded filesystem of cowfile data 1. The text received from STDIN is printed inside a speech bubble 2. The cowfile data is retrieved using the matching index, decompressed (un-gzipped), 3. The pokemon is printed along with the name & category information

func RandomInt

func RandomInt(n int) int

func ReverseANSIString added in v0.16.0

func ReverseANSIString(lines [][]ANSILineToken) [][]ANSILineToken

func ReverseUnicodeString added in v0.16.0

func ReverseUnicodeString(s string) string

func TokeniseANSIString added in v0.16.0

func TokeniseANSIString(msg string) [][]ANSILineToken

func UnicodeStringLength added in v0.14.0

func UnicodeStringLength(s string) int

Returns the length of a string, taking into account Unicode characters and ANSI escape codes.

Types

type ANSILineToken added in v0.16.0

type ANSILineToken struct {
	FG string
	BG string
	T  string
}

type Args added in v0.11.0

type Args struct {
	Width          int
	NoWrap         bool
	DrawBubble     bool
	TabSpaces      string
	NoTabSpaces    bool
	NoCategoryInfo bool
	ListCategories bool
	ListNames      bool
	ListNameToken  string
	Category       string
	NameToken      string
	IDToken        string
	JapaneseName   bool
	ShowID         bool
	BoxChars       *BoxChars
	DrawInfoBorder bool
	FlipPokemon    bool
	Help           bool
	Verbose        bool
}

type BoxChars added in v0.14.2

type BoxChars struct {
	HorizontalEdge    string
	VerticalEdge      string
	TopRightCorner    string
	TopLeftCorner     string
	BottomRightCorner string
	BottomLeftCorner  string
	BalloonString     string
	BalloonTether     string
	Separator         string
	RightArrow        string
	CategorySeparator string
}
var (
	AsciiBoxChars *BoxChars = &BoxChars{
		HorizontalEdge:    "-",
		VerticalEdge:      "|",
		TopRightCorner:    "\\",
		TopLeftCorner:     "/",
		BottomRightCorner: "/",
		BottomLeftCorner:  "\\",
		BalloonString:     "\\",
		BalloonTether:     "¡",
		Separator:         "|",
		RightArrow:        ">",
		CategorySeparator: "/",
	}
	UnicodeBoxChars *BoxChars = &BoxChars{
		HorizontalEdge:    "─",
		VerticalEdge:      "│",
		TopRightCorner:    "╮",
		TopLeftCorner:     "╭",
		BottomRightCorner: "╯",
		BottomLeftCorner:  "╰",
		BalloonString:     "╲",
		BalloonTether:     "╲",
		Separator:         "│",
		RightArrow:        "→",
		CategorySeparator: "/",
	}
	SingleWidthChars map[string]bool = map[string]bool{
		"♀": true,
		"♂": true,
	}
)

func DetermineBoxChars added in v0.14.2

func DetermineBoxChars(unicodeBox bool) *BoxChars

Jump to

Keyboard shortcuts

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