Documentation
¶
Overview ¶
Package tui
Package tui ¶
Package tui ¶
Package tui ¶
Package tui
Index ¶
- Variables
- func JoinHorizontal(pos Position, ss ...string) string
- func JoinVertical(pos Position, ss ...string) string
- func Width(s string) int
- type BatchMsg
- type Border
- type Clickable
- type Cmd
- type Component
- type KeyMsg
- type KeyType
- type Layout
- type Model
- type Msg
- type Position
- type ProgramOption
- type Style
- type TextWidget
- type Widget
- type WindowSizeMsg
Constants ¶
This section is empty.
Variables ¶
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 ¶
JoinHorizontal joins strings horizontally.
func JoinVertical ¶
JoinVertical joins strings vertically.
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.
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.
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.
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.
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.
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 ¶
WindowSizeMsg is sent when the terminal window is resized.