ui

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package ui renders the diffpane Bubble Tea interface and its supporting views.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ColorAdd colors added lines and counters.
	ColorAdd = lipgloss.AdaptiveColor{Light: "#22863a", Dark: "#56d364"}
	// ColorDel colors deleted lines and counters.
	ColorDel = lipgloss.AdaptiveColor{Light: "#cb2431", Dark: "#f85149"}
	// BgAdd colors added-line backgrounds in true-color terminals.
	// ~3.0:1 contrast vs black; luminance-matched with BgDel.
	BgAdd = lipgloss.AdaptiveColor{Light: "#dafbe1", Dark: "#286432"}
	// BgDel colors deleted-line backgrounds in true-color terminals.
	// ~2.9:1 contrast vs black; luminance-matched with BgAdd.
	BgDel = lipgloss.AdaptiveColor{Light: "#ffebe9", Dark: "#903c3c"}
	// ColorDim colors neutral metadata such as headers and footer text.
	ColorDim = lipgloss.AdaptiveColor{Light: "#6a737d", Dark: "#8b949e"}

	// StyleAdd renders added content.
	StyleAdd = lipgloss.NewStyle().Foreground(ColorAdd)
	// StyleDel renders deleted content.
	StyleDel = lipgloss.NewStyle().Foreground(ColorDel)
	// StyleDim renders neutral metadata.
	StyleDim = lipgloss.NewStyle().Foreground(ColorDim)
)

Functions

func HighlightCode added in v0.2.0

func HighlightCode(code, filename string) string

HighlightCode applies chroma syntax colors to one code fragment. It returns the original content for empty input or unsupported file types.

func InitTheme added in v0.2.0

func InitTheme()

InitTheme resolves the terminal theme once at startup. Call before starting the Bubble Tea program. Reads DIFFPANE_THEME env var (light|dark) to override auto-detection.

func RenderDiffView

func RenderDiffView(file *internal.FileDiff, scrollOffset, width, height int, highlightSet map[lineKey]bool) string

RenderDiffView renders the current file diff within the viewport.

func RenderFooter

func RenderFooter(followOn bool, notification string, width int) string

RenderFooter renders the one-line footer or a transient notification.

func RenderHeader

func RenderHeader(dirName string, files []internal.FileDiff, currentIdx, width int) string

RenderHeader renders the single-line top bar.

func RenderOverlay

func RenderOverlay(files []internal.FileDiff, cursor, height, width int) string

RenderOverlay renders the frozen file list overlay.

Types

type ClearNotificationMsg

type ClearNotificationMsg struct {
	Token int
}

ClearNotificationMsg clears a temporary footer notification. Token must match the active notification generation; stale clears are ignored.

type FilesUpdatedMsg

type FilesUpdatedMsg struct {
	BaselineSHA  string
	Files        []internal.FileDiff
	ChangedPaths []string
}

FilesUpdatedMsg notifies the UI that the computed file list changed.

type ManualResetFailedMsg added in v0.2.0

type ManualResetFailedMsg struct {
	Error string
}

ManualResetFailedMsg carries a reset error back into the Update loop.

type ManualResetMsg added in v0.2.0

type ManualResetMsg struct {
	NewSHA string
	Files  []internal.FileDiff
}

ManualResetMsg carries the result of a manual baseline reset (r key).

type Model

type Model struct {
	DirName     string
	RepoDir     string
	BaselineSHA string

	Files      []internal.FileDiff
	CurrentIdx int

	FollowOn     bool
	ScrollOffset int

	Notification string

	OverlayOpen      bool
	OverlayCursor    int
	OverlaySnapshot  []internal.FileDiff
	OverlayFollowWas bool
	PendingUpdate    *FilesUpdatedMsg

	// ResetBaseline resets the session baseline asynchronously from a tea.Cmd.
	ResetBaseline func() (string, []internal.FileDiff, error)

	Width  int
	Height int
	// contains filtered or unexported fields
}

Model is the root Bubble Tea model for diffpane.

func NewModel

func NewModel(dirName, repoDir, baselineSHA string, files []internal.FileDiff) Model

NewModel constructs the initial UI state.

func (Model) Init

func (m Model) Init() tea.Cmd

Init starts with no asynchronous UI command.

func (Model) Update

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

Update handles all UI events.

func (Model) View

func (m Model) View() string

View renders header, content, and footer into the terminal viewport.

type ResetTimeoutMsg added in v0.2.0

type ResetTimeoutMsg struct{}

ResetTimeoutMsg cancels a pending manual baseline reset after timeout.

type ThemeMode added in v0.2.0

type ThemeMode int

ThemeMode represents the resolved terminal theme.

const (
	// ThemeDark indicates a dark terminal background.
	ThemeDark ThemeMode = iota
	// ThemeLight indicates a light terminal background.
	ThemeLight
	// ThemeUnknown means detection failed; background colors are disabled.
	ThemeUnknown
)

func GetTheme added in v0.2.0

func GetTheme() ThemeMode

GetTheme returns the resolved theme mode.

Jump to

Keyboard shortcuts

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