Documentation
¶
Overview ¶
Package common provides reusable dialog models, messages, and rendering helpers.
Index ¶
- func CenterPosition(screenWidth, screenHeight, dialogWidth, dialogHeight int) (row, col int)
- func ContentEndRow(dialogRow, dialogHeight int) int
- func ContentStartRow(dialogRow int, headerContent string) int
- func HandleConfirmKeys(msg tea.KeyPressMsg, keyMap ConfirmKeyMap, ...) (layout.Model, tea.Cmd, bool)
- func HandleQuit(msg tea.KeyPressMsg) tea.Cmd
- func HelpKeysWidth(bindings ...string) int
- func RenderGroupSeparator(label string, contentWidth int) string
- func RenderHelp(text string, contentWidth int) string
- func RenderHelpKeys(contentWidth int, bindings ...string) string
- func RenderSeparator(contentWidth int) string
- func RenderTitle(title string, contentWidth int, style lipgloss.Style) string
- type BaseDialog
- func (b *BaseDialog) CenterDialog(renderedDialog string) (row, col int)
- func (b *BaseDialog) ComputeDialogWidth(percent, minWidth, maxWidth int) int
- func (b *BaseDialog) ContentWidth(dialogWidth, paddingX int) int
- func (b *BaseDialog) Height() int
- func (b *BaseDialog) SetSize(width, height int) tea.Cmd
- func (b *BaseDialog) Width() int
- type Broadcastable
- type CloseAllDialogsMsg
- type CloseDialogMsg
- type ConfirmKeyMap
- type Content
- func (dc *Content) AddContent(content string) *Content
- func (dc *Content) AddHelp(text string) *Content
- func (dc *Content) AddHelpKeys(bindings ...string) *Content
- func (dc *Content) AddQuestion(question string) *Content
- func (dc *Content) AddSeparator() *Content
- func (dc *Content) AddSpace() *Content
- func (dc *Content) AddTitle(title string) *Content
- func (dc *Content) Build() string
- type Dialog
- type MultiChoiceConfig
- type MultiChoiceOption
- type MultiChoiceResult
- type MultiChoiceResultMsg
- type OpenDialogMsg
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CenterPosition ¶
CenterPosition calculates the centered position for a dialog given screen and dialog dimensions. Returns (row, col) suitable for use in Dialog.Position().
func ContentEndRow ¶
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 ¶
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 ¶
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 ¶
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 ¶
RenderHelp renders help text at the bottom of a dialog in italic muted style.
func RenderHelpKeys ¶
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 ¶
RenderSeparator renders a horizontal separator line.
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.
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 ¶
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 ¶
NewContent creates a new dialog content builder.
func (*Content) AddContent ¶
AddContent adds raw content to the dialog.
func (*Content) AddHelpKeys ¶
AddHelpKeys adds key binding help at the bottom.
func (*Content) AddQuestion ¶
AddQuestion adds a styled question text.
func (*Content) AddSeparator ¶
AddSeparator adds a horizontal separator line.
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 ¶
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.