Documentation
¶
Index ¶
- Variables
- func CalculateColumnWidths(termWidth int, config ColumnWidthConfig) []int
- func CalculateTableHeight(terminalHeight, rowCount int) int
- func DefaultTableHeaderStyle() lipgloss.Style
- func DefaultTableSelectedStyle() lipgloss.Style
- func GetTerminalHeight() int
- func GetTerminalWidth() int
- func HighlightTableRow(cells []string, widths []int) []string
- func IsTerminal(w io.Writer) bool
- func MeasureStringWidth(s string) int
- func SortByName[T SortableByName](items []T)
- func SortStrings(items []string)
- func StyleTable(t table.Model) table.Model
- func StyleTableForDisplay(t table.Model) table.Model
- func StyleTableForList(t table.Model) table.Model
- func TruncateString(s string, maxLen int) string
- type ColumnWidthConfig
- type OutputFormat
- type SortableByName
Constants ¶
This section is empty.
Variables ¶
var ( // Table styles BaseTableStyle = lipgloss.NewStyle(). BorderStyle(lipgloss.NormalBorder()). BorderForeground(lipgloss.Color("240")) // Title styles TitleStyle = lipgloss.NewStyle(). Bold(true). Foreground(lipgloss.Color("99")) // Label/Value styles for detail views LabelStyle = lipgloss.NewStyle(). Bold(true). Foreground(lipgloss.Color("240")) ValueStyle = lipgloss.NewStyle(). Foreground(lipgloss.Color("252")) // Help text HelpStyle = lipgloss.NewStyle(). Foreground(lipgloss.Color("241")) // Success/Error styles SuccessStyle = lipgloss.NewStyle(). Foreground(lipgloss.Color("42")) ErrorStyle = lipgloss.NewStyle(). Foreground(lipgloss.Color("196")) // Selection styles SelectedItemStyle = lipgloss.NewStyle(). Foreground(lipgloss.Color("170")). Bold(true) NormalItemStyle = lipgloss.NewStyle(). Foreground(lipgloss.Color("252")) // Default indicator style (subtle) DefaultIndicatorStyle = lipgloss.NewStyle(). Foreground(lipgloss.Color("42")) // Green color for checkmark // Default row highlight style DefaultRowStyle = lipgloss.NewStyle(). Background(lipgloss.Color("228")) // Subtle yellow background )
Common styles used across the application
Functions ¶
func CalculateColumnWidths ¶
func CalculateColumnWidths(termWidth int, config ColumnWidthConfig) []int
CalculateColumnWidths calculates optimal column widths based on terminal width This is inspired by GitHub CLI's approach to responsive table layouts
func CalculateTableHeight ¶
CalculateTableHeight calculates appropriate table height based on terminal and row count
func DefaultTableHeaderStyle ¶
Table header style configuration
func DefaultTableSelectedStyle ¶
Table selected row style configuration
func GetTerminalHeight ¶
func GetTerminalHeight() int
GetTerminalHeight returns the current terminal height with a fallback
func GetTerminalWidth ¶
func GetTerminalWidth() int
GetTerminalWidth returns the current terminal width with a fallback
func HighlightTableRow ¶
HighlightTableRow applies the default row highlight style to all cells in a row
func IsTerminal ¶
IsTerminal returns true if the given writer is a terminal
func MeasureStringWidth ¶
MeasureStringWidth returns the display width of a string, accounting for ANSI codes
func SortByName ¶
func SortByName[T SortableByName](items []T)
SortByName sorts a slice of items alphabetically by name (case-insensitive)
func SortStrings ¶
func SortStrings(items []string)
SortStrings sorts a slice of strings alphabetically (case-insensitive)
func StyleTable ¶
StyleTable applies common styling to a table (for interactive select views)
func StyleTableForDisplay ¶
StyleTableForDisplay applies styling for non-interactive display tables
func StyleTableForList ¶
StyleTableForList applies styling for list views with subtle default highlighting
func TruncateString ¶
TruncateString truncates a string to fit within maxLen, adding "..." if needed
Types ¶
type ColumnWidthConfig ¶
type ColumnWidthConfig struct {
// MinWidths defines minimum width for each column
MinWidths []int
// MaxWidths defines maximum width for each column (0 = no limit)
MaxWidths []int
// PreferredWidths defines preferred width for each column
PreferredWidths []int
// FlexColumns marks which columns should expand to fill available space
FlexColumns []bool
}
ColumnWidthConfig defines how to calculate column widths
type OutputFormat ¶
type OutputFormat string
OutputFormat represents the desired output format
const ( // OutputFormatTable renders as a human-readable table OutputFormatTable OutputFormat = "table" // OutputFormatJSON renders as JSON OutputFormatJSON OutputFormat = "json" // OutputFormatTSV renders as tab-separated values OutputFormatTSV OutputFormat = "tsv" )
func ParseOutputFormat ¶
func ParseOutputFormat(s string) (OutputFormat, error)
ParseOutputFormat parses a string into an OutputFormat
type SortableByName ¶
type SortableByName interface {
GetName() string
}
SortableByName is an interface for items that can be sorted by name