tui

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GradientUpDown = iota
	GradientDownUp
	GradientLeftRight
	GradientRightLeft
)

Gradient direction constants for TUI usage

View Source
const (
	ShadowLight = iota
	ShadowMedium
	ShadowDark
)

Shadow style constants for TUI usage

Variables

View Source
var ANSIColorMap = map[string]string{
	"30": "#000000",
	"31": "#CD3131",
	"32": "#0DBC79",
	"33": "#E5E510",
	"34": "#2472C8",
	"35": "#BC3FBC",
	"36": "#11A8CD",
	"37": "#E5E5E5",
	"90": "#808080",
	"91": "#FF9999",
	"92": "#99FF99",
	"93": "#FFFF99",
	"94": "#66BBFF",
	"95": "#FF99FF",
	"96": "#99FFFF",
	"97": "#FFFFFF",
}

ANSIColorMap provides mappings from ANSI color codes to hex values This is the canonical color mapping used throughout the library

Functions

func ApplyHorizontalAlignment

func ApplyHorizontalAlignment(line string, canvasWidth int, alignment HorizontalAlignment) string

ApplyHorizontalAlignment applies horizontal alignment to a single line of text.

func ApplyVerticalAlignment

func ApplyVerticalAlignment(lines []string, canvasHeight int, alignment VerticalAlignment) []string

ApplyVerticalAlignment applies vertical alignment to a set of lines.

func CreateAnimationPreview

func CreateAnimationPreview(animName, theme, file string, width, height int) string

CreateAnimationPreview creates a static preview of the animation config

func DetectHalfPixelUsage

func DetectHalfPixelUsage(text string, fontData FontData, scaleFactor float64) bool

DetectHalfPixelUsage checks if the current text rendering would use half-pixels that would interfere with shadow rendering. This function should only return true when shadows would actually cause visual artifacts.

func ExportBitArt

func ExportBitArt(filename string, content []string, target int) error

ExportBitArt handles export target selection and saves accordingly

func ExportToSyscWalls

func ExportToSyscWalls(filename, content string) error

ExportToSyscWalls exports ASCII art to sysc-walls with config update

func FindFontPath

func FindFontPath(fontName string) (string, error)

FindFontPath returns the full path to a font file by name

func GetRenderedDimensions

func GetRenderedDimensions(opts TUIRenderOptions) (width, height int)

GetRenderedDimensions calculates the final dimensions of rendered text

func LaunchAnimation

func LaunchAnimation(animName, theme, file, duration string) error

LaunchAnimation launches the actual animation in the CLI

func ListAvailableFonts

func ListAvailableFonts() []string

ListAvailableFonts returns a list of .bit font files from the assets/fonts directory

func RenderBitText

func RenderBitText(opts TUIRenderOptions) []string

RenderBitText renders text using a bitmap font with styling options This wraps BIT's proven rendering engine

func RenderTextWithFont

func RenderTextWithFont(text string, fontData FontData, options RenderOptions) []string

RenderTextWithFont renders text using the specified font with advanced rendering options

Types

type AnimationWrapper

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

AnimationWrapper wraps any animation type to provide a common interface

func (*AnimationWrapper) Render

func (a *AnimationWrapper) Render() string

func (*AnimationWrapper) Reset

func (a *AnimationWrapper) Reset()

func (*AnimationWrapper) Update

func (a *AnimationWrapper) Update()

type BitFont

type BitFont struct {
	Name       string              `json:"name"`
	Author     string              `json:"author"`
	License    string              `json:"license"`
	Characters map[string][]string `json:"characters"`
}

BitFont represents a bitmap font loaded from a .bit JSON file

func LoadBitFont

func LoadBitFont(path string) (*BitFont, error)

LoadBitFont loads a .bit font file from the given path

func (*BitFont) GetCharWidth

func (f *BitFont) GetCharWidth(char rune) int

GetCharWidth returns the width of a character in this font

func (*BitFont) GetHeight

func (f *BitFont) GetHeight() int

GetHeight returns the height of characters in this font

func (*BitFont) GetMaxWidth

func (f *BitFont) GetMaxWidth(text string) int

GetMaxWidth returns the maximum width needed for the given text

func (*BitFont) RenderText

func (f *BitFont) RenderText(text string) []string

RenderText converts a string to ASCII art using this font

type DescenderInfo

type DescenderInfo struct {
	HasDescender    bool
	BaselineHeight  int // Height of the main character body (excluding descender)
	DescenderHeight int // Height of the descender part
	TotalHeight     int // Total character height
	VerticalOffset  int // How much to offset this character vertically
}

DescenderInfo holds information about a character's descender properties

type FontData

type FontData struct {
	Name       string
	Author     string
	License    string
	Characters map[string][]string
}

FontData represents BIT's font structure

type GradientDirection

type GradientDirection int

GradientDirection from BIT

const (
	UpDown GradientDirection = iota
	DownUp
	LeftRight
	RightLeft
)

type HorizontalAlignment

type HorizontalAlignment int

HorizontalAlignment represents the horizontal alignment of a character or line.

const (
	// AlignLeft aligns the left of the character/line to the left of the canvas.
	AlignLeft HorizontalAlignment = iota
	// AlignCenter aligns the center of the character/line to the center of the canvas.
	AlignCenter
	// AlignRight aligns the right of the character/line to the right of the canvas.
	AlignRight
)

type Model

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

Model represents the TUI state

func NewModel

func NewModel() Model

NewModel creates a new TUI model with default values

func (Model) Init

func (m Model) Init() tea.Cmd

Init initializes the model

func (Model) Update

func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update handles messages and updates the model

func (Model) View

func (m Model) View() string

View renders the TUI

type RenderOptions

type RenderOptions struct {
	CharSpacing            int
	WordSpacing            int
	LineSpacing            int
	Alignment              TextAlignment
	TextColor              string
	GradientColor          string
	GradientDirection      GradientDirection
	UseGradient            bool
	ScaleFactor            float64
	ShadowEnabled          bool
	ShadowHorizontalOffset int
	ShadowVerticalOffset   int
	ShadowStyle            ShadowStyle
	TextLines              []string
}

RenderOptions is BIT's full rendering options structure

type ShadowStyle

type ShadowStyle int

ShadowStyle from BIT

const (
	LightShade ShadowStyle = iota
	MediumShade
	DarkShade
)

type ShadowStyleOption

type ShadowStyleOption struct {
	Name string
	Char rune
	Hex  string
}

ShadowStyleOption represents shadow style options

type Styles

type Styles struct {
	Canvas          lipgloss.Style
	Selector        lipgloss.Style
	SelectorFocused lipgloss.Style
	SelectorLabel   lipgloss.Style
	SelectorValue   lipgloss.Style
	GuidanceBox     lipgloss.Style
	Help            lipgloss.Style
	Background      lipgloss.Style
}

Styles holds lipgloss styles for the TUI

func NewStyles

func NewStyles() Styles

NewStyles creates the dark theme styles

type TUIRenderOptions

type TUIRenderOptions struct {
	Font          *BitFont
	Text          string
	Alignment     int
	Color         string
	Scale         float64
	Shadow        bool
	ShadowOffsetX int
	ShadowOffsetY int
	ShadowStyle   int
	CharSpacing   int
	WordSpacing   int
	LineSpacing   int
	UseGradient   bool
	GradientColor string
	GradientDir   int
	MaxWidth      int // Canvas width for alignment
}

TUIRenderOptions holds simplified configuration for rendering text in the TUI This is our wrapper around BIT's RenderOptions

type TextAlignment

type TextAlignment int

TextAlignment from BIT - using the same values as HorizontalAlignment

const (
	LeftAlign TextAlignment = iota
	CenterAlign
	RightAlign
)

type TickMsg

type TickMsg time.Time

TickMsg is sent when animation should update

type VerticalAlignment

type VerticalAlignment int

VerticalAlignment represents the vertical alignment of a character or line.

const (
	// AlignTop aligns the top of the character/line to the top of the canvas.
	AlignTop VerticalAlignment = iota
	// AlignMiddle aligns the middle of the character/line to the middle of the canvas.
	AlignMiddle
	// AlignBottom aligns the bottom of the character/line to the bottom of the canvas.
	AlignBottom
)

Jump to

Keyboard shortcuts

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