context

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package context provides shared state that propagates to all views and components. Inspired by gh-dash's ProgramContext pattern for centralized state management.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ColorPalette

type ColorPalette struct {
	Primary   lipgloss.Color // Google Blue
	Secondary lipgloss.Color // Google Green
	Warning   lipgloss.Color // Google Yellow
	Error     lipgloss.Color // Google Red
	Muted     lipgloss.Color // Gray
	Bg        lipgloss.Color // Dark background
	BgLight   lipgloss.Color // Lighter background
	Text      lipgloss.Color // Primary text
	TextMuted lipgloss.Color // Secondary text
}

ColorPalette defines the GCP-inspired color scheme

type CommonStyles

type CommonStyles struct {
	Title         lipgloss.Style
	Subtitle      lipgloss.Style
	Selected      lipgloss.Style
	Normal        lipgloss.Style
	Muted         lipgloss.Style
	Error         lipgloss.Style
	Success       lipgloss.Style
	Warning       lipgloss.Style
	StatusRunning lipgloss.Style
	StatusStopped lipgloss.Style
	StatusPending lipgloss.Style
}

CommonStyles holds styles used across multiple components

type FooterStyles

type FooterStyles struct {
	Container lipgloss.Style
	Text      lipgloss.Style
	Key       lipgloss.Style
	Separator lipgloss.Style
	TaskInfo  lipgloss.Style
}

FooterStyles holds footer-specific styles

type HelpStyles

type HelpStyles struct {
	Key  lipgloss.Style
	Desc lipgloss.Style
}

HelpStyles holds help display styles

type ProgramContext

type ProgramContext struct {
	// Terminal dimensions
	ScreenWidth  int
	ScreenHeight int

	// Content area dimensions (excluding sidebar when active)
	ContentWidth  int
	ContentHeight int

	// EmojiWidthBudget is the number of extra characters subtracted from
	// ContentWidth by renderWithSidebar to compensate for wide-emoji
	// miscounting. Views that produce lines at ContentWidth will have those
	// lines wrapped by lipgloss MaxWidth(ContentWidth - EmojiWidthBudget).
	// Views with text that fills the full width should subtract this value.
	EmojiWidthBudget int

	// Sidebar state
	SidebarActive bool
	SidebarWidth  int

	// Styles reference - all components use these for consistent theming
	Styles *Styles

	// Task tracking - callback to start async operations with visual feedback
	StartTask func(task Task) tea.Cmd

	// Active tasks map (managed by App).
	// NOTE: This map is accessed only from within the Bubble Tea event loop
	// (Update/View methods). Do not read or write Tasks from goroutines
	// outside the event loop without adding proper synchronization.
	Tasks map[string]Task

	// Current project context
	ProjectID string

	// Global error to display
	Error error
}

ProgramContext holds shared state propagated to all views and components. This centralizes dimensions, styles, and async task tracking.

func New

func New() *ProgramContext

New creates a new ProgramContext with default values

func (*ProgramContext) ActiveTaskDescription

func (ctx *ProgramContext) ActiveTaskDescription() string

ActiveTaskDescription returns the description of the first running task

func (*ProgramContext) HasActiveTask

func (ctx *ProgramContext) HasActiveTask() bool

HasActiveTask returns true if any task is currently running

func (*ProgramContext) SetDimensions

func (ctx *ProgramContext) SetDimensions(screenW, screenH, contentW, contentH int)

SetDimensions updates all dimension-related fields

type SidebarStyles

type SidebarStyles struct {
	Container    lipgloss.Style
	Item         lipgloss.Style
	SelectedItem lipgloss.Style
	Category     lipgloss.Style
	Border       lipgloss.Style
}

SidebarStyles holds sidebar-specific styles

type Styles

type Styles struct {
	// Color palette - GCP inspired
	Colors ColorPalette

	// Component-specific styles
	Common  CommonStyles
	Table   TableStyles
	Sidebar SidebarStyles
	Footer  FooterStyles
	Help    HelpStyles
}

Styles holds all application styles organized by component. Centralizing styles ensures consistent theming across the app.

func DefaultStyles

func DefaultStyles() Styles

DefaultStyles returns the default GCP-themed styles

type TableStyles

type TableStyles struct {
	Header       lipgloss.Style
	Cell         lipgloss.Style
	SelectedCell lipgloss.Style
	StatusBar    lipgloss.Style
}

TableStyles holds table-specific styles

type Task

type Task struct {
	ID           string
	Description  string // "Loading instances..."
	State        TaskState
	Error        error
	StartTime    time.Time
	FinishedTime *time.Time
}

Task tracks an async operation with visual feedback

type TaskClearMsg

type TaskClearMsg struct {
	TaskID string
}

TaskClearMsg is sent to remove a completed task from display

type TaskFinishedMsg

type TaskFinishedMsg struct {
	TaskID string
	Error  error
}

TaskFinishedMsg is sent when an async task completes

type TaskStartedMsg

type TaskStartedMsg struct {
	Task Task
}

TaskStartedMsg is sent when an async task begins

type TaskState

type TaskState int

TaskState represents the current state of an async task

const (
	TaskRunning TaskState = iota
	TaskFinished
	TaskError
)

Jump to

Keyboard shortcuts

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