ui

package
v3.11.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2025 License: MIT Imports: 7 Imported by: 0

README

UI Components Package

This package provides standardized UI components and styling for Buildkite CLI output, ensuring consistent visual presentation across the application.

Features

  • Consistent Colors: Standard color palette for different states (success, error, warning, etc.)
  • Reusable Icons: Standard icons for different states and actions
  • Standardized Components: Pre-styled components for common UI elements
  • Layout Helpers: Utilities for creating consistent layouts
  • Text Formatting: Utilities for text manipulation and formatting
  • Buildkite Entity Rendering: Components for rendering Buildkite entities like builds, jobs, artifacts, etc.

Usage

Basic Styling
import "github.com/buildkite/cli/v3/internal/ui"

// Use predefined styles
title := ui.Bold.Render("This is bold text")
subtitle := ui.Italic.Render("This is italic text")

// Use predefined colors
successText := ui.StatusStyle("success").Render("Operation successful")
errorText := ui.StatusStyle("error").Render("Operation failed")
Layout Components
import "github.com/buildkite/cli/v3/internal/ui"

// Create a section with title and content
section := ui.Section("Section Title", "Section content goes here")

// Create a row with columns
row := ui.Row("Column 1", "Column 2", "Column 3")

// Create a labeled value
label := ui.LabeledValue("Label", "Value")

// Create a table
headers := []string{"Name", "Value"}
rows := [][]string{
    {"Row 1", "Value 1"},
    {"Row 2", "Value 2"},
}
table := ui.Table(headers, rows)

// Create a card
card := ui.Card("Card Title", "Card content", ui.WithBorder(true))
Buildkite Entity Rendering
import "github.com/buildkite/cli/v3/internal/ui"

// Render build summary
buildSummary := ui.RenderBuildSummary(build)

// Render job summary
jobSummary := ui.RenderJobSummary(job)

// Render artifact
artifactSummary := ui.RenderArtifact(artifact)

// Render annotation
annotationSummary := ui.RenderAnnotation(annotation)

// Render agent summary
agentSummary := ui.RenderAgentSummary(agent)

// Render cluster summary
clusterSummary := ui.RenderClusterSummary(cluster)
Text Formatting
import "github.com/buildkite/cli/v3/internal/ui"

// Truncate text
truncated := ui.TruncateText("Long text to truncate", 10)

// Strip HTML tags
plain := ui.StripHTMLTags("<p>HTML <b>content</b></p>")

// Format bytes
human := ui.FormatBytes(1500000) // "1.5MB"

// Format date
date := ui.FormatDate(time.Now())

Design Principles

  1. Consistency: All UI components follow the same design patterns and color schemes
  2. Modularity: Components are designed to be reusable and composable
  3. Separation of Concerns: UI rendering is separated from business logic
  4. Testability: Components are designed to be easily testable

By using this package for all UI rendering, we ensure a consistent look and feel across the application while reducing code duplication.

Documentation

Index

Constants

View Source
const (
	// Base colors
	ColorBlack  = lipgloss.Color("0")
	ColorRed    = lipgloss.Color("1")
	ColorGreen  = lipgloss.Color("2")
	ColorYellow = lipgloss.Color("3")
	ColorBlue   = lipgloss.Color("4")
	ColorPurple = lipgloss.Color("5")
	ColorCyan   = lipgloss.Color("6")
	ColorWhite  = lipgloss.Color("7")
	ColorGrey   = lipgloss.Color("8")

	// Semantic colors
	ColorSuccess     = lipgloss.Color("#2ECC40") // Green
	ColorError       = lipgloss.Color("#F45756") // Red
	ColorWarning     = lipgloss.Color("#FF841C") // Orange
	ColorInfo        = lipgloss.Color("#337AB7") // Blue
	ColorDefault     = lipgloss.Color("#DDD")    // Light Grey
	ColorRunning     = lipgloss.Color("#FF6E00") // Orange
	ColorPending     = lipgloss.Color("#5A5A5A") // Grey
	ColorPassedGreen = lipgloss.Color("#9dcc3a") // Bright Green
)

Color constants for consistent styling across the application

View Source
const (
	IconSuccess   = "✓"
	IconError     = "✖"
	IconWarning   = "⚠"
	IconInfo      = "ℹ"
	IconRunning   = "▶"
	IconPending   = "⏰"
	IconWaiting   = "⌛"
	IconCanceled  = "🚫"
	IconBlocked   = "🔒"
	IconUnblocked = "🔓"
	IconNote      = "🗒️"
	IconDefault   = "❔"
	IconEllipsis  = "…"
)

Icon constants for consistent status representation

View Source
const MaxPreviewLength = 120

MaxPreviewLength is the maximum length for content previews

Variables

View Source
var (
	// Text styles
	Bold   = lipgloss.NewStyle().Bold(true)
	Italic = lipgloss.NewStyle().Italic(true)
	Faint  = lipgloss.NewStyle().Faint(true)

	// Layout styles
	Padding = lipgloss.NewStyle().Padding(0, 1)
	Header  = lipgloss.NewStyle().Bold(true).Padding(0, 1).Underline(true)
	Title   = lipgloss.NewStyle().Bold(true).Padding(0, 0)

	// Border styles
	BorderRounded = lipgloss.NewStyle().Border(lipgloss.RoundedBorder())
)

Standard style variants

Functions

func Card

func Card(title, content string, opts ...CardOption) string

Card creates a bordered card with title and content

func Divider

func Divider() string

Divider creates a horizontal divider

func FormatBytes

func FormatBytes(bytes int64) string

FormatBytes formats bytes into human-readable format (KB, MB, GB, etc.)

func FormatDate

func FormatDate(t time.Time) string

FormatDate formats a time in RFC3339 format

func FormatDuration

func FormatDuration(d time.Duration) string

FormatDuration formats a duration in a human-readable way

func LabeledValue

func LabeledValue(label string, value string) string

LabeledValue creates a "Label: Value" formatted string

func RenderAgentSummary

func RenderAgentSummary(agent buildkite.Agent) string

RenderAgentSummary renders a summary of an agent

func RenderAnnotation

func RenderAnnotation(annotation *buildkite.Annotation) string

RenderAnnotation renders a build annotation

func RenderArtifact

func RenderArtifact(artifact *buildkite.Artifact) string

RenderArtifact renders a build artifact

func RenderBuildNumber

func RenderBuildNumber(state string, number int) string

RenderBuildNumber formats a build number with appropriate styling

func RenderBuildSummary

func RenderBuildSummary(b *buildkite.Build) string

RenderBuildSummary renders a summary of a build

func RenderClusterSummary

func RenderClusterSummary(cluster buildkite.Cluster) string

RenderClusterSummary renders a summary of a cluster

func RenderJobSummary

func RenderJobSummary(job buildkite.Job) string

RenderJobSummary renders a summary of a job

func RenderStatus

func RenderStatus(state string, opts ...StatusOption) string

RenderStatus renders a status with the appropriate icon and styling

func Row

func Row(columns ...string) string

Row creates a horizontal row of columns with consistent padding

func Section

func Section(title string, content string) string

Section creates a titled section with content underneath

func SpacedVertical

func SpacedVertical(strings ...string) string

SpacedVertical joins strings vertically with a blank line between them

func StatusIcon

func StatusIcon(state string, opts ...StatusOption) string

StatusIcon returns the appropriate icon for a status state

func StatusStyle

func StatusStyle(state string) lipgloss.Style

StatusStyle returns the appropriate styling for a status state

func StripHTMLTags

func StripHTMLTags(html string) string

StripHTMLTags removes HTML tags from a string

func Table

func Table(headers []string, rows [][]string) string

Table creates a table with the given headers and rows

func TrimMessage

func TrimMessage(msg string) string

TrimMessage trims a multi-line message to the first line

func TruncateAndStripTags

func TruncateAndStripTags(html string, maxLength int) string

TruncateAndStripTags strips HTML tags and truncates text

func TruncateText

func TruncateText(text string, maxLength int) string

TruncateText truncates text to the specified length and adds an ellipsis

Types

type CardOption

type CardOption func(*CardOptions)

CardOption is a function that modifies CardOptions

func WithBorder

func WithBorder(bordered bool) CardOption

WithBorder adds a border to the card

func WithBorderColor

func WithBorderColor(color lipgloss.Color) CardOption

WithBorderColor sets the border color

type CardOptions

type CardOptions struct {
	// contains filtered or unexported fields
}

CardOptions contains options for card rendering

type StatusOption

type StatusOption func(*StatusOptions)

StatusOption is a function that modifies StatusOptions

func WithBlocked

func WithBlocked(blocked bool) StatusOption

WithBlocked indicates the status is blocked

type StatusOptions

type StatusOptions struct {
	// contains filtered or unexported fields
}

StatusOptions contains options for status rendering

Jump to

Keyboard shortcuts

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