common

package
v1.145.0 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package common provides reusable dialog models, messages, and rendering helpers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CenterPosition

func CenterPosition(screenWidth, screenHeight, dialogWidth, dialogHeight int) (row, col int)

CenterPosition calculates the centered position for a dialog given screen and dialog dimensions. Returns (row, col) suitable for use in Dialog.Position().

func ContentEndRow

func ContentEndRow(dialogRow, dialogHeight int) int

ContentEndRow returns the absolute Y row of the last content line inside a dialog. dialogRow is the top-left row and dialogHeight is the total rendered height. The dialog frame (border + padding) is accounted for automatically using DialogStyle.

func ContentStartRow

func ContentStartRow(dialogRow int, headerContent string) int

ContentStartRow returns the absolute Y row where content begins inside a dialog. dialogRow is the top-left row of the dialog, and headerContent is the rendered header text above the target content area. The dialog frame (border + padding) is accounted for automatically using DialogStyle.

func HandleConfirmKeys

func HandleConfirmKeys(msg tea.KeyPressMsg, keyMap ConfirmKeyMap, onYes, onNo func() (layout.Model, tea.Cmd)) (layout.Model, tea.Cmd, bool)

HandleConfirmKeys handles Yes/No key presses for confirmation dialogs. Returns the command to execute and whether a key was matched.

func HandleQuit

func HandleQuit(msg tea.KeyPressMsg) tea.Cmd

HandleQuit checks for the configured quit key and returns tea.Quit if matched.

func HelpKeysWidth

func HelpKeysWidth(bindings ...string) int

HelpKeysWidth returns the rendered width of the given key bindings laid out on a single line, using the same formatting as RenderHelpKeys. It returns 0 for empty or malformed input.

func RenderGroupSeparator

func RenderGroupSeparator(label string, contentWidth int) string

RenderGroupSeparator renders a labelled section separator inside a list, like "── Custom themes ──────────────". It is used to visually divide groups of items in a picker list.

func RenderHelp

func RenderHelp(text string, contentWidth int) string

RenderHelp renders help text at the bottom of a dialog in italic muted style.

func RenderHelpKeys

func RenderHelpKeys(contentWidth int, bindings ...string) string

RenderHelpKeys renders key bindings in the same style as the main TUI's status bar. Each binding is a pair of [key, description] strings.

func RenderSeparator

func RenderSeparator(contentWidth int) string

RenderSeparator renders a horizontal separator line.

func RenderTitle

func RenderTitle(title string, contentWidth int, style lipgloss.Style) string

RenderTitle renders a dialog title with the given style and width.

Types

type BaseDialog

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

BaseDialog provides common functionality for dialog implementations. It handles size management, position calculation, and common UI patterns.

func (*BaseDialog) CenterDialog

func (b *BaseDialog) CenterDialog(renderedDialog string) (row, col int)

CenterDialog returns the (row, col) position to center a rendered dialog.

func (*BaseDialog) ComputeDialogWidth

func (b *BaseDialog) ComputeDialogWidth(percent, minWidth, maxWidth int) int

ComputeDialogWidth calculates dialog width based on screen percentage with bounds.

func (*BaseDialog) ContentWidth

func (b *BaseDialog) ContentWidth(dialogWidth, paddingX int) int

ContentWidth calculates the inner content width given dialog width and padding.

func (*BaseDialog) Height

func (b *BaseDialog) Height() int

Height returns the current height.

func (*BaseDialog) SetSize

func (b *BaseDialog) SetSize(width, height int) tea.Cmd

SetSize updates the dialog dimensions.

func (*BaseDialog) Width

func (b *BaseDialog) Width() int

Width returns the current width.

type Broadcastable

type Broadcastable interface {
	BroadcastToDialogs()
}

Broadcastable marks messages the manager delivers to every dialog in the stack instead of only the topmost one. Data-refresh messages implement it so dialogs buried under another dialog (e.g. the plan browser under its detail dialog) stay fresh.

type CloseAllDialogsMsg

type CloseAllDialogsMsg struct{}

CloseAllDialogsMsg is sent to close all dialogs in the stack

type CloseDialogMsg

type CloseDialogMsg struct{}

CloseDialogMsg is sent to close the current (topmost) dialog

type ConfirmKeyMap

type ConfirmKeyMap struct {
	Yes key.Binding
	No  key.Binding
}

ConfirmKeyMap defines key bindings for confirmation dialogs (Yes/No).

func DefaultConfirmKeyMap

func DefaultConfirmKeyMap() ConfirmKeyMap

DefaultConfirmKeyMap returns the standard Yes/No key bindings.

type Content

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

Content helps build dialog content with consistent structure.

func NewContent

func NewContent(contentWidth int) *Content

NewContent creates a new dialog content builder.

func (*Content) AddContent

func (dc *Content) AddContent(content string) *Content

AddContent adds raw content to the dialog.

func (*Content) AddHelp

func (dc *Content) AddHelp(text string) *Content

AddHelp adds help text at the bottom.

func (*Content) AddHelpKeys

func (dc *Content) AddHelpKeys(bindings ...string) *Content

AddHelpKeys adds key binding help at the bottom.

func (*Content) AddQuestion

func (dc *Content) AddQuestion(question string) *Content

AddQuestion adds a styled question text.

func (*Content) AddSeparator

func (dc *Content) AddSeparator() *Content

AddSeparator adds a horizontal separator line.

func (*Content) AddSpace

func (dc *Content) AddSpace() *Content

AddSpace adds an empty line for spacing.

func (*Content) AddTitle

func (dc *Content) AddTitle(title string) *Content

AddTitle adds a styled title to the dialog.

func (*Content) Build

func (dc *Content) Build() string

Build returns the final dialog content as a vertical join.

type Dialog

type Dialog interface {
	layout.Model
	Position() (int, int) // Returns (row, col) for dialog placement
}

Dialog defines the interface that all dialogs must implement

func NewMultiChoiceDialog

func NewMultiChoiceDialog(config MultiChoiceConfig) Dialog

NewMultiChoiceDialog creates a new multi-choice dialog.

type MultiChoiceConfig

type MultiChoiceConfig struct {
	DialogID          string              // Unique identifier for this dialog instance
	Title             string              // Dialog title (used as the main header)
	Options           []MultiChoiceOption // List of options (max 10 for number selection 0-9)
	AllowCustom       bool                // Whether to allow custom text input
	AllowSecondary    bool                // Whether to allow secondary action (e.g., skip)
	SecondaryLabel    string              // Label for secondary button (default: "Skip")
	PrimaryLabel      string              // Label for primary button (default: "Continue")
	CustomPlaceholder string              // Placeholder for custom input
}

MultiChoiceConfig configures the multi-choice dialog.

type MultiChoiceOption

type MultiChoiceOption struct {
	ID    string // Stable identifier for the option
	Label string // Display label shown to user
	Value string // Value returned when selected (e.g., model-friendly sentence)
}

MultiChoiceOption represents a single selectable option in the dialog.

type MultiChoiceResult

type MultiChoiceResult struct {
	OptionID    string // ID of the selected option ("custom" for custom input, "skip" for no reason)
	Value       string // The value text (option's Value or custom text)
	IsCustom    bool   // True if user provided custom input
	IsSkipped   bool   // True if user chose to skip (no reason)
	IsCancelled bool   // True if user cancelled/escaped
}

MultiChoiceResult holds the result of user selection.

type MultiChoiceResultMsg

type MultiChoiceResultMsg struct {
	DialogID string
	Result   MultiChoiceResult
}

MultiChoiceResultMsg is the tea.Msg sent when the user makes a selection.

type OpenDialogMsg

type OpenDialogMsg struct {
	Model            Dialog
	OriginatingEvent tea.Msg
}

OpenDialogMsg is sent to open a new dialog.

OriginatingEvent is an optional runtime event whose presence marks the dialog as a background dialog. Background dialogs do not block tab navigation: tab-switch keys and tab-bar mouse clicks keep working. When the user switches away from the tab that opened the dialog, the dialog is parked on its owning tab and re-displayed when the user returns. Other input (including mouse-wheel events) is still routed to the dialog while it is on screen.

Jump to

Keyboard shortcuts

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