core

package
v0.0.0-...-2914c72 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package core provides the fundamental interfaces and types for cmdux.

Package core provides rendering utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetTerminalSize

func GetTerminalSize() (width, height int)

GetTerminalSize attempts to get the terminal size. Returns default values if unable to detect.

func MeasureText

func MeasureText(text string) int

MeasureText measures the display width of text, handling ANSI codes and unicode.

func StripANSI

func StripANSI(str string) string

StripANSI removes ANSI escape codes from a string for width calculation.

Types

type Alignment

type Alignment int

Alignment represents text alignment options.

const (
	// AlignLeft aligns text to the left.
	AlignLeft Alignment = iota
	// AlignCenter centers text.
	AlignCenter
	// AlignRight aligns text to the right.
	AlignRight
)

type BoxChars

type BoxChars struct {
	TopLeft     rune
	TopRight    rune
	BottomLeft  rune
	BottomRight rune
	Horizontal  rune
	Vertical    rune
}

BoxChars defines the characters used for drawing boxes.

func ClassicBoxChars

func ClassicBoxChars() BoxChars

ClassicBoxChars returns classic ASCII box drawing characters.

func DefaultBoxChars

func DefaultBoxChars() BoxChars

DefaultBoxChars returns the default box drawing characters.

type Component

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

Component represents a basic UI component with common properties.

func NewComponent

func NewComponent() *Component

NewComponent creates a new base component.

func (*Component) GetHeight

func (c *Component) GetHeight() int

GetHeight returns the component height.

func (*Component) GetStyle

func (c *Component) GetStyle() *style.Style

GetStyle returns the component style.

func (*Component) GetWidth

func (c *Component) GetWidth() int

GetWidth returns the component width.

func (*Component) Height

func (c *Component) Height(h int) *Component

Height sets the component height.

func (*Component) Hide

func (c *Component) Hide() *Component

Hide hides the component.

func (*Component) IsHidden

func (c *Component) IsHidden() bool

IsHidden returns whether the component is hidden.

func (*Component) SetStyle

func (c *Component) SetStyle(s *style.Style) *Component

SetStyle sets the component style.

func (*Component) Show

func (c *Component) Show() *Component

Show shows the component.

func (*Component) Width

func (c *Component) Width(w int) *Component

Width sets the component width.

type Renderable

type Renderable interface {
	// Render returns the string representation of the component using the given theme.
	Render(theme *style.Theme) string
}

Renderable represents any component that can be rendered to the terminal.

type Renderer

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

Renderer provides utilities for rendering text with proper alignment and sizing.

func NewRenderer

func NewRenderer(width, height int) *Renderer

NewRenderer creates a new renderer with the specified dimensions.

func (*Renderer) Box

func (r *Renderer) Box(content string, width, height int, chars BoxChars) string

Box draws a box around text with the specified characters.

func (*Renderer) CenterText

func (r *Renderer) CenterText(text string, width int) string

CenterText centers text within the specified width.

func (*Renderer) FormatTable

func (r *Renderer) FormatTable(headers []string, rows [][]string, columnWidths []int) string

FormatTable formats a table with proper column alignment and spacing.

func (*Renderer) JoinHorizontal

func (r *Renderer) JoinHorizontal(strs []string, separator string) string

JoinHorizontal joins multiple strings horizontally.

func (*Renderer) JoinVertical

func (r *Renderer) JoinVertical(strs []string, width int, align Alignment) string

JoinVertical joins multiple strings vertically with proper alignment.

func (*Renderer) PadText

func (r *Renderer) PadText(text string, width int, align Alignment) string

PadText pads text to the specified width with proper unicode handling.

func (*Renderer) RepeatChar

func (r *Renderer) RepeatChar(char rune, width int) string

RepeatChar repeats a character to create a string of specified width.

func (*Renderer) TruncateText

func (r *Renderer) TruncateText(text string, width int) string

TruncateText truncates text to fit within the specified width.

func (*Renderer) WrapText

func (r *Renderer) WrapText(text string, width int) []string

WrapText wraps text to fit within the specified width.

Jump to

Keyboard shortcuts

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