tui

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package tui provides shared TUI components for Lango CLI commands.

Index

Constants

View Source
const (
	CheckPass = "✓"
	CheckWarn = "⚠"
	CheckFail = "✗"
	Spinner   = "◌"
)

Check result indicators

Variables

View Source
var (
	Primary    = lipgloss.Color("#7C3AED") // Purple
	Success    = lipgloss.Color("#10B981") // Green
	Warning    = lipgloss.Color("#F59E0B") // Amber
	Error      = lipgloss.Color("#EF4444") // Red
	Muted      = lipgloss.Color("#6B7280") // Gray
	Foreground = lipgloss.Color("#F9FAFB") // White
	Background = lipgloss.Color("#1F2937") // Dark gray
	Highlight  = lipgloss.Color("#3B82F6") // Blue
	Accent     = lipgloss.Color("#04B575") // Green (selection/focus)
	Dim        = lipgloss.Color("#626262") // Dim gray (descriptions)
	Separator  = lipgloss.Color("#374151") // Dark gray (dividers)
)

Color palette for consistent theming

View Source
var (
	// TitleStyle for main headers
	TitleStyle = lipgloss.NewStyle().
				Bold(true).
				Foreground(Primary).
				MarginBottom(1)

	// SubtitleStyle for secondary headers
	SubtitleStyle = lipgloss.NewStyle().
					Foreground(Muted).
					MarginBottom(1)

	// SuccessStyle for success messages
	SuccessStyle = lipgloss.NewStyle().
					Foreground(Success)

	// WarningStyle for warning messages
	WarningStyle = lipgloss.NewStyle().
					Foreground(Warning)

	// ErrorStyle for error messages
	ErrorStyle = lipgloss.NewStyle().
				Foreground(Error)

	// MutedStyle for less important text
	MutedStyle = lipgloss.NewStyle().
				Foreground(Muted)

	// HighlightStyle for emphasized text
	HighlightStyle = lipgloss.NewStyle().
					Foreground(Highlight).
					Bold(true)

	// BoxStyle for bordered containers
	BoxStyle = lipgloss.NewStyle().
				Border(lipgloss.RoundedBorder()).
				BorderForeground(Muted).
				Padding(1, 2)

	// ListItemStyle for list items
	ListItemStyle = lipgloss.NewStyle().
					PaddingLeft(2)

	// SelectedItemStyle for selected list items
	SelectedItemStyle = lipgloss.NewStyle().
						PaddingLeft(2).
						Foreground(Primary).
						Bold(true)

	// SectionHeaderStyle for menu section titles
	SectionHeaderStyle = lipgloss.NewStyle().
						Foreground(Highlight).
						Bold(true).
						PaddingLeft(2)

	// SeparatorLineStyle for section dividers
	SeparatorLineStyle = lipgloss.NewStyle().
						Foreground(Separator)

	// CursorStyle for the selection arrow
	CursorStyle = lipgloss.NewStyle().
				Foreground(Accent)

	// ActiveItemStyle for highlighted/selected items
	ActiveItemStyle = lipgloss.NewStyle().
					Foreground(Accent).
					Bold(true)

	// SearchBarStyle for the search input container
	SearchBarStyle = lipgloss.NewStyle().
					Border(lipgloss.RoundedBorder()).
					BorderForeground(Primary).
					Padding(0, 1)

	// FormTitleBarStyle for form titles
	FormTitleBarStyle = lipgloss.NewStyle().
						Bold(true).
						Foreground(Primary).
						Border(lipgloss.NormalBorder(), false, false, true, false).
						BorderForeground(Primary).
						MarginBottom(1)

	// FieldDescStyle for field description/help text
	FieldDescStyle = lipgloss.NewStyle().
					Foreground(Dim).
					Italic(true).
					PaddingLeft(2)

	// BadgeAdvancedStyle for the ADV badge on advanced categories
	BadgeAdvancedStyle = lipgloss.NewStyle().
						Foreground(Foreground).
						Background(Muted).
						Bold(true).
						Padding(0, 1)

	// BadgeDependencyStyle for the dependency warning badge on categories
	BadgeDependencyStyle = lipgloss.NewStyle().
							Foreground(Foreground).
							Background(Warning).
							Bold(true).
							Padding(0, 1)

	// BadgeExperimentalStyle for the EXP badge on experimental categories
	BadgeExperimentalStyle = lipgloss.NewStyle().
							Foreground(Warning).
							Bold(true).
							Padding(0, 1)
)

Base styles for TUI components

View Source
var (
	Danger    = Error     // destructive/high-risk operations
	Info      = Highlight // informational highlights
	Selection = Accent    // user selection/focus indicator
)

Semantic color aliases for state-driven rendering.

View Source
var (
	// BadgeBaseStyle renders a compact pill-shaped label with padding and no border.
	BadgeBaseStyle = lipgloss.NewStyle().
					Padding(0, 1).
					Bold(true)

	// DividerStyle renders a subtle horizontal separator using dim foreground.
	DividerStyle = lipgloss.NewStyle().
					Foreground(Separator)

	// PillStyle renders a rounded-corner pill for status labels.
	PillStyle = lipgloss.NewStyle().
				Padding(0, 1)

	// SpacedBlockStyle provides consistent vertical spacing without borders.
	SpacedBlockStyle = lipgloss.NewStyle().
						PaddingLeft(2).
						MarginBottom(1)
)

Spacing-based styles (prefer over borders for visual hierarchy).

Functions

func BadgeStyle added in v0.7.0

func BadgeStyle(color lipgloss.Color) lipgloss.Style

BadgeStyle returns a pill-shaped badge in the given color.

func Banner() string

Banner returns the squirrel mascot with brand info side-by-side.

func BannerBox

func BannerBox() string

BannerBox wraps the Banner in a rounded border box (for settings welcome).

func Breadcrumb(segments ...string) string

Breadcrumb renders a navigation path like "Settings > Agent Configuration".

func Divider added in v0.7.0

func Divider(width int) string

Divider returns a horizontal line of the given width.

func FormatDuration added in v0.7.0

func FormatDuration(d time.Duration) string

FormatDuration renders a duration as a human-friendly string (e.g., "2h 15m", "3m 42s", "150ms").

func FormatFail

func FormatFail(msg string) string

FormatFail formats a failing check message

func FormatMuted

func FormatMuted(msg string) string

FormatMuted formats muted/hint text

func FormatNumber added in v0.7.0

func FormatNumber(n int64) string

FormatNumber renders an integer with comma-separated thousands (e.g., 12345 -> "12,345").

func FormatPass

func FormatPass(msg string) string

FormatPass formats a passing check message

func FormatTokens added in v0.7.0

func FormatTokens(n int) string

FormatTokens returns a human-readable token count with comma separators.

func FormatWarn

func FormatWarn(msg string) string

FormatWarn formats a warning message

func GetVersion added in v0.6.0

func GetVersion() string

GetVersion returns the current version string.

func HelpBar

func HelpBar(entries ...string) string

HelpBar renders a full help footer from HelpEntry results.

func HelpEntry

func HelpEntry(key, label string) string

HelpEntry renders a single help entry: key badge + label.

func KeyBadge

func KeyBadge(key string) string

KeyBadge renders a keyboard shortcut as a styled badge.

func RelativeTime added in v0.7.0

func RelativeTime(now, t time.Time) string

RelativeTime formats a timestamp as a human-readable relative duration. It returns precise values for sub-minute durations (e.g., "5s ago").

func RelativeTimeHuman added in v0.7.0

func RelativeTimeHuman(now, t time.Time) string

RelativeTimeHuman formats a timestamp as a friendly relative duration. For sub-minute durations it returns "just now" instead of precise seconds.

func ServeBanner

func ServeBanner() string

ServeBanner returns a banner for the serve command with a separator line.

func SetProfile

func SetProfile(name string)

SetProfile injects the active profile name.

func SetVersionInfo

func SetVersionInfo(version, buildTime string)

SetVersionInfo injects version and build time from main.go.

func StartupSummary added in v0.6.0

func StartupSummary(features []FeatureLine) string

StartupSummary renders activated features based on config flags. Each entry is a key string mapped to an enabled bool and optional detail.

func Truncate added in v0.7.0

func Truncate(s string, maxLen int) string

Truncate shortens s to maxLen, appending "..." if needed.

func WordWrap added in v0.7.0

func WordWrap(text string, width int) string

WordWrap wraps text to the given width, breaking on spaces.

Types

type FeatureLine added in v0.6.0

type FeatureLine struct {
	Name    string
	Enabled bool
	Detail  string
}

FeatureLine describes a single feature for startup summary.

Jump to

Keyboard shortcuts

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