tui

package
v0.0.0-...-542f489 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package tui

Package tui

Package tui

Package tui

Package tui

Index

Constants

This section is empty.

Variables

View Source
var (
	NormalBorder  = fromLipglossBorder(lg.NormalBorder())
	RoundedBorder = fromLipglossBorder(lg.RoundedBorder())
	DoubleBorder  = fromLipglossBorder(lg.DoubleBorder())
	ThickBorder   = fromLipglossBorder(lg.ThickBorder())
	HiddenBorder  = fromLipglossBorder(lg.HiddenBorder())
)

Pre-defined borders, converted manually.

Functions

func JoinHorizontal

func JoinHorizontal(pos Position, ss ...string) string

JoinHorizontal joins strings horizontally.

func JoinVertical

func JoinVertical(pos Position, ss ...string) string

JoinVertical joins strings vertically.

func Width

func Width(s string) int

Width returns the rendered width of a string.

Types

type BatchMsg

type BatchMsg []Cmd

BatchMsg is an internal message used to batch commands. We use a custom type to avoid exposing tea.BatchMsg directly.

type Border

type Border struct {
	Top         string
	Bottom      string
	Left        string
	Right       string
	TopLeft     string
	TopRight    string
	BottomLeft  string
	BottomRight string
}

Border corresponds to lipgloss.Border

type Clickable

type Clickable interface {
	Component
	// SetOnClick sets a function to be called when the component is clicked.
	// The function should return a Cmd to be processed by the TUI runtime.
	SetOnClick(onClick func() Cmd)
}

Clickable is an interface for components that respond to click events. It embeds the base Component interface.

type Cmd

type Cmd func() Msg

Cmd is a command that can be executed by the TUI runtime. It's a function that returns a message.

func Batch

func Batch(cmds ...Cmd) Cmd

Batch is a command that executes a list of commands.

type Component

type Component interface {
	Widget
	// Styling methods
	BackgroundColor(color string) Component
	Border(border Border, sides ...bool) Component
	BorderForeground(color string) Component
	Padding(p ...int) Component
	Width(width int) Component
	Height(height int) Component
	Align(pos Position) Component
}

Component is an interface for widgets that primarily display content. It embeds the base Widget interface and provides methods for component-specific styling.

type KeyMsg

type KeyMsg struct {
	Type KeyType

	// Runes holds the runes of the key press, if any.
	Runes []rune

	// Alt is true if the alt key was pressed.
	Alt bool
}

KeyMsg is sent when a key is pressed.

type KeyType

type KeyType int

KeyType defines the type of a key press.

const (
	KeyRunes KeyType = iota
	KeySpace
	KeyBackspace
	KeyDelete
	KeyEnter
	KeyEsc
	KeyTab
	KeyUp
	KeyDown
	KeyRight
	KeyLeft
	KeyCtrlC
	KeyCtrlD
)

This is a subset of bubbletea's KeyType for abstraction purposes.

func (KeyType) String

func (k KeyType) String() string

String returns a string representation of the key type.

type Layout

type Layout interface {
	Widget
	// Styling methods
	BackgroundColor(color string) Layout
	Border(border Border, sides ...bool) Layout
	BorderForeground(color string) Layout
	Padding(p ...int) Layout
	Width(width int) Layout
	Height(height int) Layout
	Align(pos Position) Layout
}

Layout is an interface for widgets that primarily arrange other widgets. It embeds the base Widget interface and provides methods for layout-specific styling.

type Model

type Model interface {
	// Init is the first function that will be called. It returns an optional
	// command to be executed.
	Init() Cmd

	// Update is called when a message is received. It returns the updated
	// model and an optional command.
	Update(msg Msg) (Model, Cmd)

	// View renders the model's state as a string.
	View() string
}

Model is the interface that all components in the TUI must implement.

func Run

func Run(model Model, opts ...ProgramOption) (Model, error)

Run starts and runs the TUI program for the given model.

type Msg

type Msg any

Msg represents a message that can be sent to a model's Update function. It's an alias for any, allowing for any type of message.

func Quit

func Quit() Msg

Quit is a command that signals the program to exit.

type Position

type Position float64

Position corresponds to lipgloss.Position.

const (
	Left   Position = 0.0
	Center Position = 0.5
	Right  Position = 1.0
	Top    Position = 0.0
	Bottom Position = 1.0
)

type ProgramOption

type ProgramOption func() tea.ProgramOption

ProgramOption is a functional option for configuring the TUI program. It's a wrapper around bubbletea's ProgramOption.

func WithAltScreen

func WithAltScreen() ProgramOption

WithAltScreen is an option to run the program in the alternate screen buffer.

func WithMouseCellMotion

func WithMouseCellMotion() ProgramOption

WithMouseCellMotion is an option to enable mouse motion tracking.

type Style

type Style interface {
	// Manipulation
	Width(int) Style
	Height(int) Style
	Padding(...int) Style
	Margin(...int) Style
	Align(Position) Style

	// Colors
	Foreground(string) Style
	Background(string) Style

	// Text Properties
	Bold(bool) Style
	Italic(bool) Style
	Underline(bool) Style

	// Border
	Border(Border, ...bool) Style
	BorderForeground(string) Style

	// Rendering & Introspection
	Render(string) string
	GetFrameSize() (horizontal int, vertical int)

	// Get the underlying lipgloss style, for advanced use cases or compatibility.
	GetLipglossStyle() lg.Style
}

Style is an interface that abstracts the lipgloss.Style. It allows for setting styling rules and rendering strings.

func NewStyle

func NewStyle() Style

NewStyle creates a new style adapter.

type TextWidget

type TextWidget interface {
	Component
	SetText(text string)
	// TextStyle returns the style applied to the text content.
	// This allows for more specific text styling beyond the component's overall style.
	TextStyle() Style
}

TextWidget is an interface for components that primarily display text. It embeds the base Component interface.

type Widget

type Widget interface {
	Model
}

Widget is the base interface for all UI elements. It embeds tui.Model, providing Init, Update, and View methods.

type WindowSizeMsg

type WindowSizeMsg struct {
	Width  int
	Height int
}

WindowSizeMsg is sent when the terminal window is resized.

Jump to

Keyboard shortcuts

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