common

package
v3.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package common provides shared UI components and styles.

Package common provides shared UI components and styles.

Index

Constants

View Source
const (
	SymbolSuccess = "✓"
	SymbolError   = "✗"
	SymbolWarning = "⚠"
	SymbolPending = "○"
	SymbolRunning = "●"
)

Status indicator symbols.

View Source
const MaxContentWidth = 120

MaxContentWidth defines the maximum display width for content.

Variables

View Source
var (
	ColorPrimary = lipgloss.AdaptiveColor{Light: "#9A4AFF", Dark: "#EE6FF8"}
	ColorBorder  = lipgloss.AdaptiveColor{Light: "#9F72FF", Dark: "#AD58B4"}
	ColorTitleBg = lipgloss.AdaptiveColor{Light: "#16A34A", Dark: "#22C55E"} // Unified green
	ColorTitleFg = lipgloss.AdaptiveColor{Light: "#FFFFFF", Dark: "#FFFFFF"}
	ColorSuccess = lipgloss.AdaptiveColor{Light: "#16A34A", Dark: "#22C55E"} // Same as TitleBg
	ColorWarning = lipgloss.AdaptiveColor{Light: "#D97706", Dark: "#FBBF24"}
	ColorError   = lipgloss.AdaptiveColor{Light: "#DC2626", Dark: "#F87171"}
	ColorText    = lipgloss.AdaptiveColor{Light: "#1A1A1A", Dark: "#DDDDDD"}
	ColorMuted   = lipgloss.AdaptiveColor{Light: "#6F6C6C", Dark: "#7A7A7A"}

	// Commit message colors
	ColorCommitType    = lipgloss.AdaptiveColor{Light: "#CA8A04", Dark: "#FACC15"} // Yellow for type
	ColorCommitScope   = lipgloss.AdaptiveColor{Light: "#C026D3", Dark: "#E879F9"} // Magenta for scope
	ColorCommitSubject = lipgloss.AdaptiveColor{Light: "#FFFFFF", Dark: "#FFFFFF"} // White for subject
	ColorCommitBody    = lipgloss.AdaptiveColor{Light: "#16A34A", Dark: "#4ADE80"} // Green for body
	ColorCommitFooter  = lipgloss.AdaptiveColor{Light: "#2563EB", Dark: "#60A5FA"} // Blue for footer
	ColorCommitSOB     = lipgloss.AdaptiveColor{Light: "#6B7280", Dark: "#9CA3AF"} // Gray for signed-off-by
)

Adaptive colors for light and dark terminals.

View Source
var (
	StyleSuccess    = lipgloss.NewStyle().Foreground(ColorSuccess)
	StyleWarning    = lipgloss.NewStyle().Foreground(ColorWarning)
	StyleError      = lipgloss.NewStyle().Foreground(ColorError)
	StyleMuted      = lipgloss.NewStyle().Foreground(ColorMuted)
	StylePrimary    = lipgloss.NewStyle().Foreground(ColorPrimary)
	StyleTitle      = lipgloss.NewStyle().Bold(true).Foreground(ColorPrimary).MarginBottom(1)
	StyleCommitType = lipgloss.NewStyle().Foreground(ColorPrimary).Bold(true)
)

Reusable lipgloss styles.

Functions

func FormatCommitMessage

func FormatCommitMessage(msg CommitMessageContent, maxWidth int) string

FormatCommitMessage formats a commit message with colored parts. Header: yellow(type) + magenta(scope) + white(subject) Body: green Footer: blue SOB: gray maxWidth: maximum line width for wrapping (0 = no wrapping)

func GetContentWidth

func GetContentWidth(terminalWidth int) int

GetContentWidth calculates the appropriate content width for the given terminal width. If terminalWidth is 0, it auto-detects the terminal width. It returns the smaller of (terminalWidth - 4) or MaxContentWidth, with a minimum of 40.

func IsWarnErr

func IsWarnErr(err error) bool

IsWarnErr checks if an error is a warning.

func RenderResult

func RenderResult(r Result) string

RenderResult renders a Result with adaptive terminal width. The output automatically adjusts to terminal width (capped at MaxContentWidth), and preserves URLs and file paths on single lines without wrapping.

Types

type CommitMessageContent

type CommitMessageContent struct {
	Type    string
	Scope   string
	Subject string
	Body    string
	Footer  string
	SOB     string
}

CommitMessageContent holds the parts of a commit message for styled rendering.

type LuckyResult

type LuckyResult struct {
	Cancelled bool
	Err       error
	Hash      string
}

LuckyResult represents the result of a lucky commit operation.

func RunLuckyCommit

func RunLuckyCommit(prefix string, cmd *exec.Cmd, getHash func() (string, error)) LuckyResult

RunLuckyCommit runs lucky_commit with an animated spinner. Returns the result of the operation.

type MultiTaskModel

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

MultiTaskModel is a model for running multiple tasks sequentially with progress display.

func NewMultiTaskModel

func NewMultiTaskModel(title string, tasks []Task) MultiTaskModel

NewMultiTaskModel creates a new multi-task model.

func (MultiTaskModel) HasError

func (m MultiTaskModel) HasError() bool

HasError returns true if any task failed (non-warning).

func (MultiTaskModel) Init

func (m MultiTaskModel) Init() tea.Cmd

Init initializes the model.

func (MultiTaskModel) Update

func (m MultiTaskModel) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update handles messages.

func (MultiTaskModel) View

func (m MultiTaskModel) View() string

View renders the model.

type Result

type Result struct {
	Type    ResultType
	Title   string
	Content string // Pre-formatted content with ANSI colors
	Note    string // Optional note displayed at the bottom (e.g., quote)
}

Result represents a formatted message to display to the user.

func Error

func Error(title, content string) Result

Error returns a new error Result with the given title and content.

func Success

func Success(title, content string) Result

Success returns a new success Result with the given title and content.

func Warning

func Warning(title, content string) Result

Warning returns a new warning Result with the given title and content.

type ResultType

type ResultType int

ResultType indicates the severity level of a result message.

const (
	ResultSuccess ResultType = iota
	ResultError
	ResultWarning
)

Result type constants.

type SingleTaskModel

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

SingleTaskModel is a model for running a single task with a spinner.

func NewSingleTaskModel

func NewSingleTaskModel(message string, task Task) SingleTaskModel

NewSingleTaskModel creates a new single-task model.

func (SingleTaskModel) Init

func (m SingleTaskModel) Init() tea.Cmd

Init initializes the model.

func (SingleTaskModel) Update

func (m SingleTaskModel) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update handles messages.

func (SingleTaskModel) View

func (m SingleTaskModel) View() string

View renders the model.

type Task

type Task struct {
	Name string
	Run  func() error
}

Task represents a single task with name and execution function.

type TaskState

type TaskState int

TaskState represents the state of a task.

const (
	TaskPending TaskState = iota
	TaskRunning
	TaskSuccess
	TaskWarning
	TaskFailed
)

type WarnErr

type WarnErr struct {
	Msg string
}

WarnErr is an error that indicates a warning (non-fatal).

func (WarnErr) Error

func (e WarnErr) Error() string

Jump to

Keyboard shortcuts

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