renderer

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	RoundedBorder = BorderChars{
		TopLeft:     '╭',
		TopRight:    '╮',
		BottomLeft:  '╰',
		BottomRight: '╯',
		Horizontal:  '─',
		Vertical:    '│',
	}

	DoubleBorder = BorderChars{
		TopLeft:     '╔',
		TopRight:    '╗',
		BottomLeft:  '╚',
		BottomRight: '╝',
		Horizontal:  '═',
		Vertical:    '║',
	}

	ThickBorder = BorderChars{
		TopLeft:     '┏',
		TopRight:    '┓',
		BottomLeft:  '┗',
		BottomRight: '┛',
		Horizontal:  '━',
		Vertical:    '┃',
	}

	NormalBorder = BorderChars{
		TopLeft:     '┌',
		TopRight:    '┐',
		BottomLeft:  '└',
		BottomRight: '┘',
		Horizontal:  '─',
		Vertical:    '│',
	}
)

Predefined border styles

Functions

This section is empty.

Types

type ANSIRenderer

type ANSIRenderer struct {
	ColorMode ColorMode
}

ANSIRenderer converts styles to ANSI escape codes

func NewANSIRenderer

func NewANSIRenderer() *ANSIRenderer

NewANSIRenderer creates a new ANSI renderer with detected capabilities

func NewANSIRendererWithMode

func NewANSIRendererWithMode(mode ColorMode) *ANSIRenderer

NewANSIRendererWithMode creates a new ANSI renderer with specified color mode

func (*ANSIRenderer) ClearScreen

func (r *ANSIRenderer) ClearScreen() string

ClearScreen clears the entire screen

func (*ANSIRenderer) EnterAltScreen

func (r *ANSIRenderer) EnterAltScreen() string

EnterAltScreen enters the alternate screen buffer

func (*ANSIRenderer) ExitAltScreen

func (r *ANSIRenderer) ExitAltScreen() string

ExitAltScreen exits the alternate screen buffer

func (*ANSIRenderer) HideCursor

func (r *ANSIRenderer) HideCursor() string

HideCursor hides the cursor

func (*ANSIRenderer) MoveCursor

func (r *ANSIRenderer) MoveCursor(x, y int) string

MoveCursor moves the cursor to the specified position (1-indexed)

func (*ANSIRenderer) RenderStyle

func (r *ANSIRenderer) RenderStyle(s *Style) string

RenderStyle converts a style to ANSI escape codes

func (*ANSIRenderer) Reset

func (r *ANSIRenderer) Reset() string

Reset returns the ANSI reset sequence

func (*ANSIRenderer) ShowCursor

func (r *ANSIRenderer) ShowCursor() string

ShowCursor shows the cursor

type BorderChars

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

BorderChars defines the characters used for borders

type BorderStyle

type BorderStyle struct {
	Top    bool
	Right  bool
	Bottom bool
	Left   bool

	// Border characters
	Chars BorderChars
}

BorderStyle defines which borders to render

type Cell

type Cell struct {
	// Content can be a single rune or a complete grapheme cluster (emoji sequence, etc.)
	Content string
	Style   *Style
}

Cell represents a single character cell in the terminal

type ColorMode

type ColorMode int

ColorMode represents the terminal's color capabilities

const (
	ColorModeNone      ColorMode = iota // No color support
	ColorMode16                         // 16 ANSI colors
	ColorMode256                        // 256 colors
	ColorModeTrueColor                  // 24-bit RGB (16.7M colors)
)

func (ColorMode) String

func (cm ColorMode) String() string

String returns a human-readable description of the color mode

type Screen

type Screen struct {
	Width    int
	Height   int
	Cells    [][]Cell
	Previous [][]Cell
	// contains filtered or unexported fields
}

Screen represents the terminal screen buffer

func NewScreen

func NewScreen(width, height int) *Screen

NewScreen creates a new screen buffer

func (*Screen) Clear

func (s *Screen) Clear()

Clear resets all cells to empty

func (*Screen) Render

func (s *Screen) Render(node *StyledNode)

Render renders a styled node to the screen buffer

func (*Screen) Resize

func (s *Screen) Resize(width, height int)

Resize changes the screen dimensions

func (*Screen) SetCell

func (s *Screen) SetCell(x, y int, content string, style *Style)

SetCell sets a single cell with content (can be a rune or grapheme cluster)

func (*Screen) SetColorMode

func (s *Screen) SetColorMode(mode ColorMode)

SetColorMode sets the color mode for rendering

func (*Screen) String

func (s *Screen) String() string

String converts the screen buffer to a string with ANSI codes

type Style

type Style struct {
	// Colors
	Foreground *color.Color
	Background *color.Color

	// Text attributes
	Bold          bool
	Italic        bool
	Underline     bool
	Strikethrough bool
	Dim           bool
	Blink         bool
	Reverse       bool

	// Text layout
	TextWrap     TextWrap     // How text should wrap
	TextAlign    TextAlign    // Horizontal alignment
	TextOverflow TextOverflow // Overflow handling

	// Borders
	Border      *BorderStyle
	BorderColor *color.Color
}

Style defines visual attributes without sizing properties. Sizing and layout are handled by the layout engine.

func NewStyle

func NewStyle() *Style

NewStyle creates a new empty style

func (*Style) WithBackground

func (s *Style) WithBackground(c *color.Color) *Style

WithBackground sets the background color

func (*Style) WithBold

func (s *Style) WithBold(bold bool) *Style

WithBold sets bold text

func (*Style) WithBorder

func (s *Style) WithBorder(chars BorderChars) *Style

WithBorder sets a border with all sides enabled

func (*Style) WithBorderColor

func (s *Style) WithBorderColor(c *color.Color) *Style

WithBorderColor sets the border color

func (*Style) WithForeground

func (s *Style) WithForeground(c *color.Color) *Style

WithForeground sets the foreground color

func (*Style) WithItalic

func (s *Style) WithItalic(italic bool) *Style

WithItalic sets italic text

func (*Style) WithTextOverflow

func (s *Style) WithTextOverflow(overflow TextOverflow) *Style

WithTextOverflow sets the text overflow behavior

func (*Style) WithUnderline

func (s *Style) WithUnderline(underline bool) *Style

WithUnderline sets underlined text

type StyledNode

type StyledNode struct {
	*layout.Node
	Style    *Style
	Content  string
	Children []*StyledNode
}

StyledNode wraps a layout.Node with visual styling

func NewStyledNode

func NewStyledNode(node *layout.Node, style *Style) *StyledNode

NewStyledNode creates a new styled node

func (*StyledNode) AddChild

func (n *StyledNode) AddChild(child *StyledNode)

AddChild adds a child node

type TerminalCapabilities

type TerminalCapabilities struct {
	ColorMode   ColorMode
	IsTTY       bool
	SupportsAlt bool // Alternate screen buffer
}

TerminalCapabilities holds information about terminal capabilities

func DetectCapabilities

func DetectCapabilities() *TerminalCapabilities

DetectCapabilities detects the terminal's capabilities

type TerminalDimensions

type TerminalDimensions struct {
	Columns int // Character columns (e.g., 80)
	Rows    int // Character rows (e.g., 24)

	PixelWidth  int // Total width in pixels (0 if unsupported)
	PixelHeight int // Total height in pixels (0 if unsupported)

	CellWidth  float64 // Width of one character in pixels
	CellHeight float64 // Height of one character in pixels

	HasPixelSupport bool // Whether terminal supports pixel queries
}

TerminalDimensions represents the complete dimensions of the terminal

func QueryTerminalDimensions

func QueryTerminalDimensions(columns, rows int) TerminalDimensions

QueryTerminalDimensions gets comprehensive terminal dimensions including pixel sizes

func (TerminalDimensions) String

func (d TerminalDimensions) String() string

String returns a human-readable representation of dimensions

type TextAlign

type TextAlign int

TextAlign defines horizontal text alignment

const (
	TextAlignLeft    TextAlign = iota // Left-aligned (default)
	TextAlignCenter                   // Center-aligned
	TextAlignRight                    // Right-aligned
	TextAlignJustify                  // Justified (with Knuth-Plass)
)

type TextOverflow

type TextOverflow int

TextOverflow defines how text should be handled when it overflows

const (
	TextOverflowClip           TextOverflow = iota // Clip text at boundary
	TextOverflowEllipsis                           // Show ellipsis (…) at end for overflow
	TextOverflowEllipsisStart                      // Show ellipsis (…) at start for overflow
	TextOverflowEllipsisMiddle                     // Show ellipsis (…) in middle for overflow
)

type TextWrap

type TextWrap int

TextWrap defines how text should wrap

const (
	TextWrapNone     TextWrap = iota // No wrapping, preserve manual line breaks only
	TextWrapNormal                   // Standard greedy wrapping
	TextWrapBalanced                 // Balanced line lengths (prettier)
	TextWrapPretty                   // High-quality Knuth-Plass wrapping
)

Jump to

Keyboard shortcuts

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